From 2ae33382039d9d4835593a0d73b445b302906926 Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 27 Nov 2024 14:32:11 +0000 Subject: [PATCH] fix workflow --- debugging.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/debugging.py b/debugging.py index d770d98..ad04c1d 100644 --- a/debugging.py +++ b/debugging.py @@ -1,5 +1,6 @@ import requests import logging +import sys logger = logging.getLogger(__name__) @@ -8,7 +9,10 @@ def check_gcp_metadata(): Checks the GCP metadata server and prints the response. Returns: - bool: True if metadata server is accessible, False otherwise + bool: True if metadata server is accessible with 200 status code + + Raises: + SystemExit: If metadata server returns non-200 status code or is inaccessible """ metadata_server_url = "http://metadata.google.internal/computeMetadata/v1" headers = { @@ -19,12 +23,18 @@ def check_gcp_metadata(): response = requests.get(metadata_server_url, headers=headers, timeout=5) print(f"Metadata server response status: {response.status_code}") print(f"Metadata server response:\n{response.text}") + + if response.status_code != 200: + logger.error(f"Metadata server returned status code {response.status_code}") + logger.error(f"Metadata server response:\n{response.text}") + sys.exit(1) + return True except requests.exceptions.RequestException as e: logger.error(f"Failed to access metadata server: {str(e)}") print(f"Error accessing metadata server: {str(e)}") - return False + sys.exit(1) # Try accessing the metadata server check_gcp_metadata()