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 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)
Exemplo n.º 3
0
def setup_virtual_machines(engine_api):
    vm_service = test_utils.get_vm_service(engine_api.system_service(), 'vm0')
    if vm_service.get().status == types.VmStatus.DOWN:
        vm_service.start()
        assert assert_utils.equals_within_long(lambda: vm_service.get().status,
                                               types.VmStatus.POWERING_UP)
Exemplo n.º 4
0
def get_nics_on(engine, vm_name):
    return test_utils.get_vm_service(engine, vm_name).nics_service().list()
Exemplo n.º 5
0
def create_nics_on_vm(engine, vm_name, profiles):
    vm2_service = test_utils.get_vm_service(engine, vm_name)
    _add_nics(vm2_service, profiles)