Skip to content

Commit

Permalink
fix workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
baptistecolle committed Nov 27, 2024
1 parent 9581e7e commit 2ae3338
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions debugging.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests
import logging
import sys

logger = logging.getLogger(__name__)

Expand All @@ -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 = {
Expand All @@ -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()

0 comments on commit 2ae3338

Please sign in to comment.