Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added more AWS cloud facts #3387

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/rhsmlib/facts/cloud_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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]:
Expand Down
9 changes: 8 additions & 1 deletion test/rhsmlib/facts/test_cloud_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
Loading