diff --git a/src/rhsmlib/facts/cloud_facts.py b/src/rhsmlib/facts/cloud_facts.py index 28128a341b..77e1fef6aa 100644 --- a/src/rhsmlib/facts/cloud_facts.py +++ b/src/rhsmlib/facts/cloud_facts.py @@ -89,7 +89,7 @@ def get_aws_facts(self) -> Dict[str, Union[str, None]]: # BTW: There should be only two types of billing codes: bp-63a5400a and bp-6fa54006 in the list, # when RHEL is used. When the subscription-manager is used by some other Linux distribution, - # then there could be different codes or it could be null + # then there could be different codes, or it could be null if "billingProducts" in values: billing_products: Optional[List[str]] = values["billingProducts"] if isinstance(billing_products, list): @@ -108,6 +108,12 @@ def get_aws_facts(self) -> Dict[str, Union[str, None]]: else: log.debug("AWS metadata attribute marketplaceProductCodes has to be list or null") + if "instanceType" in values: + facts["aws_instance_type"] = values["instanceType"] + + if "region" in values: + facts["aws_region"] = values["region"] + return facts def get_azure_facts(self) -> Dict[str, str]: diff --git a/test/rhsmlib/facts/test_cloud_facts.py b/test/rhsmlib/facts/test_cloud_facts.py index 3887c35f5f..141680ae8d 100644 --- a/test/rhsmlib/facts/test_cloud_facts.py +++ b/test/rhsmlib/facts/test_cloud_facts.py @@ -160,6 +160,9 @@ AWS_INSTANCE_ID = "i-abcdef01234567890" AWS_ACCOUNT_ID = "012345678900" AWS_BILLING_PRODUCTS = "bp-0124abcd bp-63a5400a" +AWS_INSTANCE_TYPE = "m5.large" +AWS_REGION = "eu-central-1" + # The Azure instance ID has to be the same as "vmId" in AZURE_METADATA # values for "sku" an "offer" has to be same as in AZURE_METADATA AZURE_INSTANCE_ID = "12345678-1234-1234-1234-123456789abc" @@ -199,7 +202,7 @@ def tearDown(self) -> None: @patch("cloud_what.providers.aws.requests.Session", name="test_get_aws_facts.mock_session_class") def test_get_aws_facts(self, mock_session_class): """ - Test getting AWS facts (instance ID, accountID and billingProducts) + Test getting AWS facts (instance ID, accountID and billingProducts, etc.) """ mock_result = Mock(name="_test_get_aws_facts.mock_result") mock_result.status_code = 200 @@ -227,6 +230,10 @@ def test_get_aws_facts(self, mock_session_class): self.assertEqual(facts["aws_billing_products"], AWS_BILLING_PRODUCTS) self.assertIn("aws_marketplace_product_codes", facts) self.assertEqual(facts["aws_marketplace_product_codes"], None) + self.assertIn("aws_instance_type", facts) + self.assertEqual(facts["aws_instance_type"], AWS_INSTANCE_TYPE) + self.assertIn("aws_region", facts) + self.assertEqual(facts["aws_region"], AWS_REGION) @patch("cloud_what.providers.aws.requests.Session", name="mock_session_class") def test_get_aws_facts_with_null_billing_products(self, mock_session_class):