From ce2069256305e5557f86824f624e654d0730b626 Mon Sep 17 00:00:00 2001 From: Thirumalesh Aaraveti Date: Thu, 4 Jan 2024 17:35:12 +0530 Subject: [PATCH] Re arranged the order of policies --- .../json_datetime_encoder.py | 0 .../policy/abstract_policies/__init__.py | 0 .../abstract_policies/cleanup/__init__.py | 0 .../cleanup/abstractinstance_run.py | 95 ------------------- .../policy/aws/cleanup/instance_run.py | 48 ++++++++-- .../policy/azure/cleanup/instance_run.py | 44 +++++++-- .../{common => policy}/helpers/__init__.py | 0 .../helpers/abstract_policy_operations.py | 51 ++++++++++ .../helpers/aws/__init__.py | 0 .../helpers/aws/aws_policy_operations.py | 6 +- .../helpers/azure/__init__.py | 0 .../helpers/azure/azure_policy_operations.py | 7 +- .../run_zombie_non_cluster_policies.py | 2 +- .../policy/policy_runners/aws/upload_s3.py | 2 +- .../clouds/aws/s3/test_s3_operations.py | 3 - .../helpers/aws/test_aws_cleaup_operations.py | 2 +- .../common/helpers/test_cleanup_operations.py | 2 +- .../helpers/test_json_datetime_encoder.py | 2 +- .../policy/aws/cleanup/test_instance_run.py | 4 +- 19 files changed, 142 insertions(+), 126 deletions(-) rename cloud_governance/common/{helpers => utils}/json_datetime_encoder.py (100%) delete mode 100644 cloud_governance/policy/abstract_policies/__init__.py delete mode 100644 cloud_governance/policy/abstract_policies/cleanup/__init__.py delete mode 100644 cloud_governance/policy/abstract_policies/cleanup/abstractinstance_run.py rename cloud_governance/{common => policy}/helpers/__init__.py (100%) rename cloud_governance/{common => policy}/helpers/abstract_policy_operations.py (75%) rename cloud_governance/{common => policy}/helpers/aws/__init__.py (100%) rename cloud_governance/{common => policy}/helpers/aws/aws_policy_operations.py (96%) rename cloud_governance/{common => policy}/helpers/azure/__init__.py (100%) rename cloud_governance/{common => policy}/helpers/azure/azure_policy_operations.py (93%) diff --git a/cloud_governance/common/helpers/json_datetime_encoder.py b/cloud_governance/common/utils/json_datetime_encoder.py similarity index 100% rename from cloud_governance/common/helpers/json_datetime_encoder.py rename to cloud_governance/common/utils/json_datetime_encoder.py diff --git a/cloud_governance/policy/abstract_policies/__init__.py b/cloud_governance/policy/abstract_policies/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/cloud_governance/policy/abstract_policies/cleanup/__init__.py b/cloud_governance/policy/abstract_policies/cleanup/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/cloud_governance/policy/abstract_policies/cleanup/abstractinstance_run.py b/cloud_governance/policy/abstract_policies/cleanup/abstractinstance_run.py deleted file mode 100644 index 78739ac85..000000000 --- a/cloud_governance/policy/abstract_policies/cleanup/abstractinstance_run.py +++ /dev/null @@ -1,95 +0,0 @@ -from abc import ABC, abstractmethod -from datetime import datetime - -from cloud_governance.common.elasticsearch.elastic_upload import ElasticUpload -from cloud_governance.main.environment_variables import environment_variables - - -class AbstractInstanceRun(ABC): - - INSTANCE_TYPES_ES_INDEX = 'cloud-governance-instance-types' - RESOURCE_ACTION = "Stopped" - - def __init__(self): - self.__es_upload = ElasticUpload() - self.__environment_variables_dict = environment_variables.environment_variables_dict - self.__account = self.__environment_variables_dict.get('account').upper().replace('OPENSHIFT-', '') - self.__cloud_name = self.__environment_variables_dict.get('PUBLIC_CLOUD_NAME') - super().__init__() - - def _upload_instance_type_count_to_elastic_search(self): - """ - This method uploads the data to elasticsearch - :return: - :rtype: - """ - instance_types = self._update_instance_type_count() - account = self.__account - current_day = datetime.utcnow() - es_instance_types_data = [] - for region, instance_types in instance_types.items(): - for instance_type, instance_type_count in instance_types.items(): - es_instance_types_data.append({ - 'instance_type': instance_type, - 'instance_count': instance_type_count, - 'timestamp': current_day, - 'region': region, - 'account': account, - 'PublicCloud': self.__cloud_name, - 'index_id': f'{instance_type}-{self.__cloud_name.lower()}-{account.lower()}-{region}-{str(current_day.date())}' - }) - self.__es_upload.es_upload_data(items=es_instance_types_data, es_index=self.INSTANCE_TYPES_ES_INDEX, - set_index='index_id') - - def _get_es_data_schema_format(self, resource_id: str, user: str, skip_policy: str, launch_time: datetime, - instance_type: str, instance_state: str, running_days: int, cleanup_days: int, - dry_run: str, name: str, region: str, cleanup_result: str, cloud_name: str): - """ - This method returns the schema of the es - :return: - :rtype: - """ - current_date = datetime.utcnow().date() - return { - 'ResourceId': resource_id, - 'User': user, - 'SkipPolicy': skip_policy, - 'LaunchTime': launch_time, - 'InstanceType': instance_type, - 'InstanceState': instance_state, - 'RunningDays': running_days, - 'CleanUpDays': cleanup_days, - 'DryRun': dry_run, - 'Name': name, - 'RegionName': region, - f'Resource{self.RESOURCE_ACTION}': cleanup_result, - 'PublicCloud': cloud_name, - 'index-id': f'{current_date}-{cloud_name.lower()}-{self.__account.lower()}-{region.lower()}-{resource_id}-{instance_state.lower()}' - } - - @abstractmethod - def _update_instance_type_count(self): - """ - This method updates the instance type count to the elasticsearch - :return: { region: { instance_type: count } } - :rtype: dict - """ - raise NotImplementedError("This method not yet implemented") - - @abstractmethod - def _instance_run(self): - """ - This method returns the running instances and upload to elastic_search - :return: - :rtype: - """ - raise NotImplementedError("This method not yet implemented") - - def run(self): - """ - This method starts the instance run operations - :return: - :rtype: - """ - self._upload_instance_type_count_to_elastic_search() - return self._instance_run() diff --git a/cloud_governance/policy/aws/cleanup/instance_run.py b/cloud_governance/policy/aws/cleanup/instance_run.py index e74db2ff2..ec01641f6 100644 --- a/cloud_governance/policy/aws/cleanup/instance_run.py +++ b/cloud_governance/policy/aws/cleanup/instance_run.py @@ -1,14 +1,40 @@ -import datetime +from datetime import datetime -from cloud_governance.common.helpers.aws.aws_policy_operations import AWSPolicyOperations -from cloud_governance.policy.abstract_policies.cleanup.abstractinstance_run import AbstractInstanceRun +from cloud_governance.policy.helpers.aws.aws_policy_operations import AWSPolicyOperations -class InstanceRun(AbstractInstanceRun, AWSPolicyOperations): +class InstanceRun(AWSPolicyOperations): + + INSTANCE_TYPES_ES_INDEX = "cloud-governance-instance-types" + RESOURCE_ACTION = "Stopped" def __init__(self): super().__init__() + def _upload_instance_type_count_to_elastic_search(self): + """ + This method uploads the data to elasticsearch + :return: + :rtype: + """ + instance_types = self._update_instance_type_count() + account = self.account + current_day = datetime.utcnow() + es_instance_types_data = [] + for region, instance_types in instance_types.items(): + for instance_type, instance_type_count in instance_types.items(): + es_instance_types_data.append({ + 'instance_type': instance_type, + 'instance_count': instance_type_count, + 'timestamp': current_day, + 'region': region, + 'account': account, + 'PublicCloud': self._cloud_name, + 'index_id': f'{instance_type}-{self._cloud_name.lower()}-{account.lower()}-{region}-{str(current_day.date())}' + }) + self._es_upload.es_upload_data(items=es_instance_types_data, es_index=self.INSTANCE_TYPES_ES_INDEX, + set_index='index_id') + def _update_instance_type_count(self): """ This method returns the instance types count by region @@ -20,16 +46,17 @@ def _update_instance_type_count(self): for instance in resources: instance_type = instance.get('InstanceType') instance_types.setdefault(self._region, {}).update( - {instance_type: instance_types.get(instance_type, 0) + 1} + {instance_type: instance_types.get(self._region).get(instance_type, 0) + 1} ) return instance_types - def _instance_run(self): + def run_policy_operations(self): """ This method returns the running instances :return: :rtype: """ + self._upload_instance_type_count_to_elastic_search() instances = self._get_al_instances() running_instances_data = [] for instance in instances: @@ -40,18 +67,19 @@ def _instance_run(self): cleanup_result = self.verify_and_delete_resource( resource_id=instance.get('InstanceId'), tags=tags, clean_up_days=cleanup_days) - resource_data = self._get_es_data_schema_format( + resource_data = self._get_es_schema( resource_id=instance.get('InstanceId'), skip_policy=self.get_skip_policy_value(tags=tags), user=self.get_tag_name_from_tags(tags=tags, tag_name='User'), launch_time=instance['LaunchTime'].strftime("%Y-%m-%dT%H:%M:%S+00:00"), - instance_type=instance.get('InstanceType'), - instance_state=instance.get('State', {}).get('Name') if not cleanup_result else 'stopped', + resource_type=instance.get('InstanceType'), + resource_state=instance.get('State', {}).get('Name') if not cleanup_result else 'stopped', + resource_action=self.RESOURCE_ACTION, running_days=running_days, cleanup_days=cleanup_days, dry_run=self._dry_run, name=self.get_tag_name_from_tags(tags=tags, tag_name='Name'), region=self._region, cleanup_result=str(cleanup_result), - cloud_name=self._cloud_name + cloud_name=self._cloud_name, ) if self._force_delete and self._dry_run == 'no': resource_data.update({'ForceDeleted': str(self._force_delete)}) diff --git a/cloud_governance/policy/azure/cleanup/instance_run.py b/cloud_governance/policy/azure/cleanup/instance_run.py index 6c03416ea..215cdb795 100644 --- a/cloud_governance/policy/azure/cleanup/instance_run.py +++ b/cloud_governance/policy/azure/cleanup/instance_run.py @@ -1,12 +1,40 @@ -from cloud_governance.common.helpers.azure.azure_policy_operations import AzurePolicyOperations -from cloud_governance.policy.abstract_policies.cleanup.abstractinstance_run import AbstractInstanceRun +from datetime import datetime +from cloud_governance.policy.helpers.azure.azure_policy_operations import AzurePolicyOperations -class InstanceRun(AbstractInstanceRun, AzurePolicyOperations): + +class InstanceRun(AzurePolicyOperations): + + INSTANCE_TYPES_ES_INDEX = "cloud-governance-instance-types" + RESOURCE_ACTION = "Stopped" def __init__(self): super().__init__() + def _upload_instance_type_count_to_elastic_search(self): + """ + This method uploads the data to elasticsearch + :return: + :rtype: + """ + instance_types = self._update_instance_type_count() + account = self.account + current_day = datetime.utcnow() + es_instance_types_data = [] + for region, instance_types in instance_types.items(): + for instance_type, instance_type_count in instance_types.items(): + es_instance_types_data.append({ + 'instance_type': instance_type, + 'instance_count': instance_type_count, + 'timestamp': current_day, + 'region': region, + 'account': account, + 'PublicCloud': self._cloud_name, + 'index_id': f'{instance_type}-{self._cloud_name.lower()}-{account.lower()}-{region}-{str(current_day.date())}' + }) + self._es_upload.es_upload_data(items=es_instance_types_data, es_index=self.INSTANCE_TYPES_ES_INDEX, + set_index='index_id') + def _update_instance_type_count(self): """ This method returns the instance type count by region @@ -43,12 +71,13 @@ def __get_instance_status(self, resource_id: str, vm_name: str): status = 'Unknown Status' return status - def _instance_run(self): + def run_policy_operations(self): """ This method returns the running vms in the AAzure cloud and stops based on the action :return: :rtype: """ + self._upload_instance_type_count_to_elastic_search() vms_list = self._get_al_instances() running_vms = [] for vm in vms_list: @@ -59,16 +88,17 @@ def _instance_run(self): cleanup_days = self.get_clean_up_days_count(tags=tags) cleanup_result = self.verify_and_delete_resource(resource_id=vm.id, tags=tags, clean_up_days=cleanup_days) - resource_data = self._get_es_data_schema_format( + resource_data = self._get_es_schema( resource_id=vm.name, skip_policy=self.get_skip_policy_value(tags=tags), user=self.get_tag_name_from_tags(tags=tags, tag_name='User'), launch_time=vm.time_created, - instance_type=vm.hardware_profile.vm_size, - instance_state=status if cleanup_result else 'Vm Stopped', + resource_type=vm.hardware_profile.vm_size, + resource_state=status if cleanup_result else 'Vm Stopped', running_days=running_days, cleanup_days=cleanup_days, dry_run=self._dry_run, name=vm.name, + resource_action=self.RESOURCE_ACTION, region=vm.location, cleanup_result=str(cleanup_result), cloud_name=self._cloud_name ) diff --git a/cloud_governance/common/helpers/__init__.py b/cloud_governance/policy/helpers/__init__.py similarity index 100% rename from cloud_governance/common/helpers/__init__.py rename to cloud_governance/policy/helpers/__init__.py diff --git a/cloud_governance/common/helpers/abstract_policy_operations.py b/cloud_governance/policy/helpers/abstract_policy_operations.py similarity index 75% rename from cloud_governance/common/helpers/abstract_policy_operations.py rename to cloud_governance/policy/helpers/abstract_policy_operations.py index 461ccc5d8..0cc2a1620 100644 --- a/cloud_governance/common/helpers/abstract_policy_operations.py +++ b/cloud_governance/policy/helpers/abstract_policy_operations.py @@ -2,6 +2,7 @@ from datetime import datetime from typing import Union +from cloud_governance.common.elasticsearch.elastic_upload import ElasticUpload from cloud_governance.main.environment_variables import environment_variables @@ -20,6 +21,7 @@ def __init__(self): self._policy = self._environment_variables_dict.get('policy') self._force_delete = self._environment_variables_dict.get('FORCE_DELETE') self._resource_id = self._environment_variables_dict.get('RESOURCE_ID') + self._es_upload = ElasticUpload() def calculate_days(self, create_date: Union[datetime, str]): """ @@ -156,3 +158,52 @@ def _get_al_instances(self): :rtype: """ raise NotImplementedError("This method not yet implemented") + + def _get_es_schema(self, resource_id: str, user: str, skip_policy: str, cleanup_days: int, dry_run: str, + name: str, region: str, cleanup_result: str, resource_action: str, cloud_name: str, + resource_state: str, resource_type: str, **kwargs): + """ + This method returns the es schema data format + :return: + :rtype: + """ + current_date = datetime.utcnow().date() + resource_data = { + 'ResourceId': resource_id, + 'User': user, + 'SkipPolicy': skip_policy, + 'ResourceType': resource_type, + 'ResourceState': resource_state, + 'CleanUpDays': cleanup_days, + 'DryRun': dry_run, + 'Name': name, + 'RegionName': region, + f'Resource{resource_action}': cleanup_result, + 'PublicCloud': cloud_name, + 'index-id': f'{current_date}-{cloud_name.lower()}-{self.account.lower()}-{region.lower()}-{resource_id}-{resource_state.lower()}' + } + if kwargs.get('launch_time'): + resource_data.update({'LaunchTime': kwargs.get('launch_time')}) + if kwargs.get('running_days'): + resource_data.update({'RunningDays': kwargs.get('running_days')}) + if kwargs.get('volume_size'): + resource_data.update({'VolumeSize': kwargs.get('volume_size')}) + + return resource_data + + @abstractmethod + def run_policy_operations(self): + """ + This method returns policy output + :return: + :rtype: + """ + pass + + def run(self): + """ + This method starts the policy operations + :return: + :rtype: + """ + return self.run_policy_operations() diff --git a/cloud_governance/common/helpers/aws/__init__.py b/cloud_governance/policy/helpers/aws/__init__.py similarity index 100% rename from cloud_governance/common/helpers/aws/__init__.py rename to cloud_governance/policy/helpers/aws/__init__.py diff --git a/cloud_governance/common/helpers/aws/aws_policy_operations.py b/cloud_governance/policy/helpers/aws/aws_policy_operations.py similarity index 96% rename from cloud_governance/common/helpers/aws/aws_policy_operations.py rename to cloud_governance/policy/helpers/aws/aws_policy_operations.py index c8492f09b..16772c9dc 100644 --- a/cloud_governance/common/helpers/aws/aws_policy_operations.py +++ b/cloud_governance/policy/helpers/aws/aws_policy_operations.py @@ -3,7 +3,7 @@ from cloud_governance.common.clouds.aws.ec2.ec2_operations import EC2Operations from cloud_governance.common.clouds.aws.s3.s3_operations import S3Operations -from cloud_governance.common.helpers.abstract_policy_operations import AbstractPolicyOperations +from cloud_governance.policy.helpers.abstract_policy_operations import AbstractPolicyOperations from cloud_governance.common.logger.init_logger import logger @@ -19,7 +19,6 @@ def __init__(self): self._s3_client = boto3.client('s3') self._iam_client = boto3.client('iam') - def get_tag_name_from_tags(self, tags: list, tag_name: str) -> str: """ This method returns the tag value from the tags @@ -139,3 +138,6 @@ def _get_al_instances(self): """ instances = self._ec2_operations.get_ec2_instance_list() return instances + + def run_policy_operations(self): + raise NotImplementedError("This method needs to be implemented") diff --git a/cloud_governance/common/helpers/azure/__init__.py b/cloud_governance/policy/helpers/azure/__init__.py similarity index 100% rename from cloud_governance/common/helpers/azure/__init__.py rename to cloud_governance/policy/helpers/azure/__init__.py diff --git a/cloud_governance/common/helpers/azure/azure_policy_operations.py b/cloud_governance/policy/helpers/azure/azure_policy_operations.py similarity index 93% rename from cloud_governance/common/helpers/azure/azure_policy_operations.py rename to cloud_governance/policy/helpers/azure/azure_policy_operations.py index f13c41a1e..0bbe97a59 100644 --- a/cloud_governance/common/helpers/azure/azure_policy_operations.py +++ b/cloud_governance/policy/helpers/azure/azure_policy_operations.py @@ -1,7 +1,7 @@ from cloud_governance.common.clouds.azure.compute.compute_operations import ComputeOperations from cloud_governance.common.clouds.azure.compute.resource_group_operations import ResourceGroupOperations -from cloud_governance.common.helpers.abstract_policy_operations import AbstractPolicyOperations +from cloud_governance.policy.helpers.abstract_policy_operations import AbstractPolicyOperations from cloud_governance.common.logger.init_logger import logger from cloud_governance.common.utils.utils import Utils @@ -88,4 +88,7 @@ def _get_al_instances(self): :return: :rtype: """ - return self.compute_operations.get_all_instances() \ No newline at end of file + return self.compute_operations.get_all_instances() + + def run_policy_operations(self): + raise NotImplementedError("This method needs to be implemented") diff --git a/cloud_governance/policy/policy_operations/aws/zombie_non_cluster/run_zombie_non_cluster_policies.py b/cloud_governance/policy/policy_operations/aws/zombie_non_cluster/run_zombie_non_cluster_policies.py index 9d8f7c198..f76ed2be7 100644 --- a/cloud_governance/policy/policy_operations/aws/zombie_non_cluster/run_zombie_non_cluster_policies.py +++ b/cloud_governance/policy/policy_operations/aws/zombie_non_cluster/run_zombie_non_cluster_policies.py @@ -10,7 +10,7 @@ from cloud_governance.common.clouds.aws.s3.s3_operations import S3Operations from cloud_governance.common.elasticsearch.elastic_upload import ElasticUpload from cloud_governance.common.elasticsearch.elasticsearch_operations import ElasticSearchOperations -from cloud_governance.common.helpers.aws.aws_policy_operations import AWSPolicyOperations +from cloud_governance.policy.helpers.aws.aws_policy_operations import AWSPolicyOperations from cloud_governance.common.ldap.ldap_search import LdapSearch from cloud_governance.common.logger.init_logger import logger from cloud_governance.common.mails.mail_message import MailMessage diff --git a/cloud_governance/policy/policy_runners/aws/upload_s3.py b/cloud_governance/policy/policy_runners/aws/upload_s3.py index 6abd3ddc1..01782d895 100644 --- a/cloud_governance/policy/policy_runners/aws/upload_s3.py +++ b/cloud_governance/policy/policy_runners/aws/upload_s3.py @@ -2,7 +2,7 @@ from typing import Union from cloud_governance.common.clouds.aws.s3.s3_operations import S3Operations -from cloud_governance.common.helpers.json_datetime_encoder import JsonDateTimeEncoder +from cloud_governance.common.utils.json_datetime_encoder import JsonDateTimeEncoder from cloud_governance.common.logger.init_logger import logger from cloud_governance.policy.policy_runners.common.abstract_upload import AbstractUpload diff --git a/tests/unittest/cloud_governance/common/clouds/aws/s3/test_s3_operations.py b/tests/unittest/cloud_governance/common/clouds/aws/s3/test_s3_operations.py index f08a3369c..2c961d118 100644 --- a/tests/unittest/cloud_governance/common/clouds/aws/s3/test_s3_operations.py +++ b/tests/unittest/cloud_governance/common/clouds/aws/s3/test_s3_operations.py @@ -1,5 +1,4 @@ import datetime -import json import boto3 import tempfile @@ -10,10 +9,8 @@ # walk around for moto DeprecationWarning import warnings -from cloud_governance.common.helpers.json_datetime_encoder import JsonDateTimeEncoder from cloud_governance.main.environment_variables import environment_variables from cloud_governance.main.main_oerations.main_operations import MainOperations -from cloud_governance.policy.aws.cleanup.instance_run import AbstractInstanceRun with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=DeprecationWarning) diff --git a/tests/unittest/cloud_governance/common/helpers/aws/test_aws_cleaup_operations.py b/tests/unittest/cloud_governance/common/helpers/aws/test_aws_cleaup_operations.py index 82accba38..8e323f573 100644 --- a/tests/unittest/cloud_governance/common/helpers/aws/test_aws_cleaup_operations.py +++ b/tests/unittest/cloud_governance/common/helpers/aws/test_aws_cleaup_operations.py @@ -3,7 +3,7 @@ import boto3 from moto import mock_ec2, mock_s3, mock_iam -from cloud_governance.common.helpers.aws.aws_policy_operations import AWSPolicyOperations +from cloud_governance.policy.helpers.aws.aws_policy_operations import AWSPolicyOperations from cloud_governance.main.environment_variables import environment_variables diff --git a/tests/unittest/cloud_governance/common/helpers/test_cleanup_operations.py b/tests/unittest/cloud_governance/common/helpers/test_cleanup_operations.py index eaf381cc0..d76075e03 100644 --- a/tests/unittest/cloud_governance/common/helpers/test_cleanup_operations.py +++ b/tests/unittest/cloud_governance/common/helpers/test_cleanup_operations.py @@ -3,7 +3,7 @@ import boto3 from moto import mock_ec2, mock_s3, mock_iam -from cloud_governance.common.helpers.aws.aws_policy_operations import AWSPolicyOperations +from cloud_governance.policy.helpers.aws.aws_policy_operations import AWSPolicyOperations from cloud_governance.main.environment_variables import environment_variables diff --git a/tests/unittest/cloud_governance/common/helpers/test_json_datetime_encoder.py b/tests/unittest/cloud_governance/common/helpers/test_json_datetime_encoder.py index 1dc3c17c5..9cacf75ea 100644 --- a/tests/unittest/cloud_governance/common/helpers/test_json_datetime_encoder.py +++ b/tests/unittest/cloud_governance/common/helpers/test_json_datetime_encoder.py @@ -1,7 +1,7 @@ import datetime import json -from cloud_governance.common.helpers.json_datetime_encoder import JsonDateTimeEncoder +from cloud_governance.policy.helpers import JsonDateTimeEncoder def test_json_datetime_encoder(): diff --git a/tests/unittest/cloud_governance/policy/aws/cleanup/test_instance_run.py b/tests/unittest/cloud_governance/policy/aws/cleanup/test_instance_run.py index 723c676ca..62a5fbef7 100644 --- a/tests/unittest/cloud_governance/policy/aws/cleanup/test_instance_run.py +++ b/tests/unittest/cloud_governance/policy/aws/cleanup/test_instance_run.py @@ -3,7 +3,7 @@ import boto3 from moto import mock_ec2, mock_s3, mock_iam -from cloud_governance.common.helpers.aws.aws_policy_operations import AWSPolicyOperations +from cloud_governance.policy.helpers.aws.aws_policy_operations import AWSPolicyOperations from cloud_governance.main.environment_variables import environment_variables from cloud_governance.policy.aws.cleanup.instance_run import InstanceRun @@ -30,7 +30,7 @@ def test_instance_run(): instance_run = InstanceRun() running_instances_data = instance_run.run() assert running_instances_data[0].get('ResourceStopped') == 'False' - assert running_instances_data[0].get('InstanceState') == 'running' + assert running_instances_data[0].get('ResourceState') == 'running' @mock_ec2