def test_hp_distribution_1g_2m_for_vms(self, env, os_conn,
                                           computes_with_mixed_hp, networks,
                                           flavors, security_group):
        """This test checks huge pages 1Gb and 2Mb distribution for vms
            Steps:
            1. Create net1 with subnet, net2 with subnet and  router1 with
            interfaces to both nets
            2. Create vm1 in net1 on compute1 with 1Gb flavor
            3. Create vm2 in net2 on compute2 with 2Mb flavor
            4. Create vm3 in net2 on compute1 with 2Mb flavor
            5. Check instances configuration (about huge pages)
            6. Check quantity of HP on computes
            7. Check pings from all vms to all vms by all ips
        """
        small_nfv_flavor, medium_nfv_flavor = flavors[0], flavors[1]
        count_to_allocate_2mb = small_nfv_flavor.ram * 1024 / page_2mb
        count_to_allocate_1gb = medium_nfv_flavor.ram * 1024 / page_1gb

        initial_conf = computes_configuration(env)

        hosts = computes_with_mixed_hp
        vms_params = [
            (hosts[0], networks[0], medium_nfv_flavor, page_1gb),
            (hosts[1], networks[1], small_nfv_flavor, page_2mb),
            (hosts[0], networks[1], small_nfv_flavor, page_2mb), ]

        vms = {}

        for i, (host, network, flavor, size) in enumerate(vms_params):
            vm = os_conn.create_server(
                name='vm{}'.format(i), flavor=flavor.id,
                nics=[{'net-id': network}],
                availability_zone='nova:{}'.format(host),
                security_groups=[security_group.id])
            vms.update({vm: size})

        for vm, exp_size in vms.items():
            assert self.get_instance_page_size(os_conn, vm) == exp_size

        vms_distribution = [(hosts[0], 1, 1), (hosts[1], 0, 1), ]
        final_conf = computes_configuration(env)
        for (host, nr_1gb, nr_2mb) in vms_distribution:
            exp_free_1g = (initial_conf[host][page_1gb]['total'] -
                           nr_1gb * count_to_allocate_1gb)
            exp_free_2m = (initial_conf[host][page_2mb]['total'] -
                           nr_2mb * count_to_allocate_2mb)
            assert exp_free_1g == final_conf[host][page_1gb]['free']
            assert exp_free_2m == final_conf[host][page_2mb]['free']

        os_conn.wait_servers_ssh_ready(vms.keys())
        network_checks.check_vm_connectivity(env, os_conn)
    def test_allocation_huge_pages_2m_for_vms(self, env, os_conn, networks,
                                              computes_with_hp_2mb,
                                              flavors, security_group):
        """This test checks allocation 2M HugePages for instances
            Steps:
            1. Create net1 with subnet, net2 with subnet and  router1 with
            interfaces to both nets
            2. Launch vm1 and vm2 using net1 on the first compute
            3. Launch vm3 using net1 on the second compute
            4. Launch vm4 using net2 on the second compute
            5. Check instances configuration (about huge pages)
            6. Check quantity of HP on computes
            7. Associate floating to vm1
            8. Check pings from all vms to all vms by all ips
        """
        small_nfv_flavor = flavors[0]
        count_to_allocate_2mb = small_nfv_flavor.ram * 1024 / page_2mb
        initial_conf = computes_configuration(env)
        hosts = computes_with_hp_2mb

        vms = []
        vms_params = [
            (hosts[0], networks[0]),
            (hosts[0], networks[0]),
            (hosts[0], networks[1]),
            (hosts[1], networks[1]),
        ]
        for i, (host, network) in enumerate(vms_params):
            vm = os_conn.create_server(
                name='vm{}'.format(i), flavor=small_nfv_flavor.id,
                nics=[{'net-id': network}],
                availability_zone='nova:{}'.format(host),
                security_groups=[security_group.id])
            vms.append(vm)

        for vm in vms:
            assert self.get_instance_page_size(os_conn, vm) == page_2mb

        vms_distribution = [(hosts[0], 3), (hosts[1], 1), ]
        final_conf = computes_configuration(env)
        for (host, nr_2mb) in vms_distribution:
            exp_free_2m = (initial_conf[host][page_2mb]['total'] -
                           nr_2mb * count_to_allocate_2mb)
            assert exp_free_2m == final_conf[host][page_2mb]['free']

        os_conn.assign_floating_ip(vms[0])
        os_conn.wait_servers_ssh_ready(vms)
        network_checks.check_vm_connectivity(env, os_conn)
    def test_vms_connectivity_after_evacuation(self, env, os_conn, volume,
                                               computes_with_dpdk_hp, flavors,
                                               networks, keypair, devops_env,
                                               security_group):
        """This test checks connectivity between VMs with DPDK after
        evacuation. Please note we're not able to count DPDK huge pages only,
        they're added to count of 2Mb huge pages.
            Steps:
            1. Create net1 with subnet, net2 with subnet and  router1 with
            interfaces to both nets
            2. Create flavor for huge pages with 512Mb ram, 1 vcpu and 1Gb disk
            3. Launch vm1 (from not empty volume), vm2 on compute-1,
            vm3 - on compute-2, vm1 in net1, vm2 and vm3 in net2
            4. Kill compute2 and evacuate vm3
            5. Check vms connectivity
            6. Start compute2
            7. Check instance page size
            8. Check that neutron port has binding:vif_type = vhostuser
            9. Check that count of free 2Mb huge pages is expected one for
            each host
        """
        hosts = computes_with_dpdk_hp
        initial_conf = computes_configuration(env)
        vms_param = [(hosts[0], networks[0], {'vda': volume.id}),
                     (hosts[0], networks[1], None),
                     (hosts[1], networks[1], None)]
        vms = self.create_vms(os_conn, hosts, networks, flavors[0], keypair,
                              security_group, vms_param=vms_param)
        network_checks.check_vm_connectivity(env, os_conn, vm_keypair=keypair)

        self.compute_change_state(os_conn, devops_env, hosts[1], state='down')
        vm_new = self.evacuate(os_conn, devops_env, vms[2],
                               on_shared_storage=False)
        vm_new_host = getattr(os_conn.nova.servers.get(vm_new),
                              "OS-EXT-SRV-ATTR:host")
        assert vm_new_host in hosts
        assert vm_new_host != hosts[1]
        network_checks.check_vm_connectivity(env, os_conn, vm_keypair=keypair)

        self.compute_change_state(os_conn, devops_env, hosts[1], state='up')

        final_conf = computes_configuration(env)
        exp_hosts_usage = [(hosts[0], 3), (hosts[1], 0)]
        for (host, nr_2mb) in exp_hosts_usage:
            exp_free_2m = (initial_conf[host][page_2mb]['free'] -
                           nr_2mb * flavors[0].ram * 1024 / page_2mb)
            assert exp_free_2m == final_conf[host][page_2mb]['free']
    def test_allocation_huge_pages_2m_for_vms_with_old_flavor(
            self, env, os_conn, networks, computes_with_hp_2mb, flavors,
            computes_without_hp, security_group):
        """This test checks that Huge pages set for vm1, vm2 and vm3 shouldn't
            use Huge pages, connectivity works properly
            Steps:
            1. Create net1 with subnet, net2 with subnet and  router1 with
            interfaces to both nets
            2. Create vm1 in net1 on compute1 with 2Mb flavor
            3. Create vm2 in net2 on compute2 with old flavor
            4. Create vm3 in net1 on compute1 with old flavor
            5. Check huge pages. Check that it was allocated only HP for vm1
            6. Check pings from all vms to all vms by all ips
        """
        small_nfv_flavor, old_flavor = flavors[0], flavors[2]
        count_to_allocate_2mb = small_nfv_flavor.ram * 1024 / page_2mb
        initial_conf = computes_configuration(env)
        hosts_hp = computes_with_hp_2mb
        hosts_no_hp = computes_without_hp

        vms_params = [
            (hosts_hp[0], networks[0], small_nfv_flavor, page_2mb),
            (hosts_no_hp[0], networks[1], old_flavor, None),
            (hosts_hp[0], networks[0], old_flavor, None)]
        vms = {}

        for i, (host, network, flavor, size) in enumerate(vms_params):
            vm = os_conn.create_server(
                name='vm{}'.format(i), flavor=flavor.id,
                nics=[{'net-id': network}],
                availability_zone='nova:{}'.format(host),
                security_groups=[security_group.id])
            vms.update({vm: size})

        for vm, exp_size in vms.items():
            assert self.get_instance_page_size(os_conn, vm) == exp_size

        vms_distribution = [(hosts_hp[0], 1), (hosts_no_hp[0], 0), ]
        final_conf = computes_configuration(env)
        for (host, nr_2mb) in vms_distribution:
            exp_free_2m = (initial_conf[host][page_2mb]['total'] -
                           nr_2mb * count_to_allocate_2mb)
            assert exp_free_2m == final_conf[host][page_2mb]['free']

        os_conn.wait_servers_ssh_ready(vms.keys())
        network_checks.check_vm_connectivity(env, os_conn)
Exemplo n.º 5
0
    def test_base_vms_connectivity(self, env, os_conn, computes_with_dpdk_hp,
                                   networks, keypair, flavors, security_group):
        """This test checks base connectivity between VMs with DPDK. Please
        note we're not able to count DPDK huge pages only, they're added to
        count of 2Mb huge pages.
            Steps:
            1. Create net1 with subnet, net2 with subnet and  router1 with
            interfaces to both nets
            2. Create flavor for huge pages with 512Mb ram, 1 vcpu and 1Gb disk
            3. Launch vm1, vm2, vm3 on compute-1 and vm4 on compute-2, vm1 and
            vm2 in net1, vm3 and vm4 in net2
            4. Check vms connectivity
            5. Check instance page size
            6. Check that neutron port has binding:vif_type = vhostuser
            7. Check that count of 2Mb huge pages is expected for each host
        """
        hosts = computes_with_dpdk_hp
        initial_conf = computes_configuration(env)

        vms_param = [(hosts[0], networks[0], None),
                     (hosts[0], networks[0], None),
                     (hosts[0], networks[1], None),
                     (hosts[1], networks[1], None)]
        vms = self.create_vms(os_conn, hosts, networks, flavors[0], keypair,
                              security_group, vms_param)
        network_checks.check_vm_connectivity(env, os_conn, vm_keypair=keypair)

        for vm in vms:
            self.check_vif_type_for_vm(vm, os_conn)
            act_size = self.get_instance_page_size(os_conn, env)
            assert act_size == page_2mb, (
                "Unexpected package size. Should be {0} instead of {1}".format(
                    page_2mb, act_size))

        final_conf = computes_configuration(env)
        exp_hosts_usage = [(hosts[0], 3), (hosts[1], 1)]
        for (host, nr_2mb) in exp_hosts_usage:
            exp_free_2m = (initial_conf[host][page_2mb]['free'] -
                           nr_2mb * flavors[0].ram * 1024 / page_2mb)
            assert exp_free_2m == final_conf[host][page_2mb]['free']
Exemplo n.º 6
0
    def test_vms_connectivity_after_live_migration(self, env, os_conn,
                                                   computes_with_dpdk_hp,
                                                   flavors, networks, keypair,
                                                   security_group):
        """This test checks connectivity between VMs with DPDK after live
        migration. Please note we're not able to count DPDK huge pages only,
        they're added to count of 2Mb huge pages.
            Steps:
            1. Create net1 with subnet, net2 with subnet and  router1 with
            interfaces to both nets
            2. Create flavor for huge pages with 512Mb ram, 1 vcpu and 1Gb disk
            3. Launch vm1, vm2 on compute-1, vm3 - on compute-2, vm1 in net1,
            vm2 and vm3 in net2
            4. Live migrate vm1 to compute2
            5. Check instance page size
            6. Check that neutron port has binding:vif_type = vhostuser
            7. Check that count of free 2Mb huge pages is expected one for
            each host
            8. Check vms connectivity
        """
        hosts = computes_with_dpdk_hp
        initial_conf = computes_configuration(env)
        vms_param = [(hosts[0], networks[0], None),
                     (hosts[0], networks[1], None),
                     (hosts[1], networks[1], None)]
        vms = self.create_vms(os_conn, hosts, networks, flavors[0], keypair,
                              security_group, vms_param=vms_param)
        self.live_migrate(os_conn, vms[0], hosts[1])
        network_checks.check_vm_connectivity(env, os_conn, vm_keypair=keypair)

        final_conf = computes_configuration(env)
        exp_hosts_usage = [(hosts[0], 1), (hosts[1], 2)]
        for (host, nr_2mb) in exp_hosts_usage:
            exp_free_2m = (initial_conf[host][page_2mb]['free'] -
                           nr_2mb * flavors[0].ram * 1024 / page_2mb)
            assert exp_free_2m == final_conf[host][page_2mb]['free']
    def test_vms_connectivity_with_hp_and_numa(self, env, os_conn,
                                               computes_for_mixed_hp_and_numa,
                                               aggregate, networks,
                                               security_group, flavors):
        """This test checks vms connectivity with huge pages and cpu pinning.

            At least 2 computes with mixed huge pages and cpu pinning are
            required. 2 numa nodes should be available per compute. 512 x 2Mb
            and 1 x 1Gb huge pages should be available for each numa node.
            Specific distribution of cpus per numa nodes is required for each
            compute: at least 4 cpus for one node and at least 2 cpus for
            another one.

            Steps:
            1. Create net1 with subnet, net2 with subnet and  router1 with
            interfaces to both nets
            2. Create vm1 in net1 on host1 using flavor m1.small.hpgs_n-2
             (hw:mem_page_size=2048 and hw:numa_nodes=2)
            3. Create vm2 in net1 on host1 using flavor m1.small.performance-2
             (hw:numa_nodes=2, without huge pages)
            4. Create vm3 in net2 on host2 using flavor m1.small.hpgs_n-1
             (hw:mem_page_size=2048 and hw:numa_nodes=1)
            5. Create vm4 in net2 on host2 using flavor m1.small.hpgs
             (hw:mem_page_size=1048576 without cpu pinning)
            6. Create vm5 in net1 on host1 using flavor m1.small.old
             (without features)
            7. Check cpus allocation for all vms
            8. Check page size for all vms
            9. Check free huge pages when all vms are running
            10. Check connectivity between all vms
        """
        hosts = computes_for_mixed_hp_and_numa
        initial_conf_hp = computes_configuration(env)
        cpus = get_cpu_distribition_per_numa_node(env)

        vms = {}
        vms_params = [(flavors[3], hosts[0], networks[0], 2, page_2mb),
                      (flavors[4], hosts[0], networks[0], 2, None),
                      (flavors[2], hosts[1], networks[1], 1, page_2mb),
                      (flavors[1], hosts[1], networks[1], None, page_1gb),
                      (flavors[0], hosts[0], networks[0], None, None)]

        for i, (flv, host, net, numa_count, size) in enumerate(vms_params):
            vm = os_conn.create_server(
                name='vm{}'.format(i), flavor=flv.id,
                nics=[{'net-id': net}],
                availability_zone='nova:{}'.format(host),
                security_groups=[security_group.id], wait_for_active=False,
                wait_for_avaliable=False)
            vms.update({vm: {'numa': numa_count, 'size': size}})
        os_conn.wait_servers_active(vms)
        os_conn.wait_servers_ssh_ready(vms)

        for vm, param in vms.items():
            self.check_instance_page_size(os_conn, vm, param['size'])
            if param['numa'] is not None:
                host = getattr(vm, 'OS-EXT-SRV-ATTR:host')
                self.check_cpu_for_vm(os_conn, vm, param['numa'], cpus[host])

        network_checks.check_vm_connectivity(env, os_conn)

        final_conf = computes_configuration(env)
        vms_distribution = [(hosts[0], 0, 1), (hosts[1], 1, 1), ]
        for (host, nr_1gb, nr_2mb) in vms_distribution:
            exp_free_1g = initial_conf_hp[host][page_1gb]['total'] - nr_1gb * 1
            exp_free_2m = (
                initial_conf_hp[host][page_2mb]['total'] - nr_2mb * 512)
            assert exp_free_1g == final_conf[host][page_1gb]['free']
            assert exp_free_2m == final_conf[host][page_2mb]['free']
    def test_cold_migration_for_huge_pages_2m(
            self, env, os_conn, networks, small_nfv_flavor, security_group,
            computes_with_hp_2mb):
        """This test checks that cold migration executed successfully for
            instances created on computes with huge pages 2M
            Steps:
            1. Create net1 with subnet, net2 with subnet and  router1 with
            interfaces to both nets
            2. Launch instance vm1 in net1 with m1.small.hpgs
            3. Check that vm1 is created on compute with huge pages
            4. Launch instance vm2 in net2 with m1.small.hpgs
            5. Check that vm2 is created on compute with huge pages
            6. Check vms connectivity
            7. Cold migrate vm1 and check that vm moved to other compute with
            huge pages
            8. Check vms connectivity
        """
        count_to_allocate_2mb = small_nfv_flavor.ram * 1024 / page_2mb
        initial_conf = computes_configuration(env)
        hosts = computes_with_hp_2mb

        vms = []
        vm_hosts = []
        for i in range(2):
            vm = os_conn.create_server(
                name='vm{}'.format(i), flavor=small_nfv_flavor.id,
                security_groups=[security_group.id],
                nics=[{'net-id': networks[i]}])
            vms.append(vm)
        for vm in vms:
            host = getattr(vm, "OS-EXT-SRV-ATTR:host")
            assert host in hosts
            vm_hosts.append(host)

        vms_distribution = [(hosts[0], vm_hosts.count(hosts[0])),
                            (hosts[1], vm_hosts.count(hosts[1])), ]
        current_conf = computes_configuration(env)
        for (host, nr_2mb) in vms_distribution:
            exp_free_2m = (initial_conf[host][page_2mb]['total'] -
                           nr_2mb * count_to_allocate_2mb)
            assert exp_free_2m == current_conf[host][page_2mb]['free']

        for vm in vms:
            self.check_instance_page_size(os_conn, vm, size=page_2mb)
        network_checks.check_vm_connectivity(env, os_conn)

        vm_0_new = self.migrate(os_conn, vms[0])
        vm_host_0_new = getattr(vm_0_new, "OS-EXT-SRV-ATTR:host")

        assert vm_host_0_new in hosts
        assert vm_host_0_new != vm_hosts.pop(0)
        vm_hosts.append(vm_host_0_new)

        vms_distribution = [(hosts[0], vm_hosts.count(hosts[0])),
                            (hosts[1], vm_hosts.count(hosts[1])), ]
        final_conf = computes_configuration(env)
        for (host, nr_2mb) in vms_distribution:
            exp_free_2m = (initial_conf[host][page_2mb]['total'] -
                           nr_2mb * count_to_allocate_2mb)
            assert exp_free_2m == final_conf[host][page_2mb]['free']
        self.check_instance_page_size(os_conn, vm_0_new, size=page_2mb)
        network_checks.check_vm_connectivity(env, os_conn)
    def test_evacuation_for_huge_pages_2m(
            self, env, os_conn, devops_env, networks, small_nfv_flavor,
            security_group, computes_with_hp_2mb):
        """This test checks that evacuation executed successfully for
            instances created on computes with huge pages 2M
            Steps:
            1. Create net1 with subnet, net2 with subnet and  router1 with
               interfaces to both nets
            2. Launch instance vm1 in net1 with m1.small.hpgs on compute-1
            3. Launch instance vm2 in net2 with m1.small.hpgs on compute-2
            4. Check vms connectivity
            5. Kill the compute-1
            6. Evacuate vm1 from compute-1
            7. Check vms connectivity
            8. Make compute-1 alive
            9. Check that resources for vm1 were deleted from compute-1
        """
        count_to_allocate_2mb = small_nfv_flavor.ram * 1024 / page_2mb
        initial_conf = computes_configuration(env)
        hosts = computes_with_hp_2mb
        vms = []
        for i in range(2):
            vm = os_conn.create_server(
                name='vm{}'.format(i), flavor=small_nfv_flavor.id,
                availability_zone='nova:{}'.format(hosts[i]),
                security_groups=[security_group.id],
                nics=[{'net-id': networks[i]}])
            vms.append(vm)

        vms_distribution = [(hosts[0], 1), (hosts[1], 1)]
        current_conf = computes_configuration(env)
        for (host, nr_2mb) in vms_distribution:
            exp_free_2m = (initial_conf[host][page_2mb]['total'] -
                           nr_2mb * count_to_allocate_2mb)
            act_free_2m = current_conf[host][page_2mb]['free']
            assert exp_free_2m == act_free_2m, (
                "Unexpected count of free 2Mb huge pages: {0} instead of {1} "
                "for host {2}".format(act_free_2m, exp_free_2m, host))

        for vm in vms:
            self.check_instance_page_size(os_conn, vm, size=page_2mb)
        network_checks.check_vm_connectivity(env, os_conn)
        self.compute_change_state(os_conn, devops_env, hosts[0], state='down')

        vm_0_new = self.evacuate(os_conn, devops_env, vms[0])

        assert hosts[1] == getattr(vm_0_new, "OS-EXT-SRV-ATTR:host"), (
            "Wrong host found for {0} after evacuation. Expected host is {1}".
            format(vm_0_new, hosts[1]))
        network_checks.check_vm_connectivity(env, os_conn)
        for vm in vms:
            self.check_instance_page_size(os_conn, vm, size=page_2mb)

        self.compute_change_state(os_conn, devops_env, hosts[0], state='up')

        vms_distribution = [(hosts[0], 0), (hosts[1], 2)]
        current_conf = computes_configuration(env)
        for (host, nr_2mb) in vms_distribution:
            exp_free_2m = (initial_conf[host][page_2mb]['total'] -
                           nr_2mb * count_to_allocate_2mb)
            act_free_2m = current_conf[host][page_2mb]['free']
            assert exp_free_2m == act_free_2m, (
                "Unexpected count of free 2Mb huge pages: {0} instead of {1} "
                "for host {2}".format(act_free_2m, exp_free_2m, host))
    def test_lm_ceph_for_huge_pages(self, env, os_conn, nova_ceph,
                                    computes_with_hp_2mb, networks,
                                    volume, keypair, small_nfv_flavor,
                                    security_group):
        """This test checks that live migration executed successfully for
            instances created on computes with ceph and huge pages
            Steps:
            1. Create net1 with subnet, net2 with subnet and  router1 with
            interfaces to both nets
            2. Launch instance vm1 with volume vol1 on compute-1 in net1 with
            m1.small.hpgs
            3. Launch instance vm2 on compute-2 in net2 with m1.small.hpgs
            4. Make volume from vm2 volume_vm
            5. Launch instance vm3 on compute-2 in net2 with volume_vm
            with m1.small.hpgs
            6. Check vms connectivity
            7. Live migrate vm1 on compute-2 and check that vm moved to
            compute-2 with Active state
            8. Check vms connectivity
            9. Live migrate vm2 with block-migrate parameter on compute-1 and
            check that vm moved to compute-2 with Active state
            10. Check vms connectivity
            11. Live migrate vm3 on compute-1 and check that vm moved to
            compute-1 with Active state
            12. Check vms connectivity
        """
        count_to_allocate_2mb = small_nfv_flavor.ram * 1024 / page_2mb
        initial_conf = computes_configuration(env)
        hosts = computes_with_hp_2mb

        vm_0 = os_conn.create_server(
            name='vm1', flavor=small_nfv_flavor.id, key_name=keypair.name,
            nics=[{'net-id': networks[0]}],
            availability_zone='nova:{}'.format(hosts[0]),
            security_groups=[security_group.id],
            block_device_mapping={'vda': volume.id})
        vm_1 = os_conn.create_server(
            name='vm2', flavor=small_nfv_flavor.id, key_name=keypair.name,
            availability_zone='nova:{}'.format(hosts[1]),
            security_groups=[security_group.id],
            nics=[{'net-id': networks[1]}])
        volume_vm = self.create_volume_from_vm(os_conn, vm_1)
        vm_2 = os_conn.create_server(
            name='vm3', flavor=small_nfv_flavor.id, key_name=keypair.name,
            nics=[{'net-id': networks[1]}],
            availability_zone='nova:{}'.format(hosts[1]),
            security_groups=[security_group.id],
            block_device_mapping={'vda': volume_vm})
        vms = [vm_0, vm_1, vm_2]

        vms_distribution = [(hosts[0], 1), (hosts[1], 2)]
        current_conf = computes_configuration(env)
        for (host, nr_2mb) in vms_distribution:
            exp_free_2m = (initial_conf[host][page_2mb]['total'] -
                           nr_2mb * count_to_allocate_2mb)
            assert exp_free_2m == current_conf[host][page_2mb]['free']

        for vm in vms:
            self.check_instance_page_size(os_conn, vm, size=page_2mb)
        network_checks.check_vm_connectivity(env, os_conn)

        self.live_migrate(os_conn, vms[0], hosts[1], block_migration=False)
        vms_distribution = [(hosts[0], 0), (hosts[1], 3)]
        current_conf = computes_configuration(env)
        for (host, nr_2mb) in vms_distribution:
            exp_free_2m = (initial_conf[host][page_2mb]['total'] -
                           nr_2mb * count_to_allocate_2mb)
            assert exp_free_2m == current_conf[host][page_2mb]['free']
        network_checks.check_vm_connectivity(env, os_conn)

        self.live_migrate(os_conn, vms[1], hosts[0])
        vms_distribution = [(hosts[0], 1), (hosts[1], 2)]
        current_conf = computes_configuration(env)
        for (host, nr_2mb) in vms_distribution:
            exp_free_2m = (initial_conf[host][page_2mb]['total'] -
                           nr_2mb * count_to_allocate_2mb)
            assert exp_free_2m == current_conf[host][page_2mb]['free']
        network_checks.check_vm_connectivity(env, os_conn)

        self.live_migrate(os_conn, vms[2], hosts[0], block_migration=False)
        vms_distribution = [(hosts[0], 2), (hosts[1], 1)]
        current_conf = computes_configuration(env)
        for (host, nr_2mb) in vms_distribution:
            exp_free_2m = (initial_conf[host][page_2mb]['total'] -
                           nr_2mb * count_to_allocate_2mb)
            assert exp_free_2m == current_conf[host][page_2mb]['free']
        for vm in vms:
            self.check_instance_page_size(os_conn, vm, size=page_2mb)
        network_checks.check_vm_connectivity(env, os_conn)
    def test_lm_cinder_for_cpu_pinning_and_hp(self, env, os_conn, keypair,
                                              computes_with_mixed_hp, volume,
                                              networks, aggregate, flavors,
                                              security_group, ubuntu_image_id):
        """This test checks that live migration executed successfully for
             instances created on computes with cinder and 2 Numa nodes and
             mixed 2Mb and 1Gb huge pages
             Steps:
                 1. Create net1 with subnet, net2 with subnet and  router1 with
                    interfaces to both nets
                 2. Launch instance vm1 with volume vol1 on compute-1 in net1
                    with flavor m1.m1.small.hpgs_numa
                 3. Launch instance vm2 on compute-2 in net2 with with flavor
                    m1.small.performance_1
                 4. Live migrate vm1 with block-migrate parameter on compute-2
                    and check that vm moved to compute-2 with Active state
                 5. Run CPU load on vm2
                 8. Live migrate vm2 on compute-1 and check that vm moved to
                    compute-2 with Active state
                 9. Check vms connectivity
                 10. Check size of huge pages for each vm
                 11. Check vcpus allocation for each vm
                 12. Check count of free huge pages is correct for each host
                 13. Delete all vms
                 14. Repeat actions for flavor m1.small.hpgs_numa-2
        """
        hosts = list(set(computes_with_mixed_hp) & set(aggregate.hosts))
        if len(hosts) < 2:
            pytest.skip("At least 2 hosts with mixed features are required.")

        cpus = get_cpu_distribition_per_numa_node(env)
        initial_conf_hp = computes_configuration(env)

        flavors_param = [(1, page_2mb, flavors[0]),
                         (2, page_1gb, flavors[1])]

        for numa, page_size, flavor in flavors_param:
            vm1 = os_conn.create_server(
                name='vm1', flavor=flavor.id,
                nics=[{'net-id': networks[0]}], key_name=keypair.name,
                availability_zone='nova:{}'.format(hosts[0]),
                security_groups=[security_group.id],
                block_device_mapping={'vda': volume.id},
                wait_for_active=False, wait_for_avaliable=False)
            vm2 = os_conn.create_server(
                name='vm2', image_id=ubuntu_image_id,
                flavor=flavor.id,
                key_name=keypair.name, userdata=userdata,
                availability_zone='nova:{}'.format(hosts[1]),
                security_groups=[security_group.id],
                nics=[{'net-id': networks[1]}],
                wait_for_active=False, wait_for_avaliable=False)
            os_conn.wait_servers_active([vm1, vm2])
            os_conn.wait_servers_ssh_ready([vm1, vm2])
            os_conn.wait_marker_in_servers_log([vm2], marker)

            self.live_migrate(os_conn, vm1, hosts[1], block_migration=False)
            check_vm_connectivity_cirros_ubuntu(env, os_conn, keypair,
                                                cirros=vm1, ubuntu=vm2)

            self.cpu_load(env, os_conn, vm2, vm_keypair=keypair)
            self.live_migrate(os_conn, vm2, hosts[0])
            check_vm_connectivity_cirros_ubuntu(env, os_conn, keypair,
                                                cirros=vm1, ubuntu=vm2)
            self.cpu_load(env, os_conn, vm2, vm_keypair=keypair, action='stop')

            expected_hosts = [(hosts[1], vm1), (hosts[0], vm2)]
            for host, vm in expected_hosts:
                self.check_instance_page_size(os_conn, vm, page_size)
                self.check_cpu_for_vm(os_conn, vm, numa, cpus[host])

            final_conf_hp = computes_configuration(env)
            for host in hosts:
                exp_free = (initial_conf_hp[host][page_size]['total'] -
                            1 * (flavor.ram * 1024 / page_size))
                act_free = final_conf_hp[host][page_size]['free']
                assert exp_free == act_free, (
                    'Unexpected count of {0} huge pages are free: '
                    '{1} instead of {2}'.format(page_size, act_free, exp_free))
            self.delete_servers(os_conn)
    def test_lm_ceph_for_cpu_pinning_and_hp(self, env, os_conn, nova_ceph,
                                            computes_with_mixed_hp, keypair,
                                            networks, aggregate, flavors,
                                            security_group, volume):
        """This test checks that live migration executed successfully for
            instances created on computes with ceph and 2 Numa nodes & mixed
            2Mb and 1Gb huge page.
            Required configuration: at least 2 hosts with mixed features, max
            host's usage is 3 vms
            Steps:
                1. Create net1 with subnet, net2 with subnet and  router1 with
                   interfaces to both nets
                2. Launch instance vm1 with volume vol1 on compute-1 in net1
                   with flavor m1.small.hpgs_numa
                3. Launch instance vm2 on compute-2 in net2 with flavor
                   m1.small.hpgs_numa
                4. Make volume from vm2 volume_vm2
                5. Launch instance vm3 on compute-2 in net2 with volume_vm2
                   with flavor m1.small.hpgs_numa
                6. Live migrate vm1 on compute-2 and check that vm moved to
                   compute-2 with Active state
                7. Live migrate vm2 with block-migrate parameter on compute-1
                   and check that vm moved to compute-1 with Active state
                8. Live migrate vm3 on compute-1 and check that vm moved to
                   compute-1 with Active state
                9. Check vms connectivity
                10. Check page size for all instances
                11. Check allocated vcpus for all instances
                12. Check count of free huge pages
                13. Remove all vms and repeat actions for m1.small.hpgs_numa-2
        """
        hosts_to_use = list(set(computes_with_mixed_hp) & set(aggregate.hosts))
        if len(hosts_to_use) < 2:
            pytest.skip("At least 2 hosts with mixed features are required.")

        cpus = get_cpu_distribition_per_numa_node(env)
        initial_conf_hp = computes_configuration(env)

        flavors_param = [(1, page_2mb, flavors[0]),
                         (2, page_1gb, flavors[1])]

        for numa, page_size, flavor in flavors_param:
            vm1 = os_conn.create_server(
                name='vm1', flavor=flavor.id,
                nics=[{'net-id': networks[0]}], key_name=keypair.name,
                availability_zone='nova:{}'.format(hosts_to_use[0]),
                security_groups=[security_group.id],
                block_device_mapping={'vda': volume.id})
            vm2 = os_conn.create_server(
                name='vm2', flavor=flavor.id,
                nics=[{'net-id': networks[1]}], key_name=keypair.name,
                availability_zone='nova:{}'.format(hosts_to_use[1]),
                security_groups=[security_group.id])
            volume_vm2 = self.create_volume_from_vm(os_conn, vm2)
            vm3 = os_conn.create_server(
                name='vm3', flavor=flavor.id,
                nics=[{'net-id': networks[1]}], key_name=keypair.name,
                availability_zone='nova:{}'.format(hosts_to_use[1]),
                security_groups=[security_group.id],
                block_device_mapping={'vda': volume_vm2})

            self.live_migrate(
                os_conn, vm1, hosts_to_use[1], block_migration=False)
            network_checks.check_vm_connectivity(env, os_conn)

            self.live_migrate(os_conn, vm2, hosts_to_use[0])
            network_checks.check_vm_connectivity(env, os_conn)

            self.live_migrate(
                os_conn, vm3, hosts_to_use[0], block_migration=False)
            network_checks.check_vm_connectivity(env, os_conn)

            expected_hosts = [(hosts_to_use[1], vm1),
                              (hosts_to_use[0], vm2),
                              (hosts_to_use[0], vm3)]
            for host, vm in expected_hosts:
                self.check_instance_page_size(os_conn, vm, page_size)
                self.check_cpu_for_vm(os_conn, vm, numa, cpus[host])

            expected_hosts_usage = [(hosts_to_use[0], 2), (hosts_to_use[1], 1)]
            final_conf_hp = computes_configuration(env)
            for host, nr in expected_hosts_usage:
                exp_free = (initial_conf_hp[host][page_size]['total'] -
                            nr * (flavor.ram * 1024 / page_size))
                act_free = final_conf_hp[host][page_size]['free']
                assert exp_free == act_free, (
                    'Unexpected count of {0} huge pages are free:'
                    '{1} instead of {2}'.format(page_size, act_free, exp_free))

            self.delete_servers(os_conn)
    def test_lm_cinder_lvm_for_huge_pages(self, os_conn, env,
                                          computes_with_hp_2mb, networks,
                                          volume, small_nfv_flavor, keypair,
                                          security_group, ubuntu_image_id):
        """This test checks that live migration executed successfully for
            instances created on computes with cinder lvm and huge pages
            Steps:
            1. Create net1 with subnet, net2 with subnet and  router1 with
            interfaces to both nets
            2. Launch instance vm1 with volume vol1 on compute-1 in net1 with
            m1.small.hpgs
            3. Launch instance vm2 on compute-2 in net2 with m1.small.hpgs and
            ubuntu image
            4. Check vms connectivity
            5. Live migrate vm1 on compute-2 and check that vm moved to
            compute-2 with Active state
            6. Check vms connectivity
            7. Live migrate vm2 with block-migrate parameter on compute-1 and
            check that vm moved to compute-2 with Active state
            8. Check vms connectivity
            9. Run CPU load on vm2
            10. Live migrate vm2 on compute-2 with block-migrate parameter and
            check that vm moved to compute-2 with Active state
            11. Check vms connectivity
        """
        count_to_allocate_2mb = small_nfv_flavor.ram * 1024 / page_2mb
        initial_conf = computes_configuration(env)
        hosts = computes_with_hp_2mb

        vm_0 = os_conn.create_server(
            name='vm1', flavor=small_nfv_flavor.id,
            nics=[{'net-id': networks[0]}], key_name=keypair.name,
            availability_zone='nova:{}'.format(hosts[0]),
            security_groups=[security_group.id],
            block_device_mapping={'vda': volume.id})
        vm_1 = os_conn.create_server(
            name='vm2', image_id=ubuntu_image_id, flavor=small_nfv_flavor.id,
            key_name=keypair.name, userdata=userdata,
            availability_zone='nova:{}'.format(hosts[1]),
            security_groups=[security_group.id],
            nics=[{'net-id': networks[1]}])
        vms = [vm_0, vm_1]
        os_conn.wait_marker_in_servers_log([vm_1], marker)

        expected_hosts_usage = [(hosts[0], 1), (hosts[1], 1)]
        current_conf = computes_configuration(env)
        for (host, nr_2mb) in expected_hosts_usage:
            exp_free_2m = (initial_conf[host][page_2mb]['total'] -
                           nr_2mb * count_to_allocate_2mb)
            assert exp_free_2m == current_conf[host][page_2mb]['free']
        for vm in vms:
            self.check_instance_page_size(os_conn, vm, size=page_2mb)

        check_vm_connectivity_cirros_ubuntu(
            env, os_conn, keypair, cirros=vms[0], ubuntu=vms[1])

        self.live_migrate(os_conn, vms[0], hosts[1], block_migration=False)
        expected_hosts_usage = [(hosts[0], 0), (hosts[1], 2)]
        current_conf = computes_configuration(env)
        for (host, nr_2mb) in expected_hosts_usage:
            exp_free_2m = (initial_conf[host][page_2mb]['total'] -
                           nr_2mb * count_to_allocate_2mb)
            assert exp_free_2m == current_conf[host][page_2mb]['free']

        self.live_migrate(os_conn, vms[1], hosts[0])
        expected_hosts_usage = [(hosts[0], 1), (hosts[1], 1)]
        current_conf = computes_configuration(env)
        for (host, nr_2mb) in expected_hosts_usage:
            exp_free_2m = (initial_conf[host][page_2mb]['total'] -
                           nr_2mb * count_to_allocate_2mb)
            assert exp_free_2m == current_conf[host][page_2mb]['free']

        check_vm_connectivity_cirros_ubuntu(
            env, os_conn, keypair, cirros=vms[0], ubuntu=vms[1])
        self.cpu_load(env, os_conn, vms[1], vm_keypair=keypair)

        self.live_migrate(os_conn, vms[1], hosts[1])
        expected_hosts_usage = [(hosts[0], 0), (hosts[1], 2)]
        current_conf = computes_configuration(env)
        for (host, nr_2mb) in expected_hosts_usage:
            exp_free_2m = (initial_conf[host][page_2mb]['total'] -
                           nr_2mb * count_to_allocate_2mb)
            assert exp_free_2m == current_conf[host][page_2mb]['free']
        for vm in vms:
            self.check_instance_page_size(os_conn, vm, size=page_2mb)
        check_vm_connectivity_cirros_ubuntu(
            env, os_conn, keypair, cirros=vms[0], ubuntu=vms[1])
        self.cpu_load(env, os_conn, vms[1], vm_keypair=keypair, action='stop')