def test_remove_vm_pool(api_v4): engine = api_v4.system_service() pool_service = test_utils.get_pool_service(engine, VMPOOL_NAME) correlation_id = uuid.uuid4() with test_utils.TestEvent(engine, [321, 304]): # USER_REMOVE_VM_POOL_INITIATED(321) event # USER_REMOVE_VM_POOL(304) event pool_service.remove(query={'correlation_id': correlation_id}) vm_pools_service = api_v4.system_service().vm_pools_service() assert len(vm_pools_service.list()) == 0 testlib.assert_true_within_long( lambda: test_utils.all_jobs_finished(engine, correlation_id))
def test_live_storage_migration(api_v4): pytest.skip("TODO: el8 fails all the time") engine = api_v4.system_service() disk_service = test_utils.get_disk_service(engine, DISK0_NAME) correlation_id = 'live_storage_migration' disk_service.move(async=False, filter=False, storage_domain=types.StorageDomain(name=SD_ISCSI_NAME), query={'correlation_id': correlation_id}) testlib.assert_true_within_long( lambda: test_utils.all_jobs_finished(engine, correlation_id)) # Assert that the disk is on the correct storage domain, # its status is OK and the snapshot created for the migration # has been merged testlib.assert_true_within_long(lambda: api_v4.follow_link( disk_service.get().storage_domains[0]).name == SD_ISCSI_NAME) vm0_snapshots_service = test_utils.get_vm_snapshots_service( engine, VM0_NAME) testlib.assert_true_within_long( lambda: len(vm0_snapshots_service.list()) == 1) testlib.assert_true_within_long( lambda: disk_service.get().status == types.DiskStatus.OK)
def test_hotplug_disk(prefix): api_v4 = prefix.virt_env.engine_vm().get_api_v4() engine = api_v4.system_service() disk_attachments_service = test_utils.get_disk_attachments_service( engine, VM0_NAME) disk_attachment = disk_attachments_service.add( types.DiskAttachment(disk=types.Disk( name=DISK0_NAME, provisioned_size=2 * GB, format=types.DiskFormat.COW, storage_domains=[ types.StorageDomain(name=SD_NFS_NAME, ), ], status=None, sparse=True, ), interface=types.DiskInterface.VIRTIO, bootable=False, active=True)) disks_service = engine.disks_service() disk_service = disks_service.disk_service(disk_attachment.disk.id) attachment_service = disk_attachments_service.attachment_service( disk_attachment.id) testlib.assert_true_within_short( lambda: attachment_service.get().active == True) testlib.assert_true_within_short( lambda: disk_service.get().status == types.DiskStatus.OK) assert_vm0_is_alive(prefix)
def test_add_snapshot_for_backup(api_v4): engine = api_v4.system_service() vm2_disk_attachments_service = test_utils.get_disk_attachments_service( engine, VM2_NAME) disk = vm2_disk_attachments_service.list()[0] backup_snapshot_params = types.Snapshot( description=SNAPSHOT_FOR_BACKUP_VM, persist_memorystate=False, disk_attachments=[types.DiskAttachment(disk=types.Disk(id=disk.id))]) vm2_snapshots_service = test_utils.get_vm_snapshots_service( engine, VM2_NAME) correlation_id = uuid.uuid4() with test_utils.TestEvent(engine, [45, 68]): # USER_CREATE_SNAPSHOT(41) event # USER_CREATE_SNAPSHOT_FINISHED_SUCCESS(68) event vm2_snapshots_service.add(backup_snapshot_params, query={'correlation_id': correlation_id}) testlib.assert_true_within_long( lambda: test_utils.all_jobs_finished(engine, correlation_id)) testlib.assert_true_within_long( lambda: vm2_snapshots_service.list()[-1].snapshot_status == types. SnapshotStatus.OK, )
def test_verify_backup_snapshot_removed(api_v4): engine = api_v4.system_service() vm2_snapshots_service = test_utils.get_vm_snapshots_service( engine, VM2_NAME) testlib.assert_true_within_long( lambda: len(vm2_snapshots_service.list()) == 1)
def test_add_labeled_network(api_v4): """ Creates a labeled network """ # create network labeled_net = Network( name=LABELED_NET_NAME, data_center=DataCenter( name=DC_NAME, ), description='Labeled network on VLAN {}'.format(LABELED_NET_VLAN_ID), usages=[], # because only one non-VLAN network, here 'ovirtmgmt', can be assigned # to each nic, this additional network has to be a VLAN network # NOTE: we have added three more NICs since creating this test vlan=Vlan( id=LABELED_NET_VLAN_ID, ), ) networks_service = api_v4.system_service().networks_service() net = networks_service.add(labeled_net) assert net network_service = networks_service.network_service(id=net.id) labels_service = network_service.network_labels_service() # assign label to the network assert labels_service.add( NetworkLabel( id=NETWORK_LABEL ) ) labels = [l for l in labels_service.list() if l.id == NETWORK_LABEL] assert len(labels) == 1
def test_assign_hosts_network_label(api_v4): """ Assigns NETWORK_LABEL to first network interface of every host in cluster """ engine = api_v4.system_service() def _assign_host_network_label(host): host_service = engine.hosts_service().host_service(id=host.id) nics_service = host_service.nics_service() nics = sorted(nics_service.list(), key=lambda n: n.name) assert len(nics) >= 1 nic = nics[0] nic_service = nics_service.nic_service(id=nic.id) labels_service = nic_service.network_labels_service() return labels_service.add( NetworkLabel( id=NETWORK_LABEL, host_nic=nic ) ) hosts = test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME) vec = utils.func_vector(_assign_host_network_label, [(h,) for h in hosts]) vt = utils.VectorThread(vec) vt.start_all() assert all(vt.join_all())
def test_remove_vm2_lease(api_v4): engine = api_v4.system_service() vm2_service = test_utils.get_vm_service(engine, VM2_NAME) vm2_service.update( vm=types.Vm(high_availability=types.HighAvailability(enabled=False, ), lease=types.StorageDomainLease(storage_domain=None))) testlib.assert_true_within_short(lambda: vm2_service.get().lease is None)
def test_check_snapshot_with_memory(api_v4): engine = api_v4.system_service() vm_service = test_utils.get_vm_service(engine, VM0_NAME) testlib.assert_true_within_long( lambda: test_utils.get_snapshot(engine, VM0_NAME, SNAPSHOT_DESC_MEM). snapshot_status == types.SnapshotStatus.IN_PREVIEW) vm_service.start() _verify_vm_state(engine, VM0_NAME, types.VmStatus.UP)
def test_sparsify_disk1(api_v4): engine = api_v4.system_service() disk_service = test_utils.get_disk_service(engine, DISK1_NAME) with test_utils.TestEvent(engine, 1325): # USER_SPARSIFY_IMAGE_START event disk_service.sparsify() testlib.assert_true_within_short( lambda: disk_service.get().status == types.DiskStatus.OK)
def test_verify_vm_import(api_v4): engine = api_v4.system_service() vm_service = _verify_vm_state(engine, IMPORTED_VM_NAME, types.VmStatus.DOWN) # Remove the imported VM num_of_vms = len(engine.vms_service().list()) vm_service.remove() assert len(engine.vms_service().list()) == (num_of_vms - 1)
def test_hotplug_memory(prefix): api_v4 = prefix.virt_env.engine_vm().get_api_v4() engine = api_v4.system_service() vm_service = test_utils.get_vm_service(engine, VM0_NAME) new_memory = vm_service.get().memory + 256 * MB with test_utils.TestEvent(engine, 2039): # HOT_SET_MEMORY(2,039) vm_service.update(vm=types.Vm(memory=new_memory)) assert vm_service.get().memory == new_memory assert_vm0_is_alive(prefix)
def test_hotplug_nic(prefix): pytest.skip('https://bugzilla.redhat.com/1776317') api_v4 = prefix.virt_env.engine_vm().get_api_v4() vms_service = api_v4.system_service().vms_service() vm = vms_service.list(search='name=%s' % VM0_NAME)[0] nics_service = vms_service.vm_service(vm.id).nics_service() nics_service.add( types.Nic(name='eth1', interface=types.NicInterface.VIRTIO), ) assert_vm0_is_alive(prefix)
def prepare_migration_vlan(api_v4): engine = api_v4.system_service() assert network_utils_v4.set_network_usages_in_cluster( engine, MIGRATION_NETWORK, CLUSTER_NAME, [NetworkUsage.MIGRATION]) # Set Migration_Network's MTU to match the other VLAN's on the NIC. assert network_utils_v4.set_network_mtu(engine, MIGRATION_NETWORK, DC_NAME, DEFAULT_MTU)
def test_update_vm_pool(api_v4): engine = api_v4.system_service() pool_service = test_utils.get_pool_service(engine, VMPOOL_NAME) correlation_id = uuid.uuid4() pool_service.update(pool=types.VmPool(max_user_vms=2), query={'correlation_id': correlation_id}) assert pool_service.get().max_user_vms == 2 testlib.assert_true_within_long( lambda: test_utils.all_jobs_finished(engine, correlation_id))
def test_modify_host_0_ip_to_dhcp(api_v4): engine = api_v4.system_service() host = test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME)[0] host_service = engine.hosts_service().host_service(id=host.id) ip_configuration = network_utils_v4.create_dhcp_ip_configuration() network_utils_v4.modify_ip_config(engine, host_service, VM_NETWORK, ip_configuration)
def test_verify_vm1_exported(api_v4): engine = api_v4.system_service() _verify_vm_state(engine, VM1_NAME, types.VmStatus.DOWN) storage_domain_service = test_utils.get_storage_domain_service( engine, SD_TEMPLATES_NAME) vm_sd_service = test_utils.get_storage_domain_vm_service_by_name( storage_domain_service, VM1_NAME) testlib.assert_true_within_short( lambda: vm_sd_service.get().status == types.VmStatus.DOWN)
def test_verify_add_vm1_from_template(api_v4): engine = api_v4.system_service() _verify_vm_state(engine, VM1_NAME, types.VmStatus.DOWN) disks_service = engine.disks_service() vm1_disk_attachments_service = test_utils.get_disk_attachments_service( engine, VM1_NAME) for disk_attachment in vm1_disk_attachments_service.list(): disk_service = disks_service.disk_service(disk_attachment.disk.id) testlib.assert_true_within_short( lambda: disk_service.get().status == types.DiskStatus.OK)
def test_detach_vm_network_from_host_0(api_v4): engine = api_v4.system_service() host = test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME)[0] host_service = engine.hosts_service().host_service(id=host.id) network_utils_v4.set_network_required_in_cluster(engine, VM_NETWORK, CLUSTER_NAME, False) network_utils_v4.detach_network_from_host(engine, host_service, VM_NETWORK) assert not _host_is_attached_to_network(engine, host_service, VM_NETWORK)
def test_export_vm1(api_v4): engine = api_v4.system_service() vm_service = test_utils.get_vm_service(engine, VM1_NAME) sd = engine.storage_domains_service().list( search='name={}'.format(SD_TEMPLATES_NAME))[0] with test_utils.TestEvent(engine, 1162): # IMPORTEXPORT_STARTING_EXPORT_VM event vm_service.export(storage_domain=types.StorageDomain(id=sd.id, ), discard_snapshots=True, async=True)
def test_add_ldap_user(api_v4): engine = api_v4.system_service() users_service = engine.users_service() with test_utils.TestEvent(engine, 149): # USER_ADD(149) users_service.add( types.User( user_name=AAA_LDAP_USER, domain=types.Domain( name=AAA_LDAP_AUTHZ_PROVIDER ), ), )
def test_template_update(api_v4): template_guest = test_utils.get_template_service(api_v4.system_service(), TEMPLATE_GUEST) if template_guest is None: pytest.skip('{0}: template {1} is missing'.format( template_update.__name__, TEMPLATE_GUEST)) new_comment = "comment by ovirt-system-tests" template_guest.update(template=types.Template(comment=new_comment)) testlib.assert_true_within_short( lambda: template_guest.get().status == types.TemplateStatus.OK) assert template_guest.get().comment == new_comment
def test_add_ldap_group(api_v4): engine = api_v4.system_service() groups_service = engine.groups_service() with test_utils.TestEvent(engine, 149): # USER_ADD(149) groups_service.add( types.Group( name=AAA_LDAP_GROUP, domain=types.Domain( name=AAA_LDAP_AUTHZ_PROVIDER ), ), )
def test_hotplug_cpu(prefix): api_v4 = prefix.virt_env.engine_vm().get_api_v4() engine = api_v4.system_service() vm_service = test_utils.get_vm_service(engine, VM0_NAME) new_cpu = vm_service.get().cpu new_cpu.topology.sockets = 2 with test_utils.TestEvent(engine, 2033): # HOT_SET_NUMBER_OF_CPUS(2,033) vm_service.update(vm=types.Vm(cpu=new_cpu)) assert vm_service.get().cpu.topology.sockets == 2 ret = _vm_ssh(test_utils.get_vm0_ip_address(prefix), ['lscpu']) assert ret.code == 0 match = re.search(r'CPU\(s\):\s+(?P<cpus>[0-9]+)', ret.out.decode('utf-8')) assert match.group('cpus') == '2'
def test_preview_snapshot_with_memory(api_v4): engine = api_v4.system_service() events = engine.events_service() testlib.assert_true_within_long( # wait for event 68 == USER_CREATE_SNAPSHOT_FINISHED_SUCCESS lambda: any(e.code == 68 for e in events.list(max=6))) vm_service = test_utils.get_vm_service(engine, VM0_NAME) vm_service.stop() _verify_vm_state(engine, VM0_NAME, types.VmStatus.DOWN) snapshot = test_utils.get_snapshot(engine, VM0_NAME, SNAPSHOT_DESC_MEM) vm_service.preview_snapshot(snapshot=snapshot, async=False, restore_memory=True)
def test_add_disks(api_v4): engine = api_v4.system_service() vm_service = test_utils.get_vm_service(engine, VM0_NAME) glance_disk = test_utils.get_disk_service(engine, GLANCE_DISK_NAME) assert vm_service and glance_disk vm0_disk_attachments_service = test_utils.get_disk_attachments_service( engine, VM0_NAME) vm0_disk_attachments_service.add( types.DiskAttachment( disk=types.Disk( id=glance_disk.get().id, storage_domains=[ types.StorageDomain(name=SD_ISCSI_NAME, ), ], ), interface=types.DiskInterface.VIRTIO, active=True, bootable=True, ), ) disk_params = types.Disk( provisioned_size=1 * GB, format=types.DiskFormat.COW, status=None, sparse=True, active=True, bootable=True, ) for vm_name, disk_name, sd_name in ((VM1_NAME, DISK1_NAME, SD_NFS_NAME), (VM2_NAME, DISK2_NAME, SD_SECOND_NFS_NAME), (BACKUP_VM_NAME, BACKUP_DISK_NAME, SD_NFS_NAME)): disk_params.name = disk_name disk_params.storage_domains = [types.StorageDomain(name=sd_name, )] disk_attachments_service = test_utils.get_disk_attachments_service( engine, vm_name) assert disk_attachments_service.add( types.DiskAttachment(disk=disk_params, interface=types.DiskInterface.VIRTIO)) for disk_name in (GLANCE_DISK_NAME, DISK1_NAME, DISK2_NAME, BACKUP_DISK_NAME): disk_service = test_utils.get_disk_service(engine, disk_name) testlib.assert_true_within_short( lambda: disk_service.get().status == types.DiskStatus.OK)
def test_next_run_unplug_cpu(api_v4): engine = api_v4.system_service() vm_service = test_utils.get_vm_service(engine, VM0_NAME) new_cpu = vm_service.get().cpu new_cpu.topology.sockets = 1 vm_service.update(vm=types.Vm(cpu=new_cpu, ), next_run=True) assert vm_service.get().cpu.topology.sockets == 2 assert vm_service.get(next_run=True).cpu.topology.sockets == 1 with test_utils.TestEvent(engine, 157): # USER_REBOOT_VM(157) vm_service.reboot() testlib.assert_true_within_long( lambda: vm_service.get().status == types.VmStatus.UP) assert vm_service.get().cpu.topology.sockets == 1
def test_hotunplug_disk(api_v4): engine = api_v4.system_service() disk_service = test_utils.get_disk_service(engine, DISK0_NAME) disk_attachments_service = test_utils.get_disk_attachments_service( engine, VM0_NAME) disk_attachment = disk_attachments_service.attachment_service( disk_service.get().id) with test_utils.TestEvent(engine, 2002): # USER_HOTUNPLUG_DISK(2,002) assert disk_attachment.update(types.DiskAttachment(active=False)) testlib.assert_true_within_short( lambda: disk_attachment.get().active == False)
def test_use_ovn_provider(prefix, api_v4): engine = api_v4.system_service() engine_ip = prefix.virt_env.engine_vm().ip() provider_id = network_utils_v4.get_default_ovn_provider_id(engine) token_id = _get_auth_token(engine_ip) _validate_db_empty(token_id, engine_ip) with _disable_auto_sync(api_v4, provider_id): network1_id = _add_network( token_id, engine_ip, NETWORK_1, ) subnet1_id = _add_subnet( token_id, engine_ip, SUBNET_1, network1_id, ) port1_id = _add_port( token_id, engine_ip, PORT_1, network1_id, ) _validate_network(token_id, engine_ip, NETWORK_1, network1_id) _validate_port(token_id, engine_ip, PORT_1, port1_id, network1_id) _validate_subnet(token_id, engine_ip, SUBNET_1, subnet1_id, network1_id) datacenter_id = _get_datacenter_id(api_v4) _import_network_to_ovirt(api_v4, provider_id, network1_id, datacenter_id) _validate_vnic_profile(api_v4, NETWORK_1) ovirt_network_id = _get_ovirt_network(api_v4, datacenter_id, NETWORK_1) _add_network_to_cluster(api_v4, datacenter_id, ovirt_network_id) _hotplug_network_to_vm(api_v4, VM0_NAME, NETWORK_1, IFACE_NAME) _remove_iface_from_vm(api_v4, VM0_NAME, IFACE_NAME) _remove_network_from_ovirt(api_v4, datacenter_id, ovirt_network_id) _delete_port(token_id, engine_ip, port1_id) _delete_subnet(token_id, engine_ip, subnet1_id) _delete_network(token_id, engine_ip, network1_id) _validate_db_empty(token_id, engine_ip)
def test_reconstruct_master_domain(api_v4): pytest.skip('TODO:Handle case where tasks are running') system_service = api_v4.system_service() dc_service = test_utils.data_center_service(system_service, DC_NAME) attached_sds_service = dc_service.storage_domains_service() master_sd = next(sd for sd in attached_sds_service.list() if sd.master) attached_sd_service = attached_sds_service.storage_domain_service( master_sd.id) attached_sd_service.deactivate() testlib.assert_true_within_long(lambda: attached_sd_service.get().status == types.StorageDomainStatus.MAINTENANCE) new_master_sd = next(sd for sd in attached_sds_service.list() if sd.master) assert new_master_sd.id != master_sd.id attached_sd_service.activate() testlib.assert_true_within_long(lambda: attached_sd_service.get().status == types.StorageDomainStatus.ACTIVE)