Skip to content

Commit

Permalink
feat: 1.28 Added more AWS cloud facts
Browse files Browse the repository at this point in the history
* Backport to 1.28 branch
* Original PR: #3387
  * Original commit: df5776a
* Card Id: CCT-366
* Added two options "aws_region" and "aws_instance_type" to cloud
  facts to be able to provide better business intelligence
* Extended unit tests
  • Loading branch information
jirihnidek authored and m-horky committed May 14, 2024
1 parent c0e4989 commit 7cf5af5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/rhsmlib/facts/cloud_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ def get_aws_facts(self):
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):
Expand Down
7 changes: 7 additions & 0 deletions test/rhsmlib_test/test_cloud_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,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"
Expand Down Expand Up @@ -225,6 +228,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):
Expand Down

0 comments on commit 7cf5af5

Please sign in to comment.