Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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'
    MAC_POOL_START = '00:00:00:00:00:02'
    MAC_POOL_END = '00:00:00:00:00:15'

    # 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.

    MAC_POOL_RANGES = (clusterlib.MacPoolRange(start=MAC_POOL_START,
                                               end=MAC_POOL_END), )

    default_cluster_mac_pool = clusterlib.mac_pool(system, default_cluster,
                                                   MAC_POOL_0, MAC_POOL_RANGES)
    cluster_0_mac_pool = clusterlib.mac_pool(system, cluster_0, MAC_POOL_1,
                                             MAC_POOL_RANGES)
    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)
            _create_vnic(vm_0, NIC_NAME_1, ovirtmgmt_vnic_profile,
                         MAC_POOL_START)

            vm_1.create(vm_name=VM1,
                        cluster=cluster_0,
                        template=templatelib.TEMPLATE_BLANK)
            with pytest.raises(netlib.MacAddrInUseError):
                _create_vnic(vm_1, NIC_NAME_1, ovirtmgmt_vnic_profile,
                             MAC_POOL_START)
Ejemplo n.º 4
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=fixtures.virt.CIRROS_TEMPLATE_NAME)
        _create_vnic(vm_0, NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)

        with vm_0.wait_for_up_status():
            vm_0.run()

        snapshot = _create_snapshot(vm_0)

        _replace_vnic_mac_addr(vm_0, MAC_ADDR_2)

        vm_1.create(vm_name=VM1,
                    cluster=default_cluster,
                    template=fixtures.virt.CIRROS_TEMPLATE_NAME)
        _create_vnic(vm_1, NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)

        with vm_0.wait_for_down_status():
            vm_0.stop()

        snapshot.restore()

        vnic_0 = vm_0.get_vnic(NIC_NAME_1)
        assert vnic_0.mac_address != MAC_ADDR_1
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_id()

        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
Ejemplo n.º 6
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
Ejemplo n.º 7
0
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_id()

        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
Ejemplo n.º 8
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, 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
                )
Ejemplo n.º 9
0
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
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, 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
Ejemplo n.º 12
0
def vm_0(system, default_cluster, default_storage_domain,
         ovirtmgmt_vnic_profile):
    disk = _create_disk(system)
    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)
        with vm.wait_for_disk_up_status(disk, disk_att_id):
            yield vm
Ejemplo n.º 13
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)
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
Ejemplo n.º 15
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)
Ejemplo n.º 16
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
Ejemplo n.º 17
0
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)
Ejemplo n.º 18
0
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)
Ejemplo n.º 19
0
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=fixtures.virt.CIRROS_TEMPLATE_NAME,
                    stateless=True)

        _create_vnic(vm_0, NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)

        with vm_0.wait_for_up_status():
            vm_0.run()

        _replace_vnic_mac_addr(vm_0, MAC_ADDR_2)

        vm_1.create(vm_name=VM1,
                    cluster=default_cluster,
                    template=fixtures.virt.CIRROS_TEMPLATE_NAME)

        with pytest.raises(netlib.MacAddrInUseError):
            _create_vnic(vm_1, NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)
Ejemplo n.º 20
0
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)
Ejemplo n.º 21
0
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=fixtures.virt.CIRROS_TEMPLATE_NAME)

        _create_vnic(vm_0, NIC_NAME_1, ovirtmgmt_vnic_profile, MAC_ADDR_1)

        with vm_0.wait_for_up_status():
            vm_0.run()

        _replace_vnic_mac_addr(vm_0, MAC_ADDR_2)

        vm_1.create(vm_name=VM1,
                    cluster=default_cluster,
                    template=fixtures.virt.CIRROS_TEMPLATE_NAME)

        _create_vnic(vm_1, 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
Ejemplo n.º 22
0
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
Ejemplo n.º 23
0
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