Skip to content

Commit

Permalink
feat: Added zone GCP fact
Browse files Browse the repository at this point in the history
* Added fact about zone, where the instance is located
* Extended unit test covering this new fact
* Note: GCP does not provide any information about instance type
  • Loading branch information
jirihnidek committed Apr 18, 2024
1 parent cc59a3e commit 2d04f77
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/rhsmlib/facts/cloud_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ def get_gcp_facts(self) -> Dict[str, str]:
facts["gcp_project_number"] = values["google"]["compute_engine"]["project_number"]
else:
log.debug("GCP project_number not found in JWT token")
# zone where the machine is located
if "zone" in values["google"]["compute_engine"]:
facts["gcp_zone"] = values["google"]["compute_engine"]["zone"]
else:
log.debug("GCP zone not found in JWT token")
else:
log.debug("GCP google.compute_engine on found in JWT token")
return facts
Expand Down
2 changes: 2 additions & 0 deletions test/rhsmlib/facts/test_cloud_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ def test_get_gcp_facts(self, mock_get_metadata_from_cache, mock_write_token_to_c
self.assertEqual(facts["gcp_project_id"], "fair-kingdom-308514")
self.assertIn("gcp_project_number", facts)
self.assertEqual(facts["gcp_project_number"], 161958465613)
self.assertIn("gcp_zone", facts)
self.assertEqual(facts["gcp_zone"], "us-east1-b")

@patch("cloud_what.providers.aws.requests.Session", name="mock_session_class")
def test_get_not_aws_instance(self, mock_session_class):
Expand Down

0 comments on commit 2d04f77

Please sign in to comment.