From b6837a4a1007edbe88683ff055d7f33ae5bce9d4 Mon Sep 17 00:00:00 2001 From: Jiri Hnidek Date: Wed, 24 Apr 2024 10:26:38 +0200 Subject: [PATCH] feat: 1.28 Added Azure location to facts * Backport commit to 1.28 branch * Original PR: #3389 * Original commit: c9acace928f6f63a6016d0481eb8f73be0085575 * Card ID: CCT-384 * Add azure_location to facts, when available * TODO: update required version of metadata and get extended locatition fact --- src/rhsmlib/facts/cloud_facts.py | 5 ++++- test/rhsmlib_test/test_cloud_facts.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/rhsmlib/facts/cloud_facts.py b/src/rhsmlib/facts/cloud_facts.py index 252eeaf73d..0643fc5e28 100644 --- a/src/rhsmlib/facts/cloud_facts.py +++ b/src/rhsmlib/facts/cloud_facts.py @@ -106,12 +106,13 @@ def get_aws_facts(self): def get_azure_facts(self): """ - Try to get facts of VM running on Azure public cloud. Returned dictionary has following format: + Try to get facts of VM running on Azure public cloud. Returned dictionary has the following format: { "azure_instance_id": some_instance_ID, "azure_offer": some_offer, "azure_sku": some_sku, "azure_subscription_id": some_subscription_ID + "azure_location: azure region the VM is running in } :return: dictionary containing Azure facts, when the machine is able to gather metadata from Azure cloud provider; otherwise returns empty dictionary {} @@ -131,6 +132,8 @@ def get_azure_facts(self): facts['azure_offer'] = values['compute']['offer'] if "subscriptionId" in values["compute"]: facts["azure_subscription_id"] = values["compute"]["subscriptionId"] + if "location" in values["compute"]: + facts["azure_location"] = values["compute"]["location"] return facts def get_gcp_facts(self): diff --git a/test/rhsmlib_test/test_cloud_facts.py b/test/rhsmlib_test/test_cloud_facts.py index 4157d185ea..02f25adb60 100644 --- a/test/rhsmlib_test/test_cloud_facts.py +++ b/test/rhsmlib_test/test_cloud_facts.py @@ -154,6 +154,7 @@ AZURE_SKU = "8.1-ci" AZURE_OFFER = "RHEL" AZURE_SUBSCRIPTION_ID = "01234567-0123-0123-0123-012345679abc" +AZURE_LOCATION = "westeurope" def mock_prepare_request(request): @@ -303,6 +304,8 @@ def test_get_azure_facts(self): self.assertEqual(facts["azure_offer"], AZURE_OFFER) self.assertIn("azure_subscription_id", facts) self.assertEqual(facts["azure_subscription_id"], AZURE_SUBSCRIPTION_ID) + self.assertIn("azure_location", facts) + self.assertEqual(facts["azure_location"], AZURE_LOCATION) @patch('cloud_what.providers.gcp.GCPCloudProvider._write_token_to_cache_file') @patch('cloud_what.providers.gcp.GCPCloudProvider._get_metadata_from_cache')