Example #1
0
    def setUpClass(cls):
        if not sys.warnoptions:
            import warnings
            warnings.simplefilter("ignore")

        cls.logger = ConsoleLogger()

        cls.task_runner = get_task_runner(TESTED_ACTION,
                                          KEEP_AND_USE_EXISTING_ACTION_STACK)

        cls.resource_stack = get_resource_stack(
            TESTED_ACTION,
            create_resource_stack_func=cls.create_resource_stack,
            use_existing=KEEP_AND_USE_EXISTING_RESOURCES_STACK,
            region_name=region())

        assert (cls.resource_stack is not None)

        cls.ec2 = Ec2(region())

        cls.volume_unencrypted = cls.resource_stack.stack_outputs[
            "VolumeIdEncryptedUnencrypted"]
        cls.volume_encrypted_default = cls.resource_stack.stack_outputs[
            "VolumeIdEncryptedDefault"]
        cls.volume_encrypted_custom = cls.resource_stack.stack_outputs[
            "VolumeIdEncryptedCustom"]
        cls.custom_key_arn = cls.resource_stack.stack_outputs[
            "EncryptionKeyArn"]
Example #2
0
    def setUpClass(cls):
        if not sys.warnoptions:
            import warnings
            warnings.simplefilter("ignore")

        cls.logger = ConsoleLogger()

        cls.resource_stack = get_resource_stack(
            TESTED_ACTION,
            create_resource_stack_func=cls.create_resource_stack,
            use_existing=KEEP_AND_USE_EXISTING_RESOURCES_STACK,
            region_name=region())
        assert (cls.resource_stack is not None)

        cls.instance_id = cls.resource_stack.stack_outputs["InstanceId0"]
        cls.root_volume = Ec2(region()).get_root_volume(cls.instance_id)
        cls.data_volumes = [
            cls.resource_stack.stack_outputs["VolumeId0"],
            cls.resource_stack.stack_outputs["VolumeId1"]
        ]

        cls.task_runner = get_task_runner(TESTED_ACTION,
                                          KEEP_AND_USE_EXISTING_ACTION_STACK)

        cls.ec2 = Ec2(region())
Example #3
0
    def setUpClass(cls):

        cls.ec2 = Ec2(region())
        cls.elb = Elb(region())
        cls.elbv2 = ElbV2(region())
        cls.logger = ConsoleLogger()

        cls.resource_stack = get_resource_stack(TESTED_ACTION,
                                                create_resource_stack_func=cls.create_resource_stack,
                                                use_existing=KEEP_AND_USE_EXISTING_RESOURCES_STACK,
                                                region_name=region())

        assert (cls.resource_stack is not None)

        cls.v1_elb_name = cls.resource_stack.stack_outputs["V1LoadBalancerName"]
        cls.v2_target_group_arn = cls.resource_stack.stack_outputs["V2TargetGroupArn"]
        cls.instance_profile = cls.resource_stack.stack_outputs["InstanceProfile"]

        # noinspection PyPep8,PyBroadException
        try:
            cls.ec2.ec2_service.get(services.ec2_service.KEY_PAIRS, KeyNames=[TESTED_ACTION], region=region())
            cls.key_pair = TESTED_ACTION
        except:
            cls.key_pair = cls.ec2.ec2_client.create_key_pair(KeyName=TESTED_ACTION).get("KeyName")

        cls.ami_single_volume = cls.ec2.latest_aws_linux_image["ImageId"]

        cls.task_runner = get_task_runner(TESTED_ACTION, KEEP_AND_USE_EXISTING_ACTION_STACK)
Example #4
0
    def setUpClass(cls):
        if not sys.warnoptions:
            import warnings
            warnings.simplefilter("ignore")

        cls.logger = ConsoleLogger()

        cls.resource_stack = get_resource_stack(
            TESTED_ACTION,
            create_resource_stack_func=cls.create_resource_stack,
            use_existing=KEEP_AND_USE_EXISTING_RESOURCES_STACK,
            region_name=region())
        assert (cls.resource_stack is not None)

        cls.instance_no_cpu_load = cls.resource_stack.stack_outputs[
            "InstanceNoCPULoad"]
        cls.instance_cpu_load = cls.resource_stack.stack_outputs[
            "InstanceCPULoad"]

        cls.task_runner = get_task_runner(
            TESTED_ACTION,
            KEEP_AND_USE_EXISTING_ACTION_STACK,
            interval="0/{} * * * ?".format(INTERVAL_MINUTES))

        cls.ec2 = Ec2(region())

        testing.tags.set_ec2_tag_to_delete(
            ec2_client=cls.ec2,
            resource_ids=[cls.instance_no_cpu_load, cls.instance_cpu_load])

        cls.metrics_client = CloudwatchMetrics(region())
Example #5
0
    def setUpClass(cls):
        if not sys.warnoptions:
            import warnings
            warnings.simplefilter("ignore")

        cls.logger = ConsoleLogger()

        cls.resource_stack = get_resource_stack(
            TESTED_ACTION,
            create_resource_stack_func=cls.create_resource_stack,
            use_existing=KEEP_AND_USE_EXISTING_RESOURCES_STACK,
            region_name=region())

        assert (cls.resource_stack is not None)

        cls.ec2 = Ec2(region())
        cls.instance_id = cls.resource_stack.stack_outputs["InstanceId"]
        if KEEP_AND_USE_EXISTING_ACTION_STACK:
            cls.ec2.start_instance(cls.instance_id)

        testing.tags.set_ec2_tag_to_delete(ec2_client=cls.ec2,
                                           resource_ids=[cls.instance_id])

        cls.task_runner = get_task_runner(TESTED_ACTION,
                                          KEEP_AND_USE_EXISTING_ACTION_STACK)

        tags = cls.ec2.get_instance_tags(cls.instance_id)
        cls.original_tags = {
            t: tags[t]
            for t in tags if not t.startswith("aws:")
        }
Example #6
0
    def test_copy_snapshot_encrypt_with_custom_key_other_region(self):

        destination_ec2 = Ec2(region=remote_region())

        self.logger.test("Creating stack in destination region with custom encryption key")
        remote_stack = get_resource_stack(TESTED_ACTION, create_resource_stack_func=self.create_remote_resource_stack,
                                          use_existing=KEEP_AND_USE_EXISTING_RESOURCES_STACK, region_name=remote_region())

        remote_snapshot_copy_id = None
        try:

            remote_custom_key_arn = remote_stack.stack_outputs["EncryptionKeyArn"]

            test_method = inspect.stack()[0][3]

            self.cleanup_leftover_source_snapshots(test_method)

            self.logger.test("Creating source snapshot")
            source_snapshot_unencrypted = self.ec2.create_snapshot(self.volume_unencrypted, tags={
                "Name": "Ec2CopySnapshot_{}".format(test_method),
                tasklist_tagname(TESTED_ACTION): test_method
            }, description="Snapshot for testing Ec2CopySnapshot : {}".format(test_method))
            assert (source_snapshot_unencrypted is not None)
            self.snapshots.append(source_snapshot_unencrypted["SnapshotId"])

            parameters = {
                copy_snapshot.PARAM_DESTINATION_REGION: remote_region(),
                copy_snapshot.PARAM_ENCRYPTED: True,
                copy_snapshot.PARAM_KMS_KEY_ID: remote_custom_key_arn
            }

            self.snapshots.append(source_snapshot_unencrypted["SnapshotId"])

            self.logger.test("Running task")
            self.task_runner.run(parameters,
                                 task_name=test_method,
                                 complete_check_polling_interval=10)
            self.assertTrue(self.task_runner.success(), "Task executed successfully")
            remote_snapshot_copy_id = self.task_runner.results[0].result["copy-snapshot-id"]
            self.logger.test("[X] Task completed")

            self.logger.test("Checking snapshot copy")
            snapshot_copy = destination_ec2.get_snapshot(remote_snapshot_copy_id)
            self.assertIsNotNone(snapshot_copy, "Snapshot created in destination region")
            self.assertTrue(snapshot_copy["Encrypted"], "Snapshot is encrypted")
            self.assertEqual(snapshot_copy["KmsKeyId"], remote_custom_key_arn, "Custom encryption key is used")
            self.logger.test("[X] Snapshot created and encrypted")

        finally:
            if not KEEP_AND_USE_EXISTING_RESOURCES_STACK and remote_stack is not None:
                remote_stack.delete_stack(600)
            if remote_snapshot_copy_id is not None:
                destination_ec2.delete_snapshots([remote_snapshot_copy_id])
Example #7
0
    def setUpClass(cls):

        cls.logger = ConsoleLogger()

        cls.resource_stack = get_resource_stack(TESTED_ACTION,
                                                create_resource_stack_func=cls.create_resource_stack,
                                                use_existing=KEEP_AND_USE_EXISTING_RESOURCES_STACK, region_name=region())
        assert (cls.resource_stack is not None)
        cls.volume_id = cls.resource_stack.stack_outputs["VolumeId0"]

        cls.ec2 = Ec2(region())

        cls.task_runner = get_task_runner(TESTED_ACTION, KEEP_AND_USE_EXISTING_ACTION_STACK)
Example #8
0
    def setUpClass(cls):

        cls.logger = ConsoleLogger()

        cls.resource_stack = get_resource_stack(
            TESTED_ACTION,
            create_resource_stack_func=cls.create_resource_stack,
            use_existing=KEEP_AND_USE_EXISTING_RESOURCES_STACK,
            region_name=region())
        assert (cls.resource_stack is not None)

        cls.dynamodb = DynamoDB(region=region())

        cls.table_name = cls.resource_stack.stack_outputs["TableName"]
        cls.task_runner = get_task_runner(TESTED_ACTION,
                                          KEEP_AND_USE_EXISTING_ACTION_STACK)

        cls.logger.debug(
            "Waiting for continuous backups to become available for table {}",
            cls.table_name)
        assert (cls.dynamodb.wait_until_table_backups_available(
            cls.table_name))