Beispiel #1
0
 def test_create_snapshot(self):
     """
     Verify setting a tag on an EC2 snapshot creation event.
     """
     with open('../test_event_data/ec2_CreateSnapshot.json') as create_snapshot:
         detail = json.load(create_snapshot)
     event = {'account': ACCOUNT, 'region': REGION, 'detail': detail}
     path = os.path.join(os.path.dirname(__file__), '../local-aws-response/create_snapshot')
     attach_local_aws_response(path)
     self.assertEqual(ec2_lambda_handler(event, ''), True)
Beispiel #2
0
 def test_iam_user(self):
     """
     Verify setting an EC2 tag when the creator is a regular IAM user.
     """
     with open('../test_event_data/ec2_iam_user.json') as iam_user:
         detail = json.load(iam_user)
     event = {'account': ACCOUNT, 'region': REGION, 'detail': detail}
     path = os.path.join(os.path.dirname(__file__), '../local-aws-response/iam_user')
     attach_local_aws_response(path)
     self.assertEqual(ec2_lambda_handler(event, ''), True)
Beispiel #3
0
 def test_create_s3_bucket(self):
     """
     Verifies setting an S3 Bucket Creator tag.
     """
     with open('../test_event_data/s3_CreateBucket.json') as s3_bucket:
         detail = json.load(s3_bucket)
     event = {'account': ACCOUNT, 'region': REGION, 'detail': detail}
     path = os.path.join(os.path.dirname(__file__),
                         '../local-aws-response/create_S3Bucket')
     attach_local_aws_response(path)
     self.assertEqual(s3_lambda_handler(event, ''), True)
Beispiel #4
0
 def test_reboot_instances(self):
     """
     Verify setting owner tag on an EC2 instance, volumes, and network interfaces
     when the interface is rebooted.
     """
     with open('../test_event_data/ec2_RebootInstances.json') as reboot_instances:
         detail = json.load(reboot_instances)
     event = {'account': ACCOUNT, 'region': REGION, 'detail': detail}
     path = os.path.join(os.path.dirname(__file__), '../local-aws-response/reboot_instances')
     attach_local_aws_response(path)
     self.assertEqual(ec2_lambda_handler(event, ''), True)
Beispiel #5
0
 def test_create_db_instance(self):
     """
     Verify setting a tag on a DB instance creation event.
     """
     with open(
             '../test_event_data/rds_CreateDBInstance.json') as db_instance:
         detail = json.load(db_instance)
     event = {'account': ACCOUNT, 'region': REGION, 'detail': detail}
     path = os.path.join(os.path.dirname(__file__),
                         '../local-aws-response/create_DBInstance')
     attach_local_aws_response(path)
     self.assertEqual(rds_lambda_handler(event, ''), True)
Beispiel #6
0
 def test_create_option_group(self):
     """
     Verify setting a tag on a option group creation event.
     """
     with open('../test_event_data/rds_CreateOptionGroup.json'
               ) as option_group:
         detail = json.load(option_group)
     event = {'account': ACCOUNT, 'region': REGION, 'detail': detail}
     path = os.path.join(os.path.dirname(__file__),
                         '../local-aws-response/create_DBOptionGroup')
     attach_local_aws_response(path)
     self.assertEqual(rds_lambda_handler(event, ''), True)
Beispiel #7
0
 def test_put_s3_object(self):
     """
     Verifies setting an S3 Object Creator tag.
     Object uploaded by IAM user.
     """
     with open('../test_event_data/s3_PutObject.json') as s3_object:
         detail = json.load(s3_object)
     event = {'account': ACCOUNT, 'region': REGION, 'detail': detail}
     path = os.path.join(os.path.dirname(__file__),
                         '../local-aws-response/put_S3Object')
     attach_local_aws_response(path)
     self.assertEqual(s3_lambda_handler(event, ''), True)
Beispiel #8
0
    def test_create_cluster_sfn_max_retries(self):
        """
        Verifies the event state when maximum retries have been reached.

        @return: True if the event response from the Lambda is as expected.
        """
        with open('../test_event_data/redshift_SFN_CreateCluster.json'
                  ) as cluster:
            detail = json.load(cluster)
        attach_local_aws_response(path='')
        self.assertEqual(
            redshift_sfn_lambda_handler(detail, '')['TagStatus'],
            'max retries reached')
Beispiel #9
0
    def test_create_cluster_sfn_complete(self):
        """
        Verifies the event state has status "complete" when tagging where retries remaining.

        @return: True if the event response from the Lambda is as expected.
        """
        with open('../test_event_data/redshift_SFN_CreateCluster.json'
                  ) as cluster:
            detail = json.load(cluster)
        detail['MaxRetries'] = 10
        path = os.path.join(
            os.path.dirname(__file__),
            '../local-aws-response/create_RedshiftCluster_SFN')
        attach_local_aws_response(path)
        self.assertEqual(
            redshift_sfn_lambda_handler(detail, '')['TagStatus'], 'complete')
Beispiel #10
0
    def test_create_cluster(self):
        """
        Verifies the Step Function state machine starts and the cluster is tagged.

        @return: True if asserts as expected
        """
        with open('../test_event_data/redshift_CreateCluster.json') as cluster:
            detail = json.load(cluster)
        event = {'account': ACCOUNT, 'region': REGION, 'detail': detail}
        path = os.path.join(os.path.dirname(__file__),
                            '../local-aws-response/create_RedshiftCluster')
        attach_local_aws_response(path)
        with patch.dict(
                os.environ,
            {
                'SFN_MAX_RETRIES':
                '30',
                'SFN_ARN':
                'arn:aws:states:us-east-1:292909299215:stateMachine:AutoTag-Redshift-SFN'
            }):
            self.assertEqual(redshift_lambda_handler(event, ''), True)