def test_userportal( ovirt_driver, nonadmin_username, nonadmin_password, user_login, engine_webadmin_url, save_screenshot, ): welcome_screen = WelcomeScreen(ovirt_driver) welcome_screen.wait_for_displayed() welcome_screen.open_user_portal() user_login(nonadmin_username, nonadmin_password) vm_portal = VmPortal(ovirt_driver) vm_portal.wait_for_displayed() # using vm0 requires logic from 002 _bootstrap::test_add_vm_permissions_to_user assert assert_utils.equals_within_short(vm_portal.get_vm_count, 1) vm0_status = vm_portal.get_vm_status('vm0') assert vm0_status == 'Powering up' or vm0_status == 'Running' save_screenshot('userportal') vm_portal.logout() save_screenshot('userportal-logout') welcome_screen = WelcomeScreen(ovirt_driver) welcome_screen.wait_for_displayed() assert welcome_screen.is_user_logged_out()
def migrate_vm(all_hosts_hostnames, ansible_by_hostname, system_service): vm_service = test_utils.get_vm_service(system_service, VM0_NAME) vm_id = vm_service.get().id hosts_service = system_service.hosts_service() def _current_running_host(): host_id = vm_service.get().host.id host = hosts_service.list(search='id={}'.format(host_id))[0] return host.name src_host = _current_running_host() dst_host = next(iter(all_hosts_hostnames - {src_host})) LOGGER.debug('source host: {}'.format(src_host)) LOGGER.debug('destination host: {}'.format(dst_host)) correlation_id = uuid.uuid4() vm_service.migrate(host=Host(name=dst_host), query={'correlation_id': correlation_id}) assert assert_utils.true_within_long(lambda: test_utils.all_jobs_finished(system_service, correlation_id)) # Verify that VDSM cleaned the vm in the source host def vm_is_not_on_host(): ansible_src_host = ansible_by_hostname(src_host) out = ansible_src_host.shell('vdsm-client Host getVMList')["stdout"] vms = json.loads(out) return vm_id not in [vm["vmId"] for vm in vms] assert assert_utils.true_within_short(vm_is_not_on_host) assert assert_utils.equals_within_short(lambda: vm_service.get().status, VmStatus.UP) assert _current_running_host() == dst_host
def _remove_iface_from_vm(api, vm_name, iface_name): nics_service = test_utils.get_nics_service(api.system_service(), vm_name) nic = next(nic for nic in nics_service.list() if nic.name == iface_name) nic_service = nics_service.nic_service(nic.id) nic_service.deactivate() assert assert_utils.equals_within_short(lambda: nic_service.get().plugged, False) nic_service.remove()
def remove_vm_root_checkpoint(checkpoints_service): vm_checkpoints = checkpoints_service.list() root_checkpoint = vm_checkpoints[0] checkpoint_service = checkpoints_service.checkpoint_service( id=root_checkpoint.id) checkpoint_service.remove() assert assert_utils.equals_within_short( lambda: len(checkpoints_service.list()), len(vm_checkpoints) - 1)
def test_reattach_storage_domain(engine_api): VnicSetup.vnic_setup().remove_some_profiles_and_networks() engine = engine_api.system_service() dc = test_utils.data_center_service(engine, DC_NAME) sd = test_utils.get_attached_storage_domain(engine, SD_SECOND_NFS_NAME) dc.storage_domains_service().add(sd) assert assert_utils.equals_within_short( lambda: test_utils.get_attached_storage_domain(dc, SD_SECOND_NFS_NAME). status, ovirtsdk4.types.StorageDomainStatus.ACTIVE, )
def test_detach_storage_domain(engine_api): engine = engine_api.system_service() dc = test_utils.data_center_service(engine, DC_NAME) test_utils.get_attached_storage_domain(dc, SD_SECOND_NFS_NAME, service=True).remove() assert assert_utils.equals_within_short( lambda: test_utils.get_attached_storage_domain( engine, SD_SECOND_NFS_NAME).status, ovirtsdk4.types.StorageDomainStatus.UNATTACHED, )
def test_add_blank_vms(engine_api, ost_cluster_name): engine = engine_api.system_service() vms_service = engine.vms_service() vm_params = sdk4.types.Vm( os=sdk4.types.OperatingSystem(type='other_linux', ), type=sdk4.types.VmType.SERVER, high_availability=sdk4.types.HighAvailability(enabled=False, ), cluster=sdk4.types.Cluster(name=ost_cluster_name, ), template=sdk4.types.Template(name=TEMPLATE_BLANK, ), display=sdk4.types.Display( smartcard_enabled=True, keyboard_layout='en-us', file_transfer_enabled=True, copy_paste_enabled=True, ), usb=sdk4.types.Usb( enabled=True, type=sdk4.types.UsbType.NATIVE, ), memory_policy=sdk4.types.MemoryPolicy(ballooning=True, ), ) vm_params.name = BACKUP_VM_NAME vm_params.memory = 96 * MB vm_params.memory_policy.guaranteed = 64 * MB vms_service.add(vm_params) backup_vm_service = test_utils.get_vm_service(engine, BACKUP_VM_NAME) vm_params.name = VM0_NAME least_hotplug_increment = 256 * MB required_memory = 96 * MB vm_params.memory = required_memory vm_params.memory_policy.guaranteed = required_memory vm_params.memory_policy.max = required_memory + least_hotplug_increment vms_service.add(vm_params) vm0_vm_service = test_utils.get_vm_service(engine, VM0_NAME) for vm_service in [backup_vm_service, vm0_vm_service]: assert assert_utils.equals_within_short( lambda: vm_service.get().status, sdk4.types.VmStatus.DOWN)
def test_deactivate_storage_domain(engine_api): # TODO: this also seems to leave running tasks behind which break the deactivation. # TODO: it should be tested in multiple runs or properly waited for. VnicSetup.vnic_setup().init(engine_api.system_service(), VM2_NAME, DC_NAME, CLUSTER_NAME) engine = engine_api.system_service() dc = test_utils.data_center_service(engine_api.system_service(), DC_NAME) correlation_id = 'deactivate_storage_domain' def _deactivate_with_running_ovf_update_task(): try: test_utils.get_attached_storage_domain( dc, SD_SECOND_NFS_NAME, service=True).deactivate( query={'correlation_id': correlation_id}) return True except ovirtsdk4.Error as err: # The storage domain's deactivation may fail if it has running tasks. # In case of updating ovf_store disks task (UploadStream), # ignore. Otherwise, raise the exception. if not (('UploadStream' in err.args[0]) or ('OVF' in err.args[0])): raise return False def _is_deactivation_job_finished(): deactivation_job_statuses = engine_utils.get_jobs_statuses( engine, correlation_id) return (ovirtsdk4.types.JobStatus.FINISHED in deactivation_job_statuses ) and not (ovirtsdk4.types.JobStatus.STARTED in deactivation_job_statuses) assert assert_utils.true_within_short( _deactivate_with_running_ovf_update_task) # Wait for the storage deactivation to be finished. assert assert_utils.true_within_short(_is_deactivation_job_finished) assert assert_utils.equals_within_short( lambda: test_utils.get_attached_storage_domain(dc, SD_SECOND_NFS_NAME). status, ovirtsdk4.types.StorageDomainStatus.MAINTENANCE, )