def test_launch_ebs_instance_with_creating_blank_volume(self):
        """Launch instance with creating blank volume."""
        device_name_prefix = base.get_device_name_prefix(self.root_device_name)
        device_name = device_name_prefix + 'b'

        instance_id = self.run_instance(ImageId=self.image_id,
                                        BlockDeviceMappings=[{
                                            'DeviceName': device_name,
                                            'Ebs': {
                                                'VolumeSize': 1
                                            }
                                        }])

        bdt = self.get_instance_bdm(instance_id, device_name)
        self.assertIsNotNone(bdt)
        volume_id = bdt['Ebs'].get('VolumeId')
        self.assertIsNotNone(volume_id)
        self.assertTrue(bdt['Ebs']['DeleteOnTermination'])

        data = self.client.describe_volumes(VolumeIds=[volume_id])
        self.assertEqual(1, len(data['Volumes']))
        volume = data['Volumes'][0]
        self.assertEqual(1, volume['Size'])

        self.client.terminate_instances(InstanceIds=[instance_id])
        self.get_instance_waiter().wait_delete(instance_id)
Exemple #2
0
    def test_check_bdm_in_image(self):
        image_id = CONF.aws.ebs_image_id
        data = self.client.describe_images(ImageIds=[image_id])
        root_device_name = data['Images'][0]['RootDeviceName']
        device_name_prefix = base.get_device_name_prefix(root_device_name)
        device_name = device_name_prefix + 'h'

        name = data_utils.rand_name('image')
        desc = data_utils.rand_name('description')
        image_id, image_clean = self._create_image(name,
                                                   desc,
                                                   extra_run_instance_args={
                                                       'BlockDeviceMappings':
                                                       [{
                                                           'DeviceName':
                                                           device_name,
                                                           'Ebs': {
                                                               'VolumeSize': 1
                                                           }
                                                       }]
                                                   })

        data = self.client.describe_images(ImageIds=[image_id])
        image = data['Images'][0]

        for bdm in image['BlockDeviceMappings']:
            self.assertTrue('DeviceName', bdm)

        data = self.client.deregister_image(ImageId=image_id)
        self.cancelResourceCleanUp(image_clean)
    def test_launch_instance_with_creating_blank_volume(self):
        """Launch instance with creating blank volume."""
        data = self.client.describe_images(ImageIds=[CONF.aws.image_id])
        # NOTE(ft): ec2 api doesn't report root device name if it isn't
        # explicity contained in an image. So we assume it is /dev/vda,
        # which is true for only qemu hypervisor though.
        device_name_prefix = base.get_device_name_prefix(
            data['Images'][0].get('RootDeviceName', '/dev/vda'))
        device_name = device_name_prefix + 'b'
        instance_type = CONF.aws.instance_type
        data = self.client.run_instances(
            ImageId=CONF.aws.image_id, InstanceType=instance_type,
            Placement={'AvailabilityZone': self.zone}, MinCount=1, MaxCount=1,
            BlockDeviceMappings=[{'DeviceName': device_name,
                                  'Ebs': {'VolumeSize': 1}}])
        instance_id = data['Instances'][0]['InstanceId']
        res_clean = self.addResourceCleanUp(self.client.terminate_instances,
                                            InstanceIds=[instance_id])
        self.get_instance_waiter().wait_available(instance_id,
                                                  final_set=('running'))

        bdt = self.get_instance_bdm(instance_id, device_name)
        self.assertIsNotNone(bdt)
        volume_id = bdt['Ebs'].get('VolumeId')
        self.assertIsNotNone(volume_id)
        self.assertTrue(bdt['Ebs']['DeleteOnTermination'])

        data = self.client.describe_volumes(VolumeIds=[volume_id])
        self.assertEqual(1, len(data['Volumes']))
        volume = data['Volumes'][0]
        self.assertEqual(1, volume['Size'])

        self.client.terminate_instances(InstanceIds=[instance_id])
        self.cancelResourceCleanUp(res_clean)
        self.get_instance_waiter().wait_delete(instance_id)
Exemple #4
0
    def test_launch_instance_with_creating_blank_volume(self):
        """Launch instance with creating blank volume."""
        data = self.client.describe_images(ImageIds=[CONF.aws.image_id])
        # NOTE(ft): ec2 api doesn't report root device name if it isn't
        # explicity contained in an image. So we assume it is /dev/vda,
        # which is true for only qemu hypervisor though.
        device_name_prefix = base.get_device_name_prefix(data['Images'][0].get(
            'RootDeviceName', '/dev/vda'))
        device_name = device_name_prefix + 'b'
        instance_type = CONF.aws.instance_type
        data = self.client.run_instances(
            ImageId=CONF.aws.image_id,
            InstanceType=instance_type,
            Placement={'AvailabilityZone': self.zone},
            MinCount=1,
            MaxCount=1,
            BlockDeviceMappings=[{
                'DeviceName': device_name,
                'Ebs': {
                    'VolumeSize': 1
                }
            }])
        instance_id = data['Instances'][0]['InstanceId']
        res_clean = self.addResourceCleanUp(self.client.terminate_instances,
                                            InstanceIds=[instance_id])
        self.get_instance_waiter().wait_available(instance_id,
                                                  final_set=('running'))

        bdt = self.get_instance_bdm(instance_id, device_name)
        self.assertIsNotNone(bdt)
        volume_id = bdt['Ebs'].get('VolumeId')
        self.assertIsNotNone(volume_id)
        self.assertTrue(bdt['Ebs']['DeleteOnTermination'])

        data = self.client.describe_volumes(VolumeIds=[volume_id])
        self.assertEqual(1, len(data['Volumes']))
        volume = data['Volumes'][0]
        self.assertEqual(1, volume['Size'])

        self.client.terminate_instances(InstanceIds=[instance_id])
        self.cancelResourceCleanUp(res_clean)
        self.get_instance_waiter().wait_delete(instance_id)
Exemple #5
0
    def test_launch_ebs_instance_with_creating_blank_volume(self):
        """Launch instance with creating blank volume."""
        device_name_prefix = base.get_device_name_prefix(self.root_device_name)
        device_name = device_name_prefix + 'b'

        instance_id = self.run_instance(ImageId=self.image_id,
            BlockDeviceMappings=[{'DeviceName': device_name,
                                  'Ebs': {'VolumeSize': 1}}])

        bdt = self.get_instance_bdm(instance_id, device_name)
        self.assertIsNotNone(bdt)
        volume_id = bdt['Ebs'].get('VolumeId')
        self.assertIsNotNone(volume_id)
        self.assertTrue(bdt['Ebs']['DeleteOnTermination'])

        data = self.client.describe_volumes(VolumeIds=[volume_id])
        self.assertEqual(1, len(data['Volumes']))
        volume = data['Volumes'][0]
        self.assertEqual(1, volume['Size'])

        self.client.terminate_instances(InstanceIds=[instance_id])
        self.get_instance_waiter().wait_delete(instance_id)
Exemple #6
0
    def test_check_bdm_in_image(self):
        image_id = CONF.aws.ebs_image_id
        data = self.client.describe_images(ImageIds=[image_id])
        root_device_name = data['Images'][0]['RootDeviceName']
        device_name_prefix = base.get_device_name_prefix(root_device_name)
        device_name = device_name_prefix + 'h'

        name = data_utils.rand_name('image')
        desc = data_utils.rand_name('description')
        image_id, image_clean = self._create_image(
            name, desc,
            extra_run_instance_args={
                'BlockDeviceMappings': [{'DeviceName': device_name,
                                         'Ebs': {'VolumeSize': 1}}]})

        data = self.client.describe_images(ImageIds=[image_id])
        image = data['Images'][0]

        for bdm in image['BlockDeviceMappings']:
            self.assertTrue('DeviceName', bdm)

        data = self.client.deregister_image(ImageId=image_id)
        self.cancelResourceCleanUp(image_clean)
Exemple #7
0
    def setUpClass(cls):
        super(EC2_EBSInstanceAttaching, cls).setUpClass()

        if not CONF.aws.run_incompatible_tests:
            raise cls.skipException('Decsribe returns full device name while '
                                    'we boot with short name.')

        if not CONF.aws.ebs_image_id:
            raise cls.skipException('aws EBS image does not provided')
        cls.image_id = CONF.aws.ebs_image_id
        cls.zone = CONF.aws.aws_zone

        data = cls.client.describe_images(ImageIds=[cls.image_id])
        assert 1 == len(data['Images'])
        image = data['Images'][0]
        root_device_name = image['RootDeviceName']

        device_name_prefix = base.get_device_name_prefix(root_device_name)
        cls.full_device_name_prefix = device_name_prefix
        cls.short_device_name_prefix = device_name_prefix[len("/dev/"):]

        data = cls.client.create_volume(AvailabilityZone=cls.zone,
                                             Size=1)
        cls.volume_id = data['VolumeId']
        cls.addResourceCleanUpStatic(cls.client.delete_volume,
                                     VolumeId=cls.volume_id)
        cls.get_volume_waiter().wait_available(cls.volume_id)

        data = cls.client.create_snapshot(VolumeId=cls.volume_id)
        cls.snapshot_id = data['SnapshotId']
        cls.addResourceCleanUpStatic(cls.client.delete_snapshot,
                                     SnapshotId=cls.snapshot_id)
        cls.get_snapshot_waiter().wait_available(cls.snapshot_id,
                                                 final_set=('completed'))

        instance_type = CONF.aws.instance_type
        cls.device1_name = cls.full_device_name_prefix + "d"
        cls.device2_name = cls.short_device_name_prefix + "h"
        data = cls.client.run_instances(
            ImageId=cls.image_id, InstanceType=instance_type,
            Placement={'AvailabilityZone': cls.zone}, MinCount=1, MaxCount=1,
            BlockDeviceMappings=[{'DeviceName': cls.device1_name,
                                  'Ebs': {'SnapshotId': cls.snapshot_id,
                                          'DeleteOnTermination': True}},
                                 {'DeviceName': cls.device2_name,
                                  'Ebs': {'SnapshotId': cls.snapshot_id,
                                          'DeleteOnTermination': True}}])
        instance_id = data['Instances'][0]['InstanceId']
        cls.instance_id = instance_id
        cls.addResourceCleanUpStatic(cls.client.terminate_instances,
                                     InstanceIds=[instance_id])
        cls.get_instance_waiter().wait_available(instance_id,
                                                 final_set=('running'))

        data = cls.client.describe_instances(InstanceIds=[instance_id])
        assert 1 == len(data.get('Reservations', []))
        instances = data['Reservations'][0].get('Instances', [])
        assert 1 == len(instances)
        instance = instances[0]
        bdms = instance['BlockDeviceMappings']
        for bdt in bdms:
            if bdt['DeviceName'] == cls.device1_name:
                cls.volume_id1 = bdt['Ebs']['VolumeId']
            if bdt['DeviceName'] == cls.device2_name:
                cls.volume_id2 = bdt['Ebs']['VolumeId']
        assert cls.volume_id1
        assert cls.volume_id2
Exemple #8
0
    def setUpClass(cls):
        super(EC2_EBSInstanceAttaching, cls).setUpClass()

        if not CONF.aws.run_incompatible_tests:
            raise cls.skipException('Decsribe returns full device name while '
                                    'we boot with short name.')

        if not CONF.aws.ebs_image_id:
            raise cls.skipException('aws EBS image does not provided')
        cls.image_id = CONF.aws.ebs_image_id
        cls.zone = CONF.aws.aws_zone

        data = cls.client.describe_images(ImageIds=[cls.image_id])
        assert 1 == len(data['Images'])
        image = data['Images'][0]
        root_device_name = image['RootDeviceName']

        device_name_prefix = base.get_device_name_prefix(root_device_name)
        cls.full_device_name_prefix = device_name_prefix
        cls.short_device_name_prefix = device_name_prefix[len("/dev/"):]

        data = cls.client.create_volume(AvailabilityZone=cls.zone,
                                             Size=1)
        cls.volume_id = data['VolumeId']
        cls.addResourceCleanUpStatic(cls.client.delete_volume,
                                     VolumeId=cls.volume_id)
        cls.get_volume_waiter().wait_available(cls.volume_id)

        data = cls.client.create_snapshot(VolumeId=cls.volume_id)
        cls.snapshot_id = data['SnapshotId']
        cls.addResourceCleanUpStatic(cls.client.delete_snapshot,
                                     SnapshotId=cls.snapshot_id)
        cls.get_snapshot_waiter().wait_available(cls.snapshot_id,
                                                 final_set=('completed'))

        instance_type = CONF.aws.instance_type
        cls.device1_name = cls.full_device_name_prefix + "d"
        cls.device2_name = cls.short_device_name_prefix + "h"
        data = cls.client.run_instances(
            ImageId=cls.image_id, InstanceType=instance_type,
            Placement={'AvailabilityZone': cls.zone}, MinCount=1, MaxCount=1,
            BlockDeviceMappings=[{'DeviceName': cls.device1_name,
                                  'Ebs': {'SnapshotId': cls.snapshot_id,
                                          'DeleteOnTermination': True}},
                                 {'DeviceName': cls.device2_name,
                                  'Ebs': {'SnapshotId': cls.snapshot_id,
                                          'DeleteOnTermination': True}}])
        instance_id = data['Instances'][0]['InstanceId']
        cls.instance_id = instance_id
        cls.addResourceCleanUpStatic(cls.client.terminate_instances,
                                     InstanceIds=[instance_id])
        cls.get_instance_waiter().wait_available(instance_id,
                                                 final_set=('running'))

        data = cls.client.describe_instances(InstanceIds=[instance_id])
        assert 1 == len(data.get('Reservations', []))
        instances = data['Reservations'][0].get('Instances', [])
        assert 1 == len(instances)
        instance = instances[0]
        bdms = instance['BlockDeviceMappings']
        for bdt in bdms:
            if bdt['DeviceName'] == cls.device1_name:
                cls.volume_id1 = bdt['Ebs']['VolumeId']
            if bdt['DeviceName'] == cls.device2_name:
                cls.volume_id2 = bdt['Ebs']['VolumeId']
        assert cls.volume_id1
        assert cls.volume_id2