From 7a88b57f4bc92b031de921af68af5c71fda8789a Mon Sep 17 00:00:00 2001 From: Thirumalesh Aaraveti Date: Wed, 20 Nov 2024 20:08:37 +0530 Subject: [PATCH] Added the policy name to cost-savings --- cloud_governance/policy/helpers/aws/aws_policy_operations.py | 3 ++- .../cloud_governance/policy/aws/cleanup/test_database_idle.py | 2 +- .../policy/aws/cleanup/test_unattached_volume.py | 2 +- .../policy/aws/cleanup/test_unused_nat_gateway.py | 2 +- .../cloud_governance/policy/aws/test_zombie_snapshots.py | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cloud_governance/policy/helpers/aws/aws_policy_operations.py b/cloud_governance/policy/helpers/aws/aws_policy_operations.py index 017536ab..e7591ec8 100644 --- a/cloud_governance/policy/helpers/aws/aws_policy_operations.py +++ b/cloud_governance/policy/helpers/aws/aws_policy_operations.py @@ -18,6 +18,7 @@ class AWSPolicyOperations(AbstractPolicyOperations): def __init__(self): super().__init__() self._region = self._environment_variables_dict.get('AWS_DEFAULT_REGION', 'us-east-2') + self.policy_name = self._environment_variables_dict.get('policy') self._cloud_name = 'AWS' self._ec2_client = get_boto3_client(client='ec2', region_name=self._region) self._s3_client = get_boto3_client('s3', region_name=self._region) @@ -27,7 +28,7 @@ def __init__(self): self._ec2_operations = EC2Operations(region=self._region) self._cloudwatch = CloudWatchOperations(region=self._region) self._resource_pricing = ResourcesPricing() - self.cost_savings_tag = [{'Key': 'cost-savings', 'Value': 'true'}] + self.cost_savings_tag = [{'Key': 'cost-savings', 'Value': self.policy_name}] def get_tag_name_from_tags(self, tags: list, tag_name: str) -> str: """ diff --git a/tests/unittest/cloud_governance/policy/aws/cleanup/test_database_idle.py b/tests/unittest/cloud_governance/policy/aws/cleanup/test_database_idle.py index d09b8229..e6b94cbb 100644 --- a/tests/unittest/cloud_governance/policy/aws/cleanup/test_database_idle.py +++ b/tests/unittest/cloud_governance/policy/aws/cleanup/test_database_idle.py @@ -37,7 +37,7 @@ def test_database_idle(): assert get_tag_value_from_tags(tags=rds_client.describe_db_instances()['DBInstances'][0]['TagList'], tag_name='DaysCount') == f"{current_date.date()}@1" assert get_tag_value_from_tags(tags=rds_client.describe_db_instances()['DBInstances'][0]['TagList'], - tag_name='cost-savings') == "true" + tag_name='cost-savings') == "database_idle" @mock_cloudwatch diff --git a/tests/unittest/cloud_governance/policy/aws/cleanup/test_unattached_volume.py b/tests/unittest/cloud_governance/policy/aws/cleanup/test_unattached_volume.py index 678f5c6f..b05dae02 100644 --- a/tests/unittest/cloud_governance/policy/aws/cleanup/test_unattached_volume.py +++ b/tests/unittest/cloud_governance/policy/aws/cleanup/test_unattached_volume.py @@ -40,7 +40,7 @@ def test_unattached_volume_dry_run_yes(): assert response.get('ResourceAction') == 'False' assert response.get('SkipPolicy') == 'NA' assert get_tag_value_from_tags(tags=volume_run._get_all_volumes()[0]['Tags'], - tag_name='cost-savings') == 'true' + tag_name='cost-savings') == 'unattached_volume' @mock_ec2 diff --git a/tests/unittest/cloud_governance/policy/aws/cleanup/test_unused_nat_gateway.py b/tests/unittest/cloud_governance/policy/aws/cleanup/test_unused_nat_gateway.py index 6b0b3db9..01e943c6 100644 --- a/tests/unittest/cloud_governance/policy/aws/cleanup/test_unused_nat_gateway.py +++ b/tests/unittest/cloud_governance/policy/aws/cleanup/test_unused_nat_gateway.py @@ -27,7 +27,7 @@ def test_unused_nat_gateway_dry_run_yes(): assert len(response) == 1 assert response[0]['CleanUpDays'] == 0 assert get_tag_value_from_tags(tags=unused_nat_gateway._ec2_operations.get_nat_gateways()[0]['Tags'], - tag_name='cost-savings') == 'true' + tag_name='cost-savings') == 'unused_nat_gateway' @mock_cloudwatch diff --git a/tests/unittest/cloud_governance/policy/aws/test_zombie_snapshots.py b/tests/unittest/cloud_governance/policy/aws/test_zombie_snapshots.py index 2eca57f5..2a880aa9 100644 --- a/tests/unittest/cloud_governance/policy/aws/test_zombie_snapshots.py +++ b/tests/unittest/cloud_governance/policy/aws/test_zombie_snapshots.py @@ -55,7 +55,7 @@ def test_zombie_snapshots(): 'Tags'], tag_name='DaysCount') assert get_tag_value_from_tags(tags=zombie_snapshots._ec2_operations.get_snapshots()[0]['Tags'], - tag_name='cost-savings') == 'true' + tag_name='cost-savings') == 'zombie_snapshots' @mock_ec2