Esempio n. 1
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='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()
        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
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
0
def networks(system, default_data_center, default_cluster):
    vm_net_ctx = clusterlib.new_assigned_network(VM_NET_NAME, default_data_center, default_cluster)

    vm_vlan_10_net_ctx = clusterlib.new_assigned_network(
        VLAN_10_NET_NAME, default_data_center, default_cluster, vlan=10
    )

    vm_vlan_20_net_ctx = clusterlib.new_assigned_network(
        VLAN_20_NET_NAME, default_data_center, default_cluster, vlan=20
    )

    vm_vlan_30_net_ctx = clusterlib.new_assigned_network(
        VLAN_30_NET_NAME, default_data_center, default_cluster, vlan=30
    )

    vm_vlan_30_net_1_ctx = clusterlib.new_assigned_network(
        VLAN_30_NET_NAME_1, default_data_center, default_cluster, vlan=30
    )

    joblib.AllJobs(system).wait_for_done()
    with (
        vm_net_ctx as vm_network,
        vm_vlan_10_net_ctx as vm_vlan_10_network,
        vm_vlan_20_net_ctx as vm_vlan_20_network,
        vm_vlan_30_net_ctx as vm_vlan_30_network,
        vm_vlan_30_net_1_ctx as vm_vlan_30_network_1,
    ):
        yield {
            VM_NET_NAME: vm_network,
            VLAN_10_NET_NAME: vm_vlan_10_network,
            VLAN_20_NET_NAME: vm_vlan_20_network,
            VLAN_30_NET_NAME: vm_vlan_30_network,
            VLAN_30_NET_NAME_1: vm_vlan_30_network_1,
        }
Esempio n. 5
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='test_undo_preview_snapshot_when_mac_used_vm_0',
                    cluster=default_cluster,
                    template=cirros_template)
        vm_0.wait_for_down_status()

        vm_0.run()
        vm_0.wait_for_up_status()
        joblib.AllJobs(system).wait_for_done()
        nicless_snapshot = vm_0.create_snapshot(SNAPSHOT_DESC)

        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='test_undo_preview_snapshot_when_mac_used_vm_1',
                    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
Esempio n. 6
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='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)
Esempio n. 7
0
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
def test_run_vm_with_unrestricted_display_network_name(
        system, vm_0_with_display_network_and_disk):
    vm_0_with_display_network_and_disk.run()
    vm_0_with_display_network_and_disk.wait_for_up_status()
    joblib.AllJobs(system).wait_for_done()
    vm_0_with_display_network_and_disk.stop()
    vm_0_with_display_network_and_disk.wait_for_down_status()
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
def vm_in_ovn_network_up(
    system, vm_in_ovs_cluster_down, cirros_serial_console, vnic_attached_to_ovn_network, target, af
):
    vm_in_ovs_cluster_down.run_once(cloud_init_hostname=VM0_NAME)
    vm_in_ovs_cluster_down.wait_for_up_status()
    joblib.AllJobs(system).wait_for_done()
    if af.is6:
        cirros_serial_console.add_static_ip(vm_in_ovs_cluster_down.id, f'{target}/64', 'eth0')
    yield vm_in_ovs_cluster_down
Esempio n. 11
0
def vm_pool(system, size):
    pool = [Vm(system) for _ in range(size)]
    try:
        yield pool
    finally:
        for vm in pool[::-1]:
            if vm.service is None:
                continue
            vm.remove()
        joblib.AllJobs(system).wait_for_done()
Esempio n. 12
0
 def activate(self):
     syncutil.sync(exec_func=self._service.activate,
                   exec_func_args=(),
                   success_criteria=lambda s: self.is_up,
                   error_criteria=lambda e: error.is_not_ovirt_or_unlisted(
                       e, [
                           'Related operation is currently in progress',
                           'Cannot activate Host. Host in Up status',
                       ]),
                   timeout=3 * 60)
     joblib.AllJobs(self.system).wait_for_done()
Esempio n. 13
0
 def deactivate(self):
     syncutil.sync(exec_func=self._service.deactivate,
                   exec_func_args=(),
                   timeout=3 * 60,
                   success_criteria=lambda s: self.is_in_maintenance,
                   error_criteria=lambda e: error.is_not_ovirt_or_unlisted(
                       e, [
                           'Host has asynchronous running tasks',
                           'Host is contending',
                           'Host is already in Maintenance mode',
                       ]))
     joblib.AllJobs(self.system).wait_for_done()
Esempio n. 14
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()
        joblib.AllJobs(system).wait_for_done()
        yield vm
Esempio n. 15
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
Esempio n. 16
0
 def hand_over_spm(self, candidate_spm):
     if self.is_spm and candidate_spm.is_up:
         candidate_spm.force_select_spm()
         joblib.AllJobs(self.system).wait_for_done()
Esempio n. 17
0
def vm_in_ovn_network_up(system, vm_in_ovs_cluster_down,
                         vnic_attached_to_ovn_network):
    vm_in_ovs_cluster_down.run_once(cloud_init_hostname=VM0_NAME)
    vm_in_ovs_cluster_down.wait_for_up_status()
    joblib.AllJobs(system).wait_for_done()
    yield vm_in_ovs_cluster_down