Skip to content

Commit

Permalink
feat: Azure: added extended location and type of location fact
Browse files Browse the repository at this point in the history
* 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 authored and ptoscano committed Apr 18, 2024
1 parent 4739950 commit 0849db3
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 @@ -146,6 +146,11 @@ def get_azure_facts(self) -> Dict[str, str]:
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) -> Dict[str, str]:
Expand Down
13 changes: 13 additions & 0 deletions test/rhsmlib/facts/test_cloud_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
{
"compute": {
"azEnvironment": "AzurePublicCloud",
"extendedLocation": {
"type": "edgeZone",
"name": "microsoftlondon"
},
"customData": "",
"location": "westeurope",
"name": "foo-bar",
Expand Down Expand Up @@ -169,7 +173,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 @@ -319,6 +328,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 0849db3

Please sign in to comment.