From 27ccda43115588b53f6f44b1dfeb52a6fb537827 Mon Sep 17 00:00:00 2001 From: Jiri Hnidek Date: Tue, 9 Apr 2024 13:22:09 +0200 Subject: [PATCH] feat: 1.28 Added zone GCP fact * Original PR: 3388 * Original commit: 2d04f776fe2464432821631805be1d494a9b05ec * Card ID: CCT-385 * 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 --- src/rhsmlib/facts/cloud_facts.py | 5 +++++ test/rhsmlib_test/test_cloud_facts.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/rhsmlib/facts/cloud_facts.py b/src/rhsmlib/facts/cloud_facts.py index 252eeaf73d..314eb3cdea 100644 --- a/src/rhsmlib/facts/cloud_facts.py +++ b/src/rhsmlib/facts/cloud_facts.py @@ -169,6 +169,11 @@ def get_gcp_facts(self): 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 diff --git a/test/rhsmlib_test/test_cloud_facts.py b/test/rhsmlib_test/test_cloud_facts.py index 4157d185ea..64e9210332 100644 --- a/test/rhsmlib_test/test_cloud_facts.py +++ b/test/rhsmlib_test/test_cloud_facts.py @@ -339,6 +339,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):