def test_force_delete_inst_before_deferred_cleanup(
            self, set_recl_inst_interv, instances, volumes):
        """Force delete of instance before deferred cleanup
        Actions:
        1. Update '/etc/nova/nova.conf' with long 'reclaim_instance_interval'
        and restart Nova on all nodes;
        2. Create net and subnet;
        3. Create and run two instances (vm1, vm2) inside same net;
        4. Create a volume and attach it to an instance vm1;
        5. Delete instance vm1 and check that it's in 'SOFT_DELETE' state;
        6. Delete instance vm1 with 'force' option and check that it's not
        present.
        7. Check that volume is released now and has an Available state;
        8. Attach the volume to vm2 instance to ensure that the volume's reuse
        doesn't call any errors.
        """
        timeout = 60  # (sec) timeout to wait instance for status change

        # Create two vms
        vm1, vm2 = instances

        # Create a volume and attach it to an instance vm1
        volume = common_functions.create_volume(
            self.os_conn.cinder, image_id=None)
        self.os_conn.nova.volumes.create_server_volume(
            server_id=vm1.id, volume_id=volume.id, device='/dev/vdb')
        volumes.append(volume)

        # Delete instance vm1 and check that it's in "SOFT_DELETED" state
        common_functions.delete_instance(self.os_conn.nova, vm1.id)
        assert vm1 not in self.os_conn.get_servers()
        common_functions.wait(
            lambda: self.os_conn.server_status_is(vm1, 'SOFT_DELETED'),
            timeout_seconds=timeout, sleep_seconds=5,
            waiting_for='instance {0} changes status to SOFT_DELETED'.format(
                vm1.name))

        # Force delete and check vm1 not present
        common_functions.delete_instance(self.os_conn.nova, vm1.id, force=True)
        common_functions.wait(
            lambda: self.os_conn.is_server_deleted(vm1.id),
            timeout_seconds=timeout, sleep_seconds=5,
            waiting_for='instance {0} to be forced deleted'.format(vm1.name))

        # Check that volume is released now and has an Available state
        assert common_functions.check_volume_status(
            self.os_conn.cinder, volume.id, 'available', 1)

        # Check volume is not attached
        assert self.os_conn.cinder.volumes.get(volume.id).attachments == []

        # Attach the volume to vm2 instance
        self.os_conn.nova.volumes.create_server_volume(
            server_id=vm2.id, volume_id=volume.id, device='/dev/vdb')
        # Check volume status is 'in-use' after re-attach
        assert common_functions.check_volume_status(
            self.os_conn.cinder, volume.id, 'in-use', 1)
        # Check that volume has correct server id
        volume = self.os_conn.cinder.volumes.get(volume.id)
        assert volume.attachments[0]['server_id'] == vm2.id
Exemplo n.º 2
0
    def test_resize_down_an_instance_booted_from_volume(self):
        """This test checks that nova allows
            resize down an instance booted from volume
            Steps:
            1. Create bootable volume
            2. Boot instance from newly created volume
            3. Resize instance from m1.small to m1.tiny
        """

        # 1. Create bootable volume
        image_id = [image.id for image in self.nova.images.list() if
                    image.name == 'TestVM'][0]

        volume = common_functions.create_volume(self.cinder, image_id,
                                                timeout=60)
        self.volumes.append(volume)

        # 2. Create instance from newly created volume, associate floating_ip
        name = 'TestVM_543355_instance_to_resize'
        networks = self.neutron.list_networks()['networks']
        net = [net['id'] for net in networks if not net['router:external']][0]
        flavor_list = {f.name: f.id for f in self.nova.flavors.list()}
        initial_flavor = flavor_list['m1.small']
        resize_flavor = flavor_list['m1.tiny']
        bdm = {'vda': volume.id}
        instance = common_functions.create_instance(self.nova,
                                                    name, initial_flavor, net,
                                                    [self.sec_group.name],
                                                    block_device_mapping=bdm,
                                                    inst_list=self.instances)
        self.instances.append(instance.id)

        # Assert for attached volumes
        attached_volumes = self.nova.servers.get(instance).to_dict()[
            'os-extended-volumes:volumes_attached']
        self.assertIn({'id': volume.id}, attached_volumes)

        # Assert to flavor size
        self.assertEqual(self.nova.servers.get(instance).flavor['id'],
                         initial_flavor,
                         "Unexpected instance flavor before resize")

        floating_ip = self.nova.floating_ips.create()
        self.floating_ips.append(floating_ip.ip)
        instance.add_floating_ip(floating_ip.ip)

        # 3. Resize from m1.small to m1.tiny
        self.nova.servers.resize(instance, resize_flavor)
        common_functions.check_inst_status(self.nova, instance.id,
                                           'VERIFY_RESIZE', 60)
        self.nova.servers.confirm_resize(instance)
        common_functions.check_inst_status(self.nova, instance.id,
                                           'ACTIVE', 60)
        self.assertEqual(self.nova.servers.get(instance).flavor['id'],
                         resize_flavor,
                         "Unexpected instance flavor after resize")

        # Check that instance is reachable
        ping = common_functions.ping_command(floating_ip.ip)
        self.assertTrue(ping, "Instance after resize is not reachable")
Exemplo n.º 3
0
 def create_volume_from_vm(self, os_conn, vm, size=1):
     image = os_conn.nova.servers.create_image(vm, image_name="image_vm2")
     common.wait(lambda: os_conn.nova.images.get(image).status == 'ACTIVE',
                 timeout_seconds=10 * 60,
                 waiting_for='image changes status to ACTIVE')
     volume = common.create_volume(os_conn.cinder, image, size=size)
     return volume.id
Exemplo n.º 4
0
def volume(os_conn):
        image_id = [image.id for image in os_conn.nova.images.list()
                    if image.name == 'TestVM'][0]
        volume = common.create_volume(os_conn.cinder, image_id,
                                      name='nfv_volume',
                                      volume_type='volumes_lvm')
        yield volume
        volume.delete()
Exemplo n.º 5
0
 def create_volume_from_vm(self, os_conn, vm):
     image = os_conn.nova.servers.create_image(vm, image_name="image_vm2")
     common.wait(lambda: os_conn.nova.images.get(image).status == 'ACTIVE',
                 timeout_seconds=10 * 60,
                 waiting_for='image changes status to ACTIVE')
     volume = common.create_volume(os_conn.cinder,
                                   image,
                                   volume_type='volumes_lvm')
     return volume.id
    def test_543176_CreatingMultipleSnapshots(self):
        """ This test case checks creation of several snapshot at the same time

            Steps:
                1. Create a volume
                2. Create 70 snapshots for it. Wait for creation
                3. Delete all of them
                4. Launch creation of 50 snapshot without waiting of deletion
        """

        # 1. Create volume
        image_id = [image.id for image in self.nova.images.list() if
                    image.name == 'TestVM'][0]
        volume = common_functions.create_volume(self.cinder, image_id,
                                                timeout=60)
        self.volume_list.append(volume)

        # 2. Creation of 70 snapshots
        count = 70
        initial_snapshot_lst = []
        for num in xrange(count):
            snapshot_id = self.cinder.volume_snapshots \
                .create(volume.id, name='1st_creation_{0}'.format(num))
            initial_snapshot_lst.append(snapshot_id)
            self.assertTrue(
                common_functions.check_volume_snapshot_status(self.cinder,
                                                              snapshot_id,
                                                              'available',
                                                              timeout=60))
        self.snapshot_list.extend(initial_snapshot_lst)

        # 3. Delete all snapshots
        for snapshot in initial_snapshot_lst:
            self.cinder.volume_snapshots.delete(snapshot)

        # 4. Launch creation of 50 snapshot without waiting of deletion
        new_count = 50
        new_snapshot_lst = []
        for num in xrange(new_count):
            snapshot_id = self.cinder.volume_snapshots \
                .create(volume.id, name='2nd_creation_{0}'.format(num))
            new_snapshot_lst.append(snapshot_id)
        self.snapshot_list.extend(new_snapshot_lst)

        timeout = time.time() + (new_count + count) * 10
        while [s.status for s in self.cinder.volume_snapshots.list() if
               s in new_snapshot_lst].count('available') != new_count:
            if time.time() < timeout:
                time.sleep(10)
            else:
                unavailable = [s.id for s in
                               self.cinder.volume_snapshots.list() if
                               s.status != 'available']
                raise AssertionError(
                    "All snapshots must be available. "
                    "List of unavailable snapshots:\n\t{0}".format(
                        "\n\t".join(unavailable)))
    def test_boot_instance_from_volume_bigger_than_flavor_size(self):
        """This test checks that nova allows creation instance
            from volume with size bigger than flavor size
            Steps:
            1. Create volume with size 2Gb.
            2. Boot instance with flavor size 'tiny' from newly created volume
            3. Check that instance created with correct values
        """

        # 1. Create volume
        image_id = [image.id for image in self.nova.images.list() if
                    image.name == 'TestVM'][0]

        volume = common_functions.create_volume(self.cinder, image_id,
                                                size=2, timeout=60)
        self.volumes.append(volume)

        # 2. Create router, network, subnet, connect them to external network
        exist_networks = self.os_conn.list_networks()['networks']
        ext_network = [x for x in exist_networks
                       if x.get('router:external')][0]
        self.router = self.os_conn.create_router(name="router01")['router']
        self.os_conn.router_gateway_add(router_id=self.router['id'],
                                        network_id=ext_network['id'])
        net_id = self.os_conn.add_net(self.router['id'])

        # 3. Create instance from newly created volume, associate floating_ip
        name = 'TestVM_1517671_instance'
        flavor_list = {f.name: f.id for f in self.nova.flavors.list()}
        initial_flavor_id = flavor_list['m1.tiny']
        bdm = {'vda': volume.id}
        instance = common_functions.create_instance(self.nova, name,
                                                    initial_flavor_id, net_id,
                                                    [self.sec_group.id],
                                                    block_device_mapping=bdm,
                                                    inst_list=self.instances)
        self.instances.append(instance.id)

        # Assert for attached volumes
        attached_volumes = self.nova.servers.get(instance).to_dict()[
            'os-extended-volumes:volumes_attached']
        self.assertIn({'id': volume.id}, attached_volumes)

        # Assert to flavor size
        self.assertEqual(self.nova.servers.get(instance).flavor['id'],
                         initial_flavor_id,
                         "Unexpected instance flavor after creation")

        floating_ip = self.nova.floating_ips.create()
        self.floating_ips.append(floating_ip)
        instance.add_floating_ip(floating_ip.ip)

        # Check that instance is reachable
        ping = common_functions.ping_command(floating_ip.ip)
        self.assertTrue(ping, "Instance after creation is not reachable")
    def test_restore_deleted_instance(
            self, set_recl_inst_interv, instances, volumes):
        """Restore previously deleted instance.
        Actions:
        1. Update '/etc/nova/nova.conf' with 'reclaim_instance_interval=86400'
        and restart Nova on all nodes;
        2. Create net and subnet;
        3. Create and run two instances (vm1, vm2) inside same net;
        4. Check that ping are successful between vms;
        5. Create a volume and attach it to an instance vm1;
        6. Delete instance vm1 and check that it's in 'SOFT_DELETE' state;
        7. Restore vm1 instance and check that it's in 'ACTIVE' state;
        8. Check that ping are successful between vms;
        """
        timeout = 60  # (sec) timeout to wait instance for status change

        # Create two vms
        vm1, vm2 = instances

        # Ping one vm from another
        vm1_ip = self.os_conn.get_nova_instance_ips(vm1).values()[0]
        vm2_ip = self.os_conn.get_nova_instance_ips(vm2).values()[0]
        network_checks.check_ping_from_vm(
            self.env, self.os_conn, vm1, ip_to_ping=vm2_ip, timeout=60)

        # Create a volume and attach it to an instance vm1
        volume = common_functions.create_volume(
            self.os_conn.cinder, image_id=None)
        self.os_conn.nova.volumes.create_server_volume(
            server_id=vm1.id, volume_id=volume.id, device='/dev/vdb')
        volumes.append(volume)

        # Delete instance vm1 and check that it's in "SOFT_DELETED" state
        common_functions.delete_instance(self.os_conn.nova, vm1.id)
        assert vm1 not in self.os_conn.get_servers()
        common_functions.wait(
            lambda: self.os_conn.server_status_is(vm1, 'SOFT_DELETED'),
            timeout_seconds=timeout, sleep_seconds=5,
            waiting_for='instance {0} changes status to SOFT_DELETED'.format(
                vm1.name))

        # Restore vm1 instance and check that it's in "ACTIVE" state now
        resp = self.os_conn.nova.servers.restore(vm1.id)
        assert resp[0].ok
        common_functions.wait(
            lambda: self.os_conn.is_server_active(vm1.id),
            timeout_seconds=timeout, sleep_seconds=5,
            waiting_for='instance {0} changes status to ACTIVE'.format(
                vm1.name))

        # Ping one vm from another
        network_checks.check_ping_from_vm(
            self.env, self.os_conn, vm2, ip_to_ping=vm1_ip, timeout=60)
def volume(os_conn):
    logger.info('Create volume')
    image = os_conn.nova.images.find(name='TestVM')
    volume = common.create_volume(os_conn.cinder, image.id)
    yield volume
    snp_list = os_conn.cinder.volume_snapshots.findall(volume_id=volume.id)
    for snp in snp_list:
        os_conn.cinder.volume_snapshots.delete(snp)
    common.wait(
        lambda: all([is_snapshot_deleted(os_conn, x) for x in snp_list]),
        timeout_seconds=1000,
        waiting_for='snapshots to be deleted')
    os_conn.delete_volume(volume)
Exemplo n.º 10
0
    def test_nova_launch_v_m_from_volume_with_all_flavours(self):
        """This test case checks creation of instance from volume with all
        types of flavor. For this test we need node with compute role:
        8 VCPUs, 16+GB RAM and 160+GB disk for any compute

        Steps:
            1. Create bootable volume
            1. Create a floating ip
            2. Create an instance from an image with some flavor
            3. Add the floating ip to the instance
            4. Ping the instance by the floating ip
            5. Delete the floating ip
            6. delete the instance
            7. Repeat all steps for all types of flavor
        """
        image_id = [
            image.id for image in self.nova.images.list()
            if image.name == 'TestVM'
        ][0]
        networks = self.neutron.list_networks()['networks']
        net = [net['id'] for net in networks if not net['router:external']][0]
        flavor_list = self.nova.flavors.list()
        volume = common_functions.create_volume(self.cinder, image_id)
        self.volumes.append(volume)
        bdm = {'vda': volume.id}
        for flavor in flavor_list:
            floating_ip = self.nova.floating_ips.create()
            self.floating_ips.append(floating_ip)
            self.assertIn(
                floating_ip.ip,
                [fip_info.ip for fip_info in self.nova.floating_ips.list()])
            inst = common_functions.create_instance(self.nova,
                                                    "inst_543360_{}".format(
                                                        flavor.name),
                                                    flavor.id,
                                                    net, [self.sec_group.name],
                                                    block_device_mapping=bdm,
                                                    inst_list=self.instances)
            inst.add_floating_ip(floating_ip.ip)
            self.assertTrue(
                common_functions.check_ip(self.nova, inst.id, floating_ip.ip))
            ping = common_functions.ping_command(floating_ip.ip)
            common_functions.delete_instance(self.nova, inst.id)
            self.assertTrue(ping, "Instance is not reachable")
Exemplo n.º 11
0
    def test_nova_launch_v_m_from_volume_with_all_flavours(self):
        """This test case checks creation of instance from volume with all
        types of flavor. For this test needs 2 nodes with compute role:
        20Gb RAM and 150GB disk for each

        Steps:
            1. Create bootable volume
            1. Create a floating ip
            2. Create an instance from an image with some flavor
            3. Add the floating ip to the instance
            4. Ping the instance by the floating ip
            5. Delete the floating ip
            6. delete the instance
            7. Repeat all steps for all types of flavor
        """
        image_id = [image.id for image in self.nova.images.list() if
                    image.name == 'TestVM'][0]
        networks = self.neutron.list_networks()['networks']
        net = [net['id'] for net in networks if not net['router:external']][0]
        flavor_list = self.nova.flavors.list()
        for flavor in flavor_list:
            floating_ip = self.nova.floating_ips.create()
            self.floating_ips.append(floating_ip)
            self.assertIn(floating_ip.ip, [fip_info.ip for fip_info in
                                           self.nova.floating_ips.list()])
            volume = common_functions.create_volume(self.cinder, image_id)
            self.volumes.append(volume)
            bdm = {'vda': volume.id}
            inst = common_functions.create_instance(self.nova,
                                                    "inst_543360_{}"
                                                    .format(flavor.name),
                                                    flavor.id, net,
                                                    [self.sec_group.name],
                                                    block_device_mapping=bdm,
                                                    inst_list=self.instances)
            inst_id = inst.id
            self.instances.append(inst_id)
            inst.add_floating_ip(floating_ip.ip)
            self.assertTrue(common_functions.check_ip(self.nova, inst_id,
                                                      floating_ip.ip))
            ping = common_functions.ping_command(floating_ip.ip)
            self.assertTrue(ping, "Instance is not reachable")
    def test_nova_launch_v_m_from_volume_with_all_flavours(self):
        """This test case checks creation of instance from volume with all
        types of flavor. For this test we need node with compute role:
        8 VCPUs, 16+GB RAM and 160+GB disk for any compute

        Steps:
            1. Create bootable volume
            1. Create a floating ip
            2. Create an instance from an image with some flavor
            3. Add the floating ip to the instance
            4. Ping the instance by the floating ip
            5. Delete the floating ip
            6. delete the instance
            7. Repeat all steps for all types of flavor
        """
        image_id = [image.id for image in self.nova.images.list() if
                    image.name == 'TestVM'][0]
        net = self.get_admin_int_net_id()
        flavor_list = self.nova.flavors.list()
        volume = common_functions.create_volume(self.cinder, image_id)
        self.volumes.append(volume)
        bdm = {'vda': volume.id}
        for flavor in flavor_list:
            floating_ip = self.nova.floating_ips.create()
            self.floating_ips.append(floating_ip)
            self.assertIn(floating_ip.ip, [fip_info.ip for fip_info in
                                           self.nova.floating_ips.list()])
            inst = common_functions.create_instance(self.nova,
                                                    "inst_543360_{}"
                                                    .format(flavor.name),
                                                    flavor.id, net,
                                                    [self.sec_group.id],
                                                    block_device_mapping=bdm,
                                                    inst_list=self.instances)
            inst.add_floating_ip(floating_ip.ip)
            self.assertTrue(common_functions.check_ip(self.nova, inst.id,
                                                      floating_ip.ip))
            ping = common_functions.ping_command(floating_ip.ip)
            common_functions.delete_instance(self.nova, inst.id)
            self.assertTrue(ping, "Instance is not reachable")
Exemplo n.º 13
0
def volume(os_conn):
    image = os_conn.nova.images.find(name="TestVM")
    volume = common.create_volume(os_conn.cinder, image.id)
    yield volume
    os_conn.delete_volume(volume)
Exemplo n.º 14
0
    def test_resize_down_an_instance_booted_from_volume(self):
        """This test checks that nova allows
            resize down an instance booted from volume
            Steps:
            1. Create bootable volume
            2. Boot instance from newly created volume
            3. Resize instance from m1.small to m1.tiny
        """

        # 1. Create bootable volume
        image_id = [
            image.id for image in self.nova.images.list()
            if image.name == 'TestVM'
        ][0]

        volume = common_functions.create_volume(self.cinder,
                                                image_id,
                                                timeout=60)
        self.volumes.append(volume)

        # 2. Create instance from newly created volume, associate floating_ip
        name = 'TestVM_543355_instance_to_resize'
        networks = self.neutron.list_networks()['networks']
        net = [net['id'] for net in networks if not net['router:external']][0]
        flavor_list = {f.name: f.id for f in self.nova.flavors.list()}
        initial_flavor = flavor_list['m1.small']
        resize_flavor = flavor_list['m1.tiny']
        bdm = {'vda': volume.id}
        instance = common_functions.create_instance(self.nova,
                                                    name,
                                                    initial_flavor,
                                                    net, [self.sec_group.name],
                                                    block_device_mapping=bdm,
                                                    inst_list=self.instances)
        self.instances.append(instance.id)

        # Assert for attached volumes
        attached_volumes = self.nova.servers.get(
            instance).to_dict()['os-extended-volumes:volumes_attached']
        self.assertIn({'id': volume.id}, attached_volumes)

        # Assert to flavor size
        self.assertEqual(
            self.nova.servers.get(instance).flavor['id'], initial_flavor,
            "Unexpected instance flavor before resize")

        floating_ip = self.nova.floating_ips.create()
        self.floating_ips.append(floating_ip.ip)
        instance.add_floating_ip(floating_ip.ip)

        # 3. Resize from m1.small to m1.tiny
        self.nova.servers.resize(instance, resize_flavor)
        common_functions.check_inst_status(self.nova, instance.id,
                                           'VERIFY_RESIZE', 60)
        self.nova.servers.confirm_resize(instance)
        common_functions.check_inst_status(self.nova, instance.id, 'ACTIVE',
                                           60)
        self.assertEqual(
            self.nova.servers.get(instance).flavor['id'], resize_flavor,
            "Unexpected instance flavor after resize")

        # Check that instance is reachable
        ping = common_functions.ping_command(floating_ip.ip)
        self.assertTrue(ping, "Instance after resize is not reachable")
Exemplo n.º 15
0
    def test_nova_massively_spawn_v_ms_boot_from_cinder(self):
        """This test case creates a lot of VMs which boot from Cinder, checks
        it state and availability and then deletes it.

        Steps:
            1. Create 10-100 volumes.
            2. Boot 10-100 instances from volumes.
            3. Check that list of instances contains created VMs.
            4. Check state of created instances
            5. Add the floating ips to the instances
            6. Ping the instances by the floating ips
        """
        initial_instances = self.nova.servers.list()
        count = 10
        primary_name = "testVM_543357"
        image_dict = {im.name: im.id for im in self.nova.images.list()}
        image_id = image_dict["TestVM"]
        flavor_dict = {f.name: f.id for f in self.nova.flavors.list()}
        flavor_id = flavor_dict["m1.tiny"]
        networks = self.neutron.list_networks()["networks"]
        net_dict = {net["name"]: net["id"] for net in networks}
        net_internal_id = net_dict["admin_internal_net"]

        initial_volumes = self.cinder.volumes.list()
        for i in range(count):
            common_functions.create_volume(self.cinder, image_id, size=1)
        self.volumes = [
            volume for volume in self.cinder.volumes.list()
            if volume not in initial_volumes
        ]
        msg = "Count of created volumes is incorrect!"
        self.assertEqual(len(self.volumes), 10, msg)

        self.floating_ips = [
            self.nova.floating_ips.create() for _ in range(count)
        ]
        fip_new = [fip_info.ip for fip_info in self.floating_ips]
        fip_all = [fip_info.ip for fip_info in self.nova.floating_ips.list()]
        for fip in fip_new:
            self.assertIn(fip, fip_all)

        for volume in self.volumes:
            bdm = {'vda': volume.id}
            self.nova.servers.create(primary_name,
                                     '',
                                     flavor_id,
                                     security_groups=[self.sec_group.name],
                                     block_device_mapping=bdm,
                                     nics=[{
                                         "net-id": net_internal_id
                                     }])
        start_time = time()
        timeout = 5
        while len(self.nova.servers.list()) < len(initial_instances) + count \
                and time() < start_time + timeout * 60:
            sleep(5)

        instances = [
            inst for inst in self.nova.servers.list()
            if inst not in initial_instances
        ]
        self.instances = [inst.id for inst in instances]
        for inst_id in self.instances:
            self.assertTrue(
                common_functions.check_inst_status(self.nova, inst_id,
                                                   'ACTIVE'))
        fip_dict = {}
        for inst in instances:
            fip = fip_new.pop()
            inst.add_floating_ip(fip)
            fip_dict[inst.id] = fip

        for inst_id in self.instances:
            self.assertTrue(
                common_functions.check_ip(self.nova, inst_id,
                                          fip_dict[inst_id]))

        for inst_id in self.instances:
            ping = common_functions.ping_command(fip_dict[inst_id], i=8)
            self.assertTrue(ping,
                            "Instance {} is not reachable".format(inst_id))
    def test_inst_deleted_reclaim_interval_timeout(
            self, set_recl_inst_interv, instances, volumes):
        """Check that softly-deleted instance is totally deleted after
        reclaim interval timeout.
        Actions:
        1. Update '/etc/nova/nova.conf' with short 'reclaim_instance_interval'
        and restart Nova on all nodes;
        2. Create net and subnet;
        3. Create and run two instances (vm1, vm2) inside same net;
        4. Create a volume and attach it to an instance vm1;
        5. Delete instance vm1 and check that it's in 'SOFT_DELETE' state;
        6. Wait for the reclaim instance interval to expire and make sure
        the vm1 is deleted;
        7. Check that volume is released now and has an Available state;
        8. Attach the volume to vm2 instance to ensure that the volume's reuse
        doesn't call any errors.

        ~! BUG !~
        https://bugs.launchpad.net/cinder/+bug/1463856
        Cinder volume isn't available after instance soft-deleted timer
        expired while volume is still attached.
        """
        timeout = 60  # (sec) timeout to wait instance for status change

        # Create two vms
        vm1, vm2 = instances

        # Create a volume and attach it to an instance vm1
        volume = common_functions.create_volume(
            self.os_conn.cinder, image_id=None)
        self.os_conn.nova.volumes.create_server_volume(
            server_id=vm1.id, volume_id=volume.id, device='/dev/vdb')
        volumes.append(volume)

        # Delete instance vm1 and check that it's in "SOFT_DELETED" state
        common_functions.delete_instance(self.os_conn.nova, vm1.id)
        assert vm1 not in self.os_conn.get_servers()
        common_functions.wait(
            lambda: self.os_conn.server_status_is(vm1, 'SOFT_DELETED'),
            timeout_seconds=timeout, sleep_seconds=5,
            waiting_for='instance {0} changes status to SOFT_DELETED'.format(
                vm1.name))

        # Wait interval and check that instance is not present
        time_to_sleep = 2.5 * self.recl_interv_short
        logger.debug(('Sleep to wait for 2.5 reclaim_instance_interval ({0})'
                      ).format(time_to_sleep))
        sleep(time_to_sleep)
        try:
            self.os_conn.get_instance_detail(vm1.id)
        except Exception as e:
            assert e.code == 404
        else:
            raise Exception(('Instance {0} not deleted after '
                             '"reclaim_interval_timeout"').format(vm1.name))

        # Update volume information
        volume = self.os_conn.cinder.volumes.get(volume.id)

        # ~! BUG !~: https://bugs.launchpad.net/cinder/+bug/1463856
        # Check that volume is released now and has an Available state
        assert volume.status == 'available'
        # Check volume is not attached
        assert volume.attachments == []

        # Attach the volume to vm2 instance
        self.os_conn.nova.volumes.create_server_volume(
            server_id=vm2.id, volume_id=volume.id, device='/dev/vdb')

        # Check volume status after re-attach
        assert self.os_conn.cinder.volumes.get(volume.id).status == 'in-use'
    def test_nova_massively_spawn_v_ms_boot_from_cinder(self):
        """This test case creates a lot of VMs which boot from Cinder, checks
        it state and availability and then deletes it.

        Steps:
            1. Create 10-100 volumes.
            2. Boot 10-100 instances from volumes.
            3. Check that list of instances contains created VMs.
            4. Check state of created instances
            5. Add the floating ips to the instances
            6. Ping the instances by the floating ips
        """
        initial_instances = self.nova.servers.list()
        count = 10
        primary_name = "testVM_543357"
        image_dict = {im.name: im.id for im in self.nova.images.list()}
        image_id = image_dict["TestVM"]
        flavor_dict = {f.name: f.id for f in self.nova.flavors.list()}
        flavor_id = flavor_dict["m1.tiny"]
        net_internal_id = self.get_admin_int_net_id()

        initial_volumes = self.cinder.volumes.list()
        for i in range(count):
            common_functions.create_volume(self.cinder, image_id, size=1)
        self.volumes = [volume for volume in self.cinder.volumes.list()
                        if volume not in initial_volumes]
        msg = "Count of created volumes is incorrect!"
        self.assertEqual(len(self.volumes), 10, msg)

        self.floating_ips = [self.nova.floating_ips.create()
                             for _ in range(count)]
        fip_new = [fip_info.ip for fip_info in self.floating_ips]
        fip_all = [fip_info.ip for fip_info in self.nova.floating_ips.list()]
        for fip in fip_new:
            self.assertIn(fip, fip_all)

        for volume in self.volumes:
            bdm = {'vda': volume.id}
            self.nova.servers.create(primary_name, '', flavor_id,
                                     security_groups=[self.sec_group.id],
                                     block_device_mapping=bdm,
                                     nics=[{"net-id": net_internal_id}])
        start_time = time()
        timeout = 5
        while len(self.nova.servers.list()) < len(initial_instances) + count \
                and time() < start_time + timeout * 60:
            sleep(5)

        instances = [inst for inst in self.nova.servers.list()
                     if inst not in initial_instances]
        self.instances = [inst.id for inst in instances]
        for inst_id in self.instances:
            self.assertTrue(common_functions.check_inst_status(self.nova,
                                                               inst_id,
                                                               'ACTIVE'))
        fip_dict = {}
        for inst in instances:
            fip = fip_new.pop()
            inst.add_floating_ip(fip)
            fip_dict[inst.id] = fip

        for inst_id in self.instances:
            self.assertTrue(common_functions.check_ip(
                self.nova, inst_id, fip_dict[inst_id]))

        for inst_id in self.instances:
            ping = common_functions.ping_command(fip_dict[inst_id], i=8)
            self.assertTrue(ping,
                            "Instance {} is not reachable".format(inst_id))
Exemplo n.º 18
0
    def test_boot_instance_from_volume_bigger_than_flavor_size(self):
        """This test checks that nova allows creation instance
            from volume with size bigger than flavor size
            Steps:
            1. Create volume with size 2Gb.
            2. Boot instance with flavor size 'tiny' from newly created volume
            3. Check that instance created with correct values
        """

        # 1. Create volume
        image_id = [
            image.id for image in self.nova.images.list()
            if image.name == 'TestVM'
        ][0]

        volume = common_functions.create_volume(self.cinder,
                                                image_id,
                                                size=2,
                                                timeout=60)
        self.volumes.append(volume)

        # 2. Create router, network, subnet, connect them to external network
        exist_networks = self.os_conn.list_networks()['networks']
        ext_network = [x for x in exist_networks
                       if x.get('router:external')][0]
        self.router = self.os_conn.create_router(name="router01")['router']
        self.os_conn.router_gateway_add(router_id=self.router['id'],
                                        network_id=ext_network['id'])
        net_id = self.os_conn.add_net(self.router['id'])

        # 3. Create instance from newly created volume, associate floating_ip
        name = 'TestVM_1517671_instance'
        flavor_list = {f.name: f.id for f in self.nova.flavors.list()}
        initial_flavor = flavor_list['m1.tiny']
        bdm = {'vda': volume.id}
        instance = common_functions.create_instance(self.nova,
                                                    name,
                                                    initial_flavor,
                                                    net_id,
                                                    [self.sec_group.name],
                                                    block_device_mapping=bdm,
                                                    inst_list=self.instances)
        self.instances.append(instance.id)

        # Assert for attached volumes
        attached_volumes = self.nova.servers.get(
            instance).to_dict()['os-extended-volumes:volumes_attached']
        self.assertIn({'id': volume.id}, attached_volumes)

        # Assert to flavor size
        self.assertEqual(
            self.nova.servers.get(instance).flavor['id'], initial_flavor,
            "Unexpected instance flavor after creation")

        floating_ip = self.nova.floating_ips.create()
        self.floating_ips.append(floating_ip.ip)
        instance.add_floating_ip(floating_ip.ip)

        # Check that instance is reachable
        ping = common_functions.ping_command(self.floating_ip.ip)
        self.assertTrue(ping, "Instance after creation is not reachable")
Exemplo n.º 19
0
    def test_creating_multiple_snapshots(self):
        """This test case checks creation of several snapshot at the same time

            Steps:
                1. Create a volume
                2. Create 70 snapshots for it. Wait for creation
                3. Delete all of them
                4. Launch creation of 50 snapshot without waiting of deletion
        """
        # 1. Create volume
        logger.info('Create volume')
        image_id = [
            image.id for image in self.nova.images.list()
            if image.name == 'TestVM'
        ][0]
        volume = common_functions.create_volume(self.cinder, image_id)
        self.volume_list.append(volume)

        # 2. Creation of 70 snapshots
        logger.info('Create 70 snapshots')
        count = 70
        initial_snapshot_lst = []
        for num in range(count):
            logger.info('Creating {} snapshot'.format(num))
            snapshot_id = self.cinder.volume_snapshots \
                .create(volume.id, name='1st_creation_{0}'.format(num))
            initial_snapshot_lst.append(snapshot_id)
            self.assertTrue(
                common_functions.check_volume_snapshot_status(
                    self.cinder, snapshot_id, 'available'))
        self.snapshot_list.extend(initial_snapshot_lst)

        # 3. Delete all snapshots
        logger.info('Delete all snapshots')
        for snapshot in initial_snapshot_lst:
            self.cinder.volume_snapshots.delete(snapshot)

        # 4. Launch creation of 50 snapshot without waiting of deletion
        logger.info('Launch creation of 50 snapshot without waiting '
                    'of deletion')
        new_count = 50
        new_snapshot_lst = []
        for num in range(new_count):
            logger.info('Creating {} snapshot'.format(num))
            snapshot_id = self.cinder.volume_snapshots \
                .create(volume.id, name='2nd_creation_{0}'.format(num))
            new_snapshot_lst.append(snapshot_id)
        self.snapshot_list.extend(new_snapshot_lst)

        timeout = time.time() + (new_count + count) * 10
        while [
                s.status for s in self.cinder.volume_snapshots.list()
                if s in new_snapshot_lst
        ].count('available') != new_count:
            if time.time() < timeout:
                time.sleep(10)
            else:
                unavailable = [
                    s.id for s in self.cinder.volume_snapshots.list()
                    if s.status != 'available'
                ]
                raise AssertionError(
                    "All snapshots must be available. "
                    "List of unavailable snapshots:\n\t{0}".format(
                        "\n\t".join(unavailable)))