def test_mac_pools_in_different_clusters_dont_overlap(
        system, cluster_0, default_cluster, ovirtmgmt_vnic_profile):
    MAC_POOL_0 = 'mac_pool_0'
    MAC_POOL_1 = 'mac_pool_1'

    # NOTE: Static MAC address assignments are independent from the MAC pool
    # range, i.e. it is possible to assign addresses outside the range to
    # vNics (this causes the static address to be added to the pool if it is
    # not already present). However, specifying ranges is required for MAC pool
    # initialization, and as such, arbitrary ranges are used.

    default_cluster_mac_pool = clusterlib.mac_pool(
        system, default_cluster, MAC_POOL_0, (MAC_POOL_RANGE,)
    )
    cluster_0_mac_pool = clusterlib.mac_pool(
        system, cluster_0, MAC_POOL_1, (MAC_POOL_RANGE,)
    )
    with default_cluster_mac_pool, cluster_0_mac_pool:
        with virtlib.vm_pool(system, size=2) as (vm_0, vm_1):
            vm_0.create(vm_name=VM0,
                        cluster=default_cluster,
                        template=templatelib.TEMPLATE_BLANK)
            vm_0.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)

            vm_1.create(vm_name=VM1,
                        cluster=cluster_0,
                        template=templatelib.TEMPLATE_BLANK)
            with pytest.raises(netlib.MacAddrInUseError):
                vm_1.create_vnic(
                    NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1
                )
def test_restore_snapshot_with_an_used_mac_implicitly_assigns_new_mac(
        system, default_cluster, ovirtmgmt_vnic_profile, cirros_template):

    with virtlib.vm_pool(system, size=2) as (vm_0, vm_1):
        vm_0.create(vm_name=VM0,
                    cluster=default_cluster,
                    template=cirros_template)
        vm_0.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)
        vm_0.wait_for_down_status()

        vm_0.run()
        vm_0.wait_for_up_status()

        snapshot = _create_snapshot(vm_0)

        _replace_vnic_mac_addr(vm_0, MAC_ADDR_2)

        vm_1.create(vm_name=VM1,
                    cluster=default_cluster,
                    template=cirros_template)
        vm_1.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)

        vm_0.stop()
        vm_0.wait_for_down_status()

        snapshot.restore()

        vnic_0 = vm_0.get_vnic(NIC_NAME_1)
        assert vnic_0.mac_address != MAC_ADDR_1
def test_undo_preview_snapshot_when_mac_used_reassigns_a_new_mac(
        system, default_cluster, ovirtmgmt_vnic_profile, cirros_template):
    with virtlib.vm_pool(system, size=2) as (vm_0, vm_1):
        vm_0.create(vm_name=VM0,
                    cluster=default_cluster,
                    template=cirros_template)
        vm_0.wait_for_down_status()

        vm_0.run()
        vm_0.wait_for_up_status()

        nicless_snapshot = _create_snapshot(vm_0)

        vm_0.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)
        vm_0.stop()
        vm_0.wait_for_down_status()

        nicless_snapshot.preview()
        nicless_snapshot.wait_for_preview_status()

        vm_1.create(vm_name=VM1,
                    cluster=default_cluster,
                    template=cirros_template)
        vm_1.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)

        nicless_snapshot.undo_preview()

        assert vm_0.get_vnic(NIC_NAME_1).mac_address != MAC_ADDR_1
def test_move_mac_to_new_vm(
        system, default_cluster, ovirtmgmt_vnic_profile, cirros_template):

    with virtlib.vm_pool(system, size=2) as (vm_0, vm_1):
        vm_0.create(vm_name=VM0,
                    cluster=default_cluster,
                    template=cirros_template)

        vnic_0 = vm_0.create_vnic(NIC_NAME_1,
                                  ovirtmgmt_vnic_profile, MAC_ADDR_1)
        vm_0.wait_for_down_status()

        vm_0.run()
        vm_0.wait_for_up_status()

        vnic_0.hot_replace_mac_addr(MAC_ADDR_2)

        vm_1.create(vm_name=VM1,
                    cluster=default_cluster,
                    template=cirros_template)

        vm_1.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)

        vnic_1 = vm_1.get_vnic(NIC_NAME_1)
        assert vnic_1.mac_address == MAC_ADDR_1
def _run_scenario_of_bz_1760170(system, default_dc, cluster_0, cluster_1):
    """
    The BZ shows that the pool allocates an address which is used in another
    pool, although there is another unused address in the pool.
    Tricking the allocation pointer to point to a used address is achieved by
    exhausting the free addresses in the pool and then removing a vnic so that
    there is a free and unused address to allocate, but the pointer points to a
    used address and therefore it is wrongly allocated because usability is not
    checked.
    Flow:
    - on cluster_0 (pool_0) create vm_0 with 2 vnics
    - remove the second vnic
    - move vm_0 to cluster_1 (pool_1)
    - create vm_1 on cluster_0
    - create a vnic on vm_1: this fails because the allocated address is in use
      on vm_0, but it should not fail because there is another free address on
      pool_0
    """
    NET_NAME = 'net_bz_1760170'
    with clusterlib.new_assigned_network(
            NET_NAME, default_dc, cluster_0) as net:
        with virtlib.vm_pool(system, size=2) as (vm_0, vm_1):
            vm_0.create(vm_name=VM0, cluster=cluster_0, template=BLANK)
            vm_0.wait_for_down_status()
            vm_0.create_vnic(
                netlib.OVIRTMGMT,
                default_dc.get_mgmt_network().vnic_profile()
            )
            vnic = vm_0.create_vnic(NET_NAME, net.vnic_profile())
            vnic.remove()
            vm_0.move_to_cluster(cluster_1)

            vm_1.create(vm_name=VM1, cluster=cluster_0, template=BLANK)
            vm_1.wait_for_down_status()
            vm_1.create_vnic(NET_NAME, net.vnic_profile())
def vm_in_ovs_cluster_down(system, ovs_cluster, cirros_template):
    with virtlib.vm_pool(system, size=1) as (vm, ):
        vm.create(vm_name=VM0_NAME,
                  cluster=ovs_cluster,
                  template=cirros_template)
        vm.wait_for_down_status()
        yield vm
Beispiel #7
0
def test_undo_preview_snapshot_when_mac_used_reassigns_a_new_mac(
        system, default_cluster, ovirtmgmt_vnic_profile, cirros_template):
    with virtlib.vm_pool(system, size=2) as (vm_0, vm_1):
        vm_0.create(vm_name=VM0,
                    cluster=default_cluster,
                    template=cirros_template)
        vm_0.wait_for_down_status()

        vm_0.run()
        vm_0.wait_for_up_status()

        nicless_snapshot = _create_snapshot(vm_0)

        vm_0.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)
        vm_0.stop()
        vm_0.wait_for_down_status()

        nicless_snapshot.preview()
        nicless_snapshot.wait_for_preview_status()

        vm_1.create(vm_name=VM1,
                    cluster=default_cluster,
                    template=cirros_template)
        vm_1.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)

        nicless_snapshot.undo_preview()

        assert vm_0.get_vnic(NIC_NAME_1).mac_address != MAC_ADDR_1
Beispiel #8
0
def vms_up_on_host_1(
    system,
    default_cluster,
    cirros_template,
    port_isolation_network,
    ovirtmgmt_vnic_profile,
    cirros_serial_console,
    vms_conf,
):
    """
    Since the isolated_network is set up only on host_1,
    both virtual machines will be on it.
    """
    with virtlib.vm_pool(system, size=2) as (vm_0, vm_1):
        for i, vm in enumerate([vm_0, vm_1]):
            vm.create(vm_name=vms_conf[i].name,
                      cluster=default_cluster,
                      template=cirros_template)
            vm_vnic0 = netlib.Vnic(vm)
            vm_vnic0.create(name=vms_conf[i].mgmt_iface.name,
                            vnic_profile=ovirtmgmt_vnic_profile)

            vm_vnic1 = netlib.Vnic(vm)
            vm_vnic1.create(name=vms_conf[i].isolated_iface.name,
                            vnic_profile=port_isolation_network.vnic_profile())
            vm.wait_for_down_status()
            vm.run_once(cloud_init_hostname=vms_conf[i].name)

        vm_0.wait_for_up_status()
        vm_1.wait_for_up_status()
        joblib.AllJobs(system).wait_for_done()
        for vm in (vm_0, vm_1):
            ip_a = cirros_serial_console.shell(vm.id, ('ip addr', ))
            LOGGER.debug(f'before applying ips: vm={vm.name} has ip_a={ip_a}')
        yield vm_0, vm_1
def test_move_stateless_vm_mac_to_new_vm_fails(system, default_cluster,
                                               ovirtmgmt_vnic_profile,
                                               cirros_template):

    with virtlib.vm_pool(system, size=2) as (vm_0, vm_1):
        vm_0.create(vm_name='test_move_stateless_vm_mac_to_new_vm_fails_vm_0',
                    cluster=default_cluster,
                    template=cirros_template,
                    stateless=True)

        vnic_0 = vm_0.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile,
                                  MAC_ADDR_1)
        vm_0.wait_for_down_status()

        vm_0.run()
        vm_0.wait_for_up_status()
        joblib.AllJobs(system).wait_for_done()
        vnic_0.hot_replace_mac_addr(MAC_ADDR_2)

        vm_1.create(vm_name='test_move_stateless_vm_mac_to_new_vm_fails_vm_1',
                    cluster=default_cluster,
                    template=cirros_template)

        with pytest.raises(netlib.MacAddrInUseError):
            vm_1.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)
def test_move_mac_to_new_vm(system, default_cluster, ovirtmgmt_vnic_profile,
                            cirros_template):
    mac_addr_1 = '00:1a:4a:16:01:81'
    mac_addr_2 = '00:1a:4a:16:01:82'
    with virtlib.vm_pool(system, size=2) as (vm_0, vm_1):
        vm_0.create(vm_name='test_move_mac_to_new_vm_0',
                    cluster=default_cluster,
                    template=cirros_template)

        vnic_0 = vm_0.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile,
                                  mac_addr_1)
        vm_0.wait_for_down_status()

        vm_0.run()
        vm_0.wait_for_up_status()
        joblib.AllJobs(system).wait_for_done()
        vnic_0.hot_replace_mac_addr(mac_addr_2)

        vm_1.create(vm_name='test_move_mac_to_new_vm_1',
                    cluster=default_cluster,
                    template=cirros_template)

        vm_1.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, mac_addr_1)

        vnic_1 = vm_1.get_vnic(NIC_NAME_1)
        assert vnic_1.mac_address == mac_addr_1
Beispiel #11
0
def test_mac_pools_in_different_clusters_dont_overlap(system, cluster_0,
                                                      default_cluster,
                                                      ovirtmgmt_vnic_profile):
    MAC_POOL_0 = 'mac_pool_0'
    MAC_POOL_1 = 'mac_pool_1'

    # NOTE: Static MAC address assignments are independent from the MAC pool
    # range, i.e. it is possible to assign addresses outside the range to
    # vNics (this causes the static address to be added to the pool if it is
    # not already present). However, specifying ranges is required for MAC pool
    # initialization, and as such, non-overlapping ranges are used.

    default_cluster_mac_pool = clusterlib.mac_pool(system, default_cluster,
                                                   MAC_POOL_0,
                                                   (MAC_POOL_RANGE, ))
    cluster_0_mac_pool = clusterlib.mac_pool(system, cluster_0, MAC_POOL_1,
                                             (MAC_POOL_RANGE_1, ))
    with default_cluster_mac_pool, cluster_0_mac_pool:
        with virtlib.vm_pool(system, size=2) as (vm_0, vm_1):
            vm_0.create(vm_name=VM0,
                        cluster=default_cluster,
                        template=templatelib.TEMPLATE_BLANK)
            vm_0.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)

            vm_1.create(vm_name=VM1,
                        cluster=cluster_0,
                        template=templatelib.TEMPLATE_BLANK)
            with pytest.raises(netlib.MacAddrInUseError):
                vm_1.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile,
                                 MAC_ADDR_1)
def vms_up_on_same_host(system, default_cluster, cirros_template,
                        port_isolation_network, ovirtmgmt_vnic_profile):
    """
    Since the isolated_network is set up only on one host,
    both virtual machines will be on the same host.
    """
    with virtlib.vm_pool(system, size=2) as (vm_0, vm_1):
        vms = [(vm_0, VM0_NAME), (vm_1, VM1_NAME)]
        for vm, name in vms:
            vm.create(vm_name=name,
                      cluster=default_cluster,
                      template=cirros_template)
            vm_vnic0 = netlib.Vnic(vm)
            vm_vnic0.create(
                name=VNIC0_NAME,
                vnic_profile=ovirtmgmt_vnic_profile,
            )
            vm_vnic1 = netlib.Vnic(vm)
            vm_vnic1.create(
                name=VNIC1_NAME,
                vnic_profile=port_isolation_network.vnic_profile(),
            )
            vm.wait_for_down_status()
            vm.run_once(cloud_init_hostname=name)

        vm_0.wait_for_up_status()
        vm_1.wait_for_up_status()
        joblib.AllJobs(system).wait_for_done()
        yield
Beispiel #13
0
def test_restore_snapshot_with_an_used_mac_implicitly_assigns_new_mac(
        system, default_cluster, ovirtmgmt_vnic_profile, cirros_template):

    with virtlib.vm_pool(system, size=2) as (vm_0, vm_1):
        vm_0.create(vm_name=VM0,
                    cluster=default_cluster,
                    template=cirros_template)
        vm_0.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)
        vm_0.wait_for_down_status()

        vm_0.run()
        vm_0.wait_for_up_status()

        snapshot = _create_snapshot(vm_0)

        _replace_vnic_mac_addr(vm_0, MAC_ADDR_2)

        vm_1.create(vm_name=VM1,
                    cluster=default_cluster,
                    template=cirros_template)
        vm_1.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)

        vm_0.stop()
        vm_0.wait_for_down_status()

        snapshot.restore()

        vnic_0 = vm_0.get_vnic(NIC_NAME_1)
        assert vnic_0.mac_address != MAC_ADDR_1
def test_set_mac_pool_duplicate_macs_from_true_to_false_while_dup_exists(
        system, default_cluster, ovirtmgmt_vnic_profile):
    with clusterlib.mac_pool(
            system,
            default_cluster,
            MAC_POOL,
        (MAC_POOL_RANGE, ),
            allow_duplicates=True,
    ) as mac_pool:
        with virtlib.vm_pool(system, size=2) as (vm_0, vm_1):
            vm_0.create(
                vm_name='test_set_mac_pool_duplicate_macs_vm_0',
                cluster=default_cluster,
                template=templatelib.TEMPLATE_BLANK,
            )
            vm_1.create(
                vm_name='test_set_mac_pool_duplicate_macs_vm_1',
                cluster=default_cluster,
                template=templatelib.TEMPLATE_BLANK,
            )

            vm_0.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)
            vm_0.wait_for_down_status()

            vm_1.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)
            vm_1.wait_for_down_status()

            with pytest.raises(clusterlib.MacPoolContainsDuplicatesError):
                mac_pool.set_allow_duplicates(False)
def test_connect_vm_to_external_network(ovirt_external_network, system,
                                        default_cluster,
                                        default_ovn_provider_client,
                                        default_storage_domain):
    cluster_network = clusterlib.ClusterNetwork(default_cluster)
    cluster_network.assign(ovirt_external_network)
    with virtlib.vm_pool(system, size=1) as (vm_0,):
        vm_0.create(
            vm_name=VM0_NAME,
            cluster=default_cluster,
            template=templatelib.TEMPLATE_BLANK
        )
        disk = default_storage_domain.create_disk('disk1')
        vm_0.attach_disk(disk=disk)

        vnic_profile0 = netlib.VnicProfile(system)
        vnic_profile0.import_by_name(ovirt_external_network.name)

        assert not vnic_profile0.filter

        vm0_vnic_0 = netlib.Vnic(vm_0)
        vm0_vnic_0.create(
            name=VNIC0_NAME,
            vnic_profile=vnic_profile0,
            mac_addr=VNIC0_MAC
        )
        vm_0.wait_for_down_status()

        vm_0.run()
        vm_0.wait_for_up_status()

        ovn_port = _lookup_port_by_device_id(
            vm0_vnic_0.id, default_ovn_provider_client)
        assert ovn_port
        assert vm0_vnic_0.mac_address == ovn_port.mac_address
Beispiel #16
0
def running_vm_0(
    ovirt_external_network,
    system,
    default_cluster,
    default_storage_domain,
    cirros_template,
):
    cluster_network = clusterlib.ClusterNetwork(default_cluster)
    cluster_network.assign(ovirt_external_network)
    with virtlib.vm_pool(system, size=1) as (vm_0, ):
        vm_0.create(vm_name=VM0_NAME,
                    cluster=default_cluster,
                    template=cirros_template)

        vnic_profile0 = ovirt_external_network.vnic_profile()

        vm0_vnic_0 = netlib.Vnic(vm_0)
        vm0_vnic_0.create(name=VNIC0_NAME,
                          vnic_profile=vnic_profile0,
                          mac_addr=VNIC0_MAC)

        vm_0.wait_for_down_status()
        vm_0.run()
        vm_0.wait_for_up_status()
        joblib.AllJobs(system).wait_for_done()
        yield vm_0
Beispiel #17
0
def vm_down(system, default_cluster, default_storage_domain):
    with virtlib.vm_pool(system, size=1) as (vm,):
        vm.create(vm_name=VM0,
                  cluster=default_cluster,
                  template=templatelib.TEMPLATE_BLANK)
        disk = default_storage_domain.create_disk(DISK0)
        disk_att_id = vm.attach_disk(disk=disk)
        vm.wait_for_disk_up_status(disk, disk_att_id)
        vm.wait_for_down_status()
        yield vm
def vm_down(system, default_cluster, storage_domain, vm_name, disk_name):
    with virtlib.vm_pool(system, size=1) as (vm,):
        vm.create(vm_name=vm_name,
                  cluster=default_cluster,
                  template=templatelib.TEMPLATE_BLANK)
        disk = storage_domain.create_disk(disk_name)
        disk_att_id = vm.attach_disk(disk=disk)
        vm.wait_for_disk_up_status(disk, disk_att_id)
        vm.wait_for_down_status()
        yield vm
Beispiel #19
0
def running_vm_0(system, default_cluster, default_storage_domain,
                 ovirtmgmt_vnic_profile):
    disk = default_storage_domain.create_disk('disk0')
    with virtlib.vm_pool(system, size=1) as (vm, ):
        vm.create(vm_name=VM0,
                  cluster=default_cluster,
                  template=templatelib.TEMPLATE_BLANK)

        _attach_new_vnic(vm, ovirtmgmt_vnic_profile)

        disk_att_id = vm.attach_disk(disk=disk)
        vm.wait_for_disk_up_status(disk, disk_att_id)
        vm.run()
        vm.wait_for_up_status()
        yield vm
def running_vm_0(system, default_cluster, default_storage_domain,
                 ovirtmgmt_vnic_profile):
    disk = default_storage_domain.create_disk('disk0')
    with virtlib.vm_pool(system, size=1) as (vm,):
        vm.create(vm_name=VM0,
                  cluster=default_cluster,
                  template=templatelib.TEMPLATE_BLANK)

        _attach_new_vnic(vm, ovirtmgmt_vnic_profile)

        disk_att_id = vm.attach_disk(disk=disk)
        vm.wait_for_disk_up_status(disk, disk_att_id)
        vm.run()
        vm.wait_for_up_status()
        yield vm
Beispiel #21
0
def test_assign_vnic_with_full_mac_pool_capacity_fails(system, default_cluster,
                                                       ovirtmgmt_vnic_profile):
    NIC_NAME_3 = 'nic003'

    with clusterlib.mac_pool(system, default_cluster, MAC_POOL,
                             (MAC_POOL_RANGE, )):
        with virtlib.vm_pool(system, size=1) as (vm, ):
            vm.create(vm_name=VM0,
                      cluster=default_cluster,
                      template=templatelib.TEMPLATE_BLANK)
            vm.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile)
            vm.create_vnic(NIC_NAME_2, ovirtmgmt_vnic_profile)

            with pytest.raises(netlib.MacPoolIsInFullCapacityError):
                vm.create_vnic(NIC_NAME_3, ovirtmgmt_vnic_profile)
Beispiel #22
0
def running_blank_vm(system, default_cluster, default_storage_domain,
                     ovirtmgmt_vnic_profile):
    disk = default_storage_domain.create_disk('disk0')
    with virtlib.vm_pool(system, size=1) as (vm, ):
        vm.create(
            vm_name=VM_BLANK,
            cluster=default_cluster,
            template=templatelib.TEMPLATE_BLANK,
        )
        vm.create_vnic(NIC_NAMES[1], ovirtmgmt_vnic_profile)
        disk_att_id = vm.attach_disk(disk=disk)
        vm.wait_for_disk_up_status(disk, disk_att_id)
        vm.run()
        vm.wait_for_up_status()
        joblib.AllJobs(system).wait_for_done()
        yield vm
def test_assign_vnic_with_full_mac_pool_capacity_fails(
        system, default_cluster, ovirtmgmt_vnic_profile):
    NIC_NAME_3 = 'nic003'

    with clusterlib.mac_pool(
        system, default_cluster, MAC_POOL, (MAC_POOL_RANGE,)
    ):
        with virtlib.vm_pool(system, size=1) as (vm,):
            vm.create(vm_name=VM0,
                      cluster=default_cluster,
                      template=templatelib.TEMPLATE_BLANK)
            vm.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile)
            vm.create_vnic(NIC_NAME_2, ovirtmgmt_vnic_profile)

            with pytest.raises(netlib.MacPoolIsInFullCapacityError):
                vm.create_vnic(NIC_NAME_3, ovirtmgmt_vnic_profile)
def vm_0_with_display_network_and_disk(
        system, default_cluster, default_storage_domain,
        display_network_vnic_profile):
    VM_0 = 'vm0'
    VNIC_1 = 'vnic1'

    with virtlib.vm_pool(system, size=1) as (vm_0,):
        vm_0.create(vm_name=VM_0,
                    cluster=default_cluster,
                    template=templatelib.TEMPLATE_BLANK)
        disk_0 = default_storage_domain.create_disk('disk0')
        vm_0.attach_disk(disk=disk_0)
        vm_0.wait_for_down_status()
        vm_0.create_vnic(VNIC_1, display_network_vnic_profile)
        vm_0.wait_for_down_status()
        yield vm_0
Beispiel #25
0
def vm_0_with_display_network_and_disk(system, default_cluster,
                                       default_storage_domain,
                                       display_network_vnic_profile):
    VM_0 = 'vm0'
    VNIC_1 = 'vnic1'

    with virtlib.vm_pool(system, size=1) as (vm_0, ):
        vm_0.create(vm_name=VM_0,
                    cluster=default_cluster,
                    template=templatelib.TEMPLATE_BLANK)
        disk_0 = default_storage_domain.create_disk('disk0')
        vm_0.attach_disk(disk=disk_0)
        vm_0.wait_for_down_status()
        vm_0.create_vnic(VNIC_1, display_network_vnic_profile)
        vm_0.wait_for_down_status()
        yield vm_0
def test_restore_snapshot_with_an_used_mac_implicitly_assigns_new_mac(
    system,
    default_cluster,
    ovirtmgmt_vnic_profile,
    cirros_template,
    cirros_serial_console,
):

    with virtlib.vm_pool(system, size=2) as (vm_0, vm_1):
        vm_0.create(
            vm_name='test_restore_snapshot_with_an_used_mac_vm_0',
            cluster=default_cluster,
            template=cirros_template,
        )
        vnic_0 = vm_0.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile,
                                  MAC_ADDR_1)
        vm_0.wait_for_down_status()

        vm_0.run()
        vm_0.wait_for_up_status()
        joblib.AllJobs(system).wait_for_done()
        snapshot = vm_0.create_snapshot(SNAPSHOT_DESC)
        joblib.AllJobs(system).wait_for_done()
        _wait_for_running_vm(cirros_serial_console, vm_0.id)
        vnic_0.hot_replace_mac_addr(MAC_ADDR_2)

        vm_1.create(
            vm_name='test_restore_snapshot_with_an_used_mac_vm_1',
            cluster=default_cluster,
            template=cirros_template,
        )
        vm_1.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)

        vm_0.stop()
        vm_0.wait_for_down_status()

        snapshot.restore()

        vnic_0 = vm_0.get_vnic(NIC_NAME_1)
        assert vnic_0.mac_address != MAC_ADDR_1
def test_set_mac_pool_duplicate_macs_from_true_to_false_while_dup_exists(
        system, default_cluster, ovirtmgmt_vnic_profile):
    with clusterlib.mac_pool(
        system, default_cluster, MAC_POOL, (MAC_POOL_RANGE,),
        allow_duplicates=True
    ) as mac_pool:
        with virtlib.vm_pool(system, size=2) as (vm_0, vm_1):
            vm_0.create(vm_name=VM0,
                        cluster=default_cluster,
                        template=templatelib.TEMPLATE_BLANK)
            vm_1.create(vm_name=VM1,
                        cluster=default_cluster,
                        template=templatelib.TEMPLATE_BLANK)

            vm_0.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)
            vm_0.wait_for_down_status()

            vm_1.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)
            vm_1.wait_for_down_status()

            with pytest.raises(clusterlib.MacPoolContainsDuplicatesError):
                mac_pool.set_allow_duplicates(False)
def test_move_stateless_vm_mac_to_new_vm_fails(
        system, default_cluster, ovirtmgmt_vnic_profile, cirros_template):

    with virtlib.vm_pool(system, size=2) as (vm_0, vm_1):
        vm_0.create(vm_name=VM0,
                    cluster=default_cluster,
                    template=cirros_template,
                    stateless=True)

        vm_0.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)
        vm_0.wait_for_down_status()

        vm_0.run()
        vm_0.wait_for_up_status()

        _replace_vnic_mac_addr(vm_0, MAC_ADDR_2)

        vm_1.create(vm_name=VM1,
                    cluster=default_cluster,
                    template=cirros_template)

        with pytest.raises(netlib.MacAddrInUseError):
            vm_1.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)
def test_move_mac_to_new_vm(
        system, default_cluster, ovirtmgmt_vnic_profile, cirros_template):

    with virtlib.vm_pool(system, size=2) as (vm_0, vm_1):
        vm_0.create(vm_name=VM0,
                    cluster=default_cluster,
                    template=cirros_template)

        vm_0.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)
        vm_0.wait_for_down_status()

        vm_0.run()
        vm_0.wait_for_up_status()

        _replace_vnic_mac_addr(vm_0, MAC_ADDR_2)

        vm_1.create(vm_name=VM1,
                    cluster=default_cluster,
                    template=cirros_template)

        vm_1.create_vnic(NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)

        vnic_1 = vm_1.get_vnic(NIC_NAME_1)
        assert vnic_1.mac_address == MAC_ADDR_1
Beispiel #30
0
def running_cirros_vm(
    system,
    default_data_center,
    default_cluster,
    default_storage_domain,
    ovirtmgmt_vnic_profile,
    host_0_up,
    host_1_up,
    cirros_template,
):
    with clusterlib.new_assigned_network(NET1, default_data_center,
                                         default_cluster) as net_1:
        attach_data_1 = netattachlib.NetworkAttachmentData(net_1, ETH1)
        with clusterlib.new_assigned_network(NET2, default_data_center,
                                             default_cluster) as net_2:
            attach_data_2 = netattachlib.NetworkAttachmentData(net_2, ETH2)
            with hostlib.setup_networks(host_0_up,
                                        attach_data=(attach_data_1,
                                                     attach_data_2)):
                with hostlib.setup_networks(host_1_up,
                                            attach_data=(attach_data_1,
                                                         attach_data_2)):
                    with virtlib.vm_pool(system, size=1) as (vm, ):
                        vm.create(
                            vm_name=VM_CIRROS,
                            cluster=default_cluster,
                            template=cirros_template,
                        )
                        vm.create_vnic(NIC_NAMES[0], ovirtmgmt_vnic_profile)
                        vm.create_vnic(NIC_NAMES[1], net_1.vnic_profile())
                        vm.create_vnic(NIC_NAMES[2], net_2.vnic_profile())
                        vm.wait_for_down_status()
                        vm.run()
                        vm.wait_for_up_status()
                        joblib.AllJobs(system).wait_for_done()
                        yield vm
def vm_in_ovs_cluster_down(system, ovs_cluster, cirros_template):
    with virtlib.vm_pool(system, size=1) as (vm,):
        vm.create(vm_name=VM0_NAME, cluster=ovs_cluster,
                  template=cirros_template)
        vm.wait_for_down_status()
        yield vm