Skip to content

Commit

Permalink
feat: 1.28 Azure: added extended location and type of location fact
Browse files Browse the repository at this point in the history
* Backport commit to 1.28
* Original PR: #3389
  * Original commit: 0bba05e
* Card ID: CCT-384
* Added new facts from Azure IMDS metadata available since
  2021-03-01
  * Metadata with given version provides extendedLocation.name
    and extendedLocation.type
* Extendd unit tests to include new facts
  • Loading branch information
jirihnidek committed Apr 24, 2024
1 parent 1953963 commit c51eae7
Show file tree
Hide file tree
Showing 2 changed files with 18 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 @@ -134,6 +134,11 @@ def get_azure_facts(self):
facts["azure_subscription_id"] = values["compute"]["subscriptionId"]
if "location" in values["compute"]:
facts["azure_location"] = values["compute"]["location"]
if "extendedLocation" in values["compute"]:
if "name" in values["compute"]["extendedLocation"]:
facts["azure_extended_location_name"] = values["compute"]["extendedLocation"]["name"]
if "type" in values["compute"]["extendedLocation"]:
facts["azure_extended_location_type"] = values["compute"]["extendedLocation"]["type"]
return facts

def get_gcp_facts(self):
Expand Down
13 changes: 13 additions & 0 deletions test/rhsmlib_test/test_cloud_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
{
"compute": {
"azEnvironment": "AzurePublicCloud",
"extendedLocation": {
"type": "edgeZone",
"name": "microsoftlondon"
},
"customData": "",
"location": "westeurope",
"name": "foo-bar",
Expand Down Expand Up @@ -154,7 +158,12 @@
AZURE_SKU = "8.1-ci"
AZURE_OFFER = "RHEL"
AZURE_SUBSCRIPTION_ID = "01234567-0123-0123-0123-012345679abc"
# There is no list of valid values of locations, extended locations and
# types of extended locations. Value "microsoftlondon" probably does not
# exist at all, and it was added only for testing purpose.
AZURE_LOCATION = "westeurope"
AZURE_EXTENDED_LOCATION_NAME = "microsoftlondon"
AZURE_EXTENDED_LOCATION_TYPE = "edgeZone"


def mock_prepare_request(request):
Expand Down Expand Up @@ -306,6 +315,10 @@ def test_get_azure_facts(self):
self.assertEqual(facts["azure_subscription_id"], AZURE_SUBSCRIPTION_ID)
self.assertIn("azure_location", facts)
self.assertEqual(facts["azure_location"], AZURE_LOCATION)
self.assertIn("azure_extended_location_name", facts)
self.assertEqual(facts["azure_extended_location_name"], AZURE_EXTENDED_LOCATION_NAME)
self.assertIn("azure_extended_location_type", facts)
self.assertEqual(facts["azure_extended_location_type"], AZURE_EXTENDED_LOCATION_TYPE)

@patch('cloud_what.providers.gcp.GCPCloudProvider._write_token_to_cache_file')
@patch('cloud_what.providers.gcp.GCPCloudProvider._get_metadata_from_cache')
Expand Down

0 comments on commit c51eae7

Please sign in to comment.