Пример #1
0
def _boot_multiports_vm(flavor,
                        mgmt_net_id,
                        vifs,
                        net_id,
                        net_type,
                        base_vm,
                        pcipt_seg_id=None):
    nics = [{'net-id': mgmt_net_id}]

    nics, glance_vif = _append_nics_for_net(vifs, net_id=net_id, nics=nics)
    img_id = None
    if glance_vif:
        img_id = glance_helper.create_image(name=glance_vif,
                                            hw_vif_model=glance_vif,
                                            cleanup='function')[1]

    LOG.tc_step(
        "Boot a test_vm with following nics on same networks as base_vm: {}".
        format(nics))
    vm_under_test = vm_helper.boot_vm(name='multiports',
                                      nics=nics,
                                      flavor=flavor,
                                      cleanup='function',
                                      image_id=img_id)[1]
    vm_helper.wait_for_vm_pingable_from_natbox(vm_under_test, fail_ok=False)

    if pcipt_seg_id:
        LOG.tc_step("Add vlan to pci-passthrough interface for VM.")
        vm_helper.add_vlan_for_vm_pcipt_interfaces(vm_id=vm_under_test,
                                                   net_seg_id=pcipt_seg_id,
                                                   init_conf=True)

    LOG.tc_step("Ping test_vm's own {} network ips".format(net_type))
    vm_helper.ping_vms_from_vm(to_vms=vm_under_test,
                               from_vm=vm_under_test,
                               net_types=net_type)

    vm_helper.configure_vm_vifs_on_same_net(vm_id=vm_under_test)

    LOG.tc_step(
        "Ping test_vm from base_vm to verify management and data networks connection"
    )
    vm_helper.ping_vms_from_vm(to_vms=vm_under_test,
                               from_vm=base_vm,
                               net_types=['mgmt', net_type])

    return vm_under_test, nics
Пример #2
0
def _bring_up_attached_interface(vm_id,
                                 ports,
                                 guest_os,
                                 base_vm,
                                 action='attach interfaces'):
    """
    ip link set <dev> up, and dhclient <dev> to bring up the interface of last nic for given VM
    Args:
        vm_id (str):
    """
    vm_macs = network_helper.get_ports(field='MAC Address',
                                       server=vm_id,
                                       port_id=ports)
    prompt = Prompt.VXWORKS_PROMPT if guest_os == 'vxworks' else None
    vm_helper.add_ifcfg_scripts(vm_id=vm_id,
                                vm_prompt=prompt,
                                mac_addrs=vm_macs,
                                reboot=False)
    vm_helper.configure_vm_vifs_on_same_net(vm_id=vm_id,
                                            ports=ports,
                                            vm_prompt=prompt,
                                            reboot=True)
    _ping_vm_data(vm_under_test=vm_id, base_vm_id=base_vm, action=action)
Пример #3
0
def test_vm_with_max_vnics_attached_during_boot(base_vm, guest_os, nic_arg,
                                                boot_source):
    """
    Setups:
        - Boot a base vm with mgmt net and tenant_port_id (module)

    Test Steps:
        - Boot a vm with 1 mgmt and 15 avp/virtio Interfaces
        - Perform nova action (live migrate --force, live migrate, rebuild, reboot hard/soft, resize revert, resize)
        - ping between base_vm and vm_under_test over mgmt & tenant network

    Teardown:
        - Delete created vm, volume, port (if any)  (func)
        - Delete base vm, volume    (module)

    """

    base_vm_id, mgmt_nic, tenant_nic, internal_net_id, tenant_net_id, mgmt_net_id = base_vm
    vif_type = 'avp' if system_helper.is_avs() else None

    LOG.tc_step("Get/Create {} glance image".format(guest_os))
    cleanup = None if re.search(GuestImages.TIS_GUEST_PATTERN,
                                guest_os) else 'function'
    image_id = glance_helper.get_guest_image(guest_os=guest_os,
                                             cleanup=cleanup)

    # TODO Update vif model config. Right now vif model avp still under implementation
    nics = [mgmt_nic]
    for i in range(15):
        if nic_arg == 'port_id':
            port_id = network_helper.create_port(tenant_net_id,
                                                 'tenant_port-{}'.format(i),
                                                 wrs_vif=vif_type,
                                                 cleanup='function')[1]
            nics.append({'port-id': port_id})
        else:
            nics.append({'net-id': tenant_net_id, 'vif-model': vif_type})

    LOG.tc_step(
        "Boot a {} vm and flavor from {} with 1 mgmt and 15 data interfaces".
        format(guest_os, boot_source))
    vm_under_test = vm_helper.boot_vm('max_vifs-{}-{}'.format(
        guest_os, boot_source),
                                      nics=nics,
                                      source=boot_source,
                                      image_id=image_id,
                                      guest_os=guest_os,
                                      cleanup='function')[1]

    vm_ports_count = len(network_helper.get_ports(server=vm_under_test))
    expt_vnics = 16
    LOG.info("vnics attached to VM: {}".format(vm_ports_count))
    assert vm_ports_count == expt_vnics, "vnics attached is not equal to max number."

    _ping_vm_data(vm_under_test, vm_under_test, action='boot')
    vm_helper.configure_vm_vifs_on_same_net(vm_id=vm_under_test)
    _ping_vm_data(vm_under_test, base_vm_id, action='configure routes')

    destination_host = vm_helper.get_dest_host_for_live_migrate(
        vm_id=vm_under_test)
    if destination_host:
        # LOG.tc_step("Perform following action(s) on vm {}: {}".format(vm_under_test, 'live-migrate --force'))
        # vm_helper.live_migrate_vm(vm_id=vm_under_test, destination_host=destination_host, force=True)
        # _ping_vm_data(vm_under_test, base_vm_id, action='live migrate --force')

        LOG.tc_step("Perform following action(s) on vm {}: {}".format(
            vm_under_test, 'live-migrate'))
        vm_helper.live_migrate_vm(vm_id=vm_under_test)
        _ping_vm_data(vm_under_test, base_vm_id, action='live-migrate')

    LOG.tc_step("Perform following action(s) on vm {}: {}".format(
        vm_under_test, 'hard reboot'))
    vm_helper.reboot_vm(vm_id=vm_under_test, hard=True)
    _ping_vm_data(vm_under_test, base_vm_id, action='hard reboot')

    LOG.tc_step("Perform following action(s) on vm {}: {}".format(
        vm_under_test, 'soft reboot'))
    vm_helper.reboot_vm(vm_id=vm_under_test)
    _ping_vm_data(vm_under_test, base_vm_id, action='soft rebuild')

    LOG.tc_step('Create destination flavor')
    dest_flavor_id = nova_helper.create_flavor(name='dest_flavor',
                                               vcpus=2,
                                               guest_os=guest_os)[1]

    LOG.tc_step('Resize vm to dest flavor and revert')
    vm_helper.resize_vm(vm_under_test,
                        dest_flavor_id,
                        revert=True,
                        fail_ok=False)
    _ping_vm_data(vm_under_test, base_vm_id, action='resize revert')

    LOG.tc_step('Resize vm to dest flavor and revert False')
    vm_helper.resize_vm(vm_under_test, dest_flavor_id, fail_ok=False)
    vm_helper.configure_vm_vifs_on_same_net(vm_id=vm_under_test)
    _ping_vm_data(vm_under_test, base_vm_id, action='resize')

    LOG.tc_step("Perform following action(s) on vm {}: {}".format(
        vm_under_test, 'rebuild'))
    vm_helper.rebuild_vm(vm_id=vm_under_test)
    _ping_vm_data(vm_under_test, vm_under_test, action='rebuild')
    vm_helper.configure_vm_vifs_on_same_net(vm_id=vm_under_test)
    _ping_vm_data(vm_under_test, base_vm_id, action='rebuild')
Пример #4
0
    def test_multiports_on_same_network_pci_evacuate_vm(self, base_setup_pci,
                                                        vifs):
        """
        Test evacuate vm with multiple ports on same network

        Args:
            base_setup_pci (tuple): base vm id, vm under test id, segment id
                for internal0-net1
            vifs (list): list of vifs to add to same internal net

        Setups:
            - create a flavor with dedicated cpu policy (module)
            - choose one tenant network and one internal network to be used
            by test (module)
            - boot a base vm - vm1 with above flavor and networks, and ping
            it from NatBox (module)
            - Boot a vm under test - vm2 with above flavor and with multiple
            ports on same tenant network with base vm,
            and ping it from NatBox     (class)
            - Ping vm2's own data network ips       (class)
            - Ping vm2 from vm1 to verify management and internal networks
            connection   (class)

        Test Steps:
            - Reboot vm2 host
            - Wait for vm2 to be evacuated to other host
            - Wait for vm2 pingable from NatBox
            - Verify ping from vm1 to vm2 over management and internal
            networks still works

        Teardown:
            - Delete created vms and flavor
        """
        base_vm_pci, flavor, base_nics, avail_sriov_net, avail_pcipt_net, \
            pcipt_seg_ids, extra_pcipt_net = base_setup_pci

        internal_net_id = None
        pcipt_included = False
        nics = copy.deepcopy(base_nics)
        if 'pci-passthrough' in vifs:
            if not avail_pcipt_net:
                skip(SkipHostIf.PCIPT_IF_UNAVAIL)
            pcipt_included = True
            internal_net_id = avail_pcipt_net
            if extra_pcipt_net:
                nics.append(
                    {'net-id': extra_pcipt_net, 'vif-model': 'pci-passthrough'})
        if 'pci-sriov' in vifs:
            if not avail_sriov_net:
                skip(SkipHostIf.SRIOV_IF_UNAVAIL)
            internal_net_id = avail_sriov_net
        assert internal_net_id, "test script error. sriov or pcipt has to be " \
                                "included."

        for vif in vifs:
            nics.append({'net-id': internal_net_id, 'vif-model': vif})

        LOG.tc_step(
            "Boot a vm with following vifs on same network internal0-net1: "
            "{}".format(vifs))
        vm_under_test = vm_helper.boot_vm(name='multiports_pci_evac',
                                          nics=nics, flavor=flavor,
                                          cleanup='function',
                                          reuse_vol=False)[1]
        vm_helper.wait_for_vm_pingable_from_natbox(vm_under_test, fail_ok=False)

        if pcipt_included:
            LOG.tc_step("Add vlan to pci-passthrough interface.")
            vm_helper.add_vlan_for_vm_pcipt_interfaces(vm_id=vm_under_test,
                                                       net_seg_id=pcipt_seg_ids,
                                                       init_conf=True)

        LOG.tc_step("Ping vm's own data and internal network ips")
        vm_helper.ping_vms_from_vm(to_vms=vm_under_test, from_vm=vm_under_test,
                                   net_types=['data', 'internal'])
        vm_helper.configure_vm_vifs_on_same_net(vm_id=vm_under_test)

        LOG.tc_step(
            "Ping vm_under_test from base_vm over management, data, and "
            "internal networks")
        vm_helper.ping_vms_from_vm(to_vms=vm_under_test, from_vm=base_vm_pci,
                                   net_types=['mgmt', 'data', 'internal'])

        host = vm_helper.get_vm_host(vm_under_test)

        LOG.tc_step("Reboot vm host {}".format(host))
        vm_helper.evacuate_vms(host=host, vms_to_check=vm_under_test,
                               ping_vms=True)

        if pcipt_included:
            LOG.tc_step(
                "Add/Check vlan interface is added to pci-passthrough device "
                "for vm {}.".format(vm_under_test))
            vm_helper.add_vlan_for_vm_pcipt_interfaces(vm_id=vm_under_test,
                                                       net_seg_id=pcipt_seg_ids)

        LOG.tc_step(
            "Verify ping from base_vm to vm_under_test over management and "
            "internal networks still works after evacuation.")
        vm_helper.ping_vms_from_vm(to_vms=vm_under_test, from_vm=base_vm_pci,
                                   net_types=['mgmt', 'internal'])
Пример #5
0
    def test_multiports_on_same_network_pci_vm_actions(self, check_avs_pattern,
                                                       base_setup_pci, vifs):
        """
        Test vm actions on vm with multiple ports with given vif models on the same tenant network

        Args:
            base_setup_pci (tuple): base_vm_pci, flavor, mgmt_net_id, tenant_net_id,
                internal_net_id, seg_id
            vifs (list): list of vifs to add to same internal net

        Setups:
            - Create a flavor with dedicated cpu policy (class)
            - Choose management net, one tenant net, and internal0-net1 to be used by test (class)
            - Boot a base pci-sriov vm - vm1 with above flavor and networks, ping it
                from NatBox (class)
            - Ping vm1 from itself over data, and internal networks

        Test Steps:
            - Boot a vm under test - vm2 with above flavor and with multiple ports on same tenant
                network with vm1, and ping it from NatBox
            - Ping vm2's own data and internal network ips
            - Ping vm2 from vm1 to verify management and data networks connection
            - Perform one of the following actions on vm2
                - set to error/ wait for auto recovery
                - suspend/resume
                - cold migration
                - pause/unpause
            - Update vlan interface to proper eth if pci-passthrough device moves to different eth
            - Verify ping from vm1 to vm2 over management and data networks still works
            - Repeat last 3 steps with different vm actions

        Teardown:
            - Delete created vms and flavor
        """

        base_vm_pci, flavor, base_nics, avail_sriov_net, avail_pcipt_net, pcipt_seg_ids, \
            extra_pcipt_net = base_setup_pci

        pcipt_included = sriov_included = False
        internal_net_id = None
        for vif in vifs:
            if not isinstance(vif, str):
                vif = vif[0]
            if 'pci-passthrough' in vif:
                if not avail_pcipt_net:
                    skip(SkipHostIf.PCIPT_IF_UNAVAIL)
                internal_net_id = avail_pcipt_net
                pcipt_included = True
                continue
            elif 'pci-sriov' in vif:
                sriov_included = True
                if not avail_sriov_net:
                    skip(SkipHostIf.SRIOV_IF_UNAVAIL)
                internal_net_id = avail_sriov_net

        assert internal_net_id, "test script error. Internal net should have been determined."

        nics, glance_vif = _append_nics_for_net(vifs,
                                                net_id=internal_net_id,
                                                nics=base_nics)
        if pcipt_included and extra_pcipt_net:
            nics.append({
                'net-id': extra_pcipt_net,
                'vif-model': 'pci-passthrough'
            })

        img_id = None
        if glance_vif:
            img_id = glance_helper.create_image(name=glance_vif,
                                                hw_vif_model=glance_vif,
                                                cleanup='function')[1]

        LOG.tc_step(
            "Boot a vm with following vifs on same internal net: {}".format(
                vifs))
        vm_under_test = vm_helper.boot_vm(name='multiports_pci',
                                          nics=nics,
                                          flavor=flavor,
                                          cleanup='function',
                                          reuse_vol=False,
                                          image_id=img_id)[1]
        vm_helper.wait_for_vm_pingable_from_natbox(vm_under_test,
                                                   fail_ok=False)

        if pcipt_included:
            LOG.tc_step("Add vlan to pci-passthrough interface for VM.")
            vm_helper.add_vlan_for_vm_pcipt_interfaces(
                vm_id=vm_under_test, net_seg_id=pcipt_seg_ids, init_conf=True)

        LOG.tc_step("Ping vm's own data and internal network ips")
        vm_helper.ping_vms_from_vm(to_vms=vm_under_test,
                                   from_vm=vm_under_test,
                                   net_types=['data', 'internal'])
        vm_helper.configure_vm_vifs_on_same_net(vm_id=vm_under_test)

        LOG.tc_step(
            "Ping vm_under_test from base_vm over management, data, and internal networks"
        )
        vm_helper.ping_vms_from_vm(to_vms=vm_under_test,
                                   from_vm=base_vm_pci,
                                   net_types=['mgmt', 'data', 'internal'])

        vm_macs = network_helper.get_ports(server=vm_under_test,
                                           network=internal_net_id,
                                           field='MAC Address')
        vmacs = [mac for mac in vm_macs if not mac.strip().startswith('90:')]
        with vm_helper.ssh_to_vm_from_natbox(vm_id=vm_under_test) as vm_ssh:
            prev_eths = []
            for vm_mac in vmacs:
                prev_eth = network_helper.get_eth_for_mac(ssh_client=vm_ssh,
                                                          mac_addr=vm_mac)
                prev_eths.append(prev_eth)

        for vm_actions in [['auto_recover'], ['cold_migrate'],
                           ['pause', 'unpause'], ['suspend', 'resume']]:
            if 'auto_recover' in vm_actions:
                LOG.tc_step(
                    "Set vm to error state and wait for auto recovery complete, "
                    "then verify ping from base vm over management and internal networks"
                )
                vm_helper.set_vm_state(vm_id=vm_under_test,
                                       error_state=True,
                                       fail_ok=False)
                vm_helper.wait_for_vm_values(vm_id=vm_under_test,
                                             status=VMStatus.ACTIVE,
                                             fail_ok=False,
                                             timeout=600)
            else:
                LOG.tc_step("Perform following action(s) on vm {}: {}".format(
                    vm_under_test, vm_actions))
                for action in vm_actions:
                    vm_helper.perform_action_on_vm(vm_under_test,
                                                   action=action)

            vm_helper.wait_for_vm_pingable_from_natbox(vm_id=vm_under_test)
            if sriov_included and 'resume' in vm_actions:
                # After suspend/resume, the eth name for sriov interface will change, this is a
                # known upstream limitation. Work around it by rebooting the vm.
                rebooted = False
                with vm_helper.ssh_to_vm_from_natbox(
                        vm_id=vm_under_test) as vm_ssh:
                    eth_names = []
                    for vm_mac in vmacs:
                        eth_name = network_helper.get_eth_for_mac(
                            ssh_client=vm_ssh, mac_addr=vm_mac)
                        eth_names.append(eth_name)
                    if eth_names != prev_eths:
                        rebooted = True
                        vm_helper.sudo_reboot_from_vm(
                            vm_id=vm_under_test,
                            vm_ssh=vm_ssh,
                            check_host_unchanged=False,
                            force=False)
                if rebooted:
                    vm_helper.wait_for_vm_pingable_from_natbox(
                        vm_id=vm_under_test)

            if pcipt_included:
                LOG.tc_step(
                    "Bring up vlan interface for pci-passthrough vm {}.".
                    format(vm_under_test))
                vm_helper.add_vlan_for_vm_pcipt_interfaces(
                    vm_id=vm_under_test, net_seg_id=pcipt_seg_ids)

            LOG.tc_step(
                "Verify ping from base_vm to vm_under_test over management and "
                "internal networks still works "
                "after {}".format(vm_actions))
            vm_helper.ping_vms_from_vm(to_vms=vm_under_test,
                                       from_vm=base_vm_pci,
                                       net_types=['mgmt', 'internal'])