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})) print('source host: {}'.format(src_host)) print('destination host: {}'.format(dst_host)) assert_finished_within_long(vm_service.migrate, system_service, host=Host(name=dst_host)) # 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] assertions.assert_true_within_short(vm_is_not_on_host) assertions.assert_true_within_short( lambda: vm_service.get().status == VmStatus.UP) assert _current_running_host() == dst_host
def migrate_vm(prefix, api): engine = api.system_service() vm_service = test_utils.get_vm_service(engine, VM0_NAME) vm_id = vm_service.get().id hosts_service = engine.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 = sorted([h.name() for h in prefix.virt_env.host_vms() if h.name() != src_host])[0] print('source host: {}'.format(src_host)) print('destination host: {}'.format(dst_host)) assert_finished_within_long( vm_service.migrate, engine, host=Host(name=dst_host) ) # Verify that VDSM cleaned the vm in the source host def vm_is_not_on_host(): src_host_obj = [ h for h in prefix.virt_env.host_vms() if h.name() == src_host ][0] ret = src_host_obj.ssh(['vdsm-client', 'Host', 'getVMList']) if ret: raise RuntimeError('Failed to call vdsm-client in {}, {}'.format( src_host, ret.err ) ) parsed_output = json.loads(ret.out) return vm_id not in parsed_output testlib.assert_true_within_short(vm_is_not_on_host) testlib.assert_true_within_short( lambda: vm_service.get().status == VmStatus.UP ) nt.assert_equals( _current_running_host(), dst_host )
def vm_migrate(prefix, api): engine = api.system_service() vm_service = test_utils.get_vm_service(engine, VM0_NAME) vm_id = vm_service.get().id hosts_service = engine.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 def _append_domain(hostname): return "{}.{}".format(hostname, DOMAIN_NAME) src_host = _current_running_host() dst_host = sorted([ h.name() for h in prefix.virt_env.host_vms() if _append_domain(h.name()) != src_host ])[0] print('source host: {}'.format(src_host)) print('destination host: {}'.format(dst_host)) assert_finished_within_long(vm_service.migrate, engine, host=Host(name=dst_host)) # Verify that VDSM cleaned the vm in the source host def vm_is_not_on_host(): src_host_obj = [ h for h in prefix.virt_env.host_vms() if _append_domain(h.name()) == src_host ][0] ret = src_host_obj.ssh(['vdsm-client', 'Host', 'getVMList']) if ret: raise RuntimeError('Failed to call vdsm-client in {}, {}'.format( src_host, str(ret.err))) parsed_output = json.loads(ret.out) return vm_id not in parsed_output testlib.assert_true_within_short(vm_is_not_on_host) testlib.assert_true_within_short( lambda: vm_service.get().status == sdk4.types.VmStatus.UP) nt.assert_equals(_current_running_host(), dst_host)