示例#1
0
def test_run_vms(assert_vm_is_alive, engine_api, management_gw_ip):
    engine = engine_api.system_service()

    vm_params = types.Vm(initialization=types.Initialization(
        user_name=VM_USER_NAME, root_password=VM_PASSWORD))

    vm_params.initialization.host_name = BACKUP_VM_NAME
    backup_vm_service = test_utils.get_vm_service(engine, BACKUP_VM_NAME)
    backup_vm_service.start(use_cloud_init=True, vm=vm_params)

    vm_params.initialization.host_name = VM2_NAME
    vm2_service = test_utils.get_vm_service(engine, VM2_NAME)
    vm2_service.start(use_cloud_init=True, vm=vm_params)

    # CirrOS cloud-init is different, networking doesn't work since it doesn't support the format oVirt is using
    vm_params.initialization.host_name = VM0_NAME  # hostname seems to work, the others not
    vm_params.initialization.dns_search = 'lago.local'
    vm_params.initialization.domain = 'lago.local'
    vm_params.initialization.dns_servers = management_gw_ip
    vm0_service = test_utils.get_vm_service(engine, VM0_NAME)
    vm0_service.start(use_cloud_init=True, vm=vm_params)

    for vm_name in [VM0_NAME, BACKUP_VM_NAME]:
        _verify_vm_state(engine, vm_name, types.VmStatus.UP)

    assert_vm_is_alive(VM0_NAME)
def ovf_import(api):
    # Read the OVF file and replace the disk id
    engine = api.system_service()
    disk_service = test_utils.get_disk_service(engine, DISK0_NAME)
    disk_id = disk_service.get().id
    ovf_file = os.path.join(os.environ['SUITE'], 'files', 'test-vm.ovf')
    ovf_text = open(ovf_file).read()
    ovf_text = ovf_text.replace(
        "ovf:diskId='52df5324-2230-40d9-9d3d-8cbb2aa33ba6'",
        "ovf:diskId='%s'" % (disk_id,)
    )
    # Upload OVF
    vms_service = engine.vms_service()
    vms_service.add(
        types.Vm(
            name=OVF_VM_NAME,
            cluster=types.Cluster(
                name=TEST_CLUSTER,
            ),
            initialization=types.Initialization(
                configuration=types.Configuration(
                    type=types.ConfigurationType.OVA,
                    data=ovf_text
                )
            )
        )
    )
    # Check the VM exists
    nt.assert_true(test_utils.get_vm_service(engine, OVF_VM_NAME) is not None)
def migrate_vm(prefix, api):
    engine = api.system_service()
    vm_service = test_utils.get_vm_service(engine, VM0_NAME)
    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]

    # migrate() currently only returns None, but checks for errors internally
    vm_service.migrate(
        host=Host(
            name=dst_host
        )
    )

    testlib.assert_true_within_short(
        lambda: vm_service.get().status == VmStatus.UP
    )

    nt.assert_equals(
        _current_running_host(), dst_host
    )
示例#4
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()
        assertions.assert_true_within_long(
            lambda: vm_service.get().status == types.VmStatus.POWERING_UP
        )
def hotplug_memory(api):
    engine = api.system_service()
    vm_service = test_utils.get_vm_service(engine, VM0_NAME)
    new_memory = vm_service.get().memory * 2
    with test_utils.TestEvent(engine, 2039):  # HOT_SET_MEMORY(2,039)
        vm_service.update(vm=types.Vm(memory=new_memory))
        nt.assert_true(vm_service.get().memory == new_memory)
示例#6
0
def hotplug_memory(api):
    engine = api.system_service()
    vms_service = engine.vms_service()
    vm_service = test_utils.get_vm_service(engine, VM0_NAME)
    new_memory = vm_service.get().memory * 2
    vm_service.update(vm=types.Vm(memory=new_memory))
    nt.assert_true(vm_service.get().memory == new_memory)
def next_run_unplug_cpu(api):
    engine = api.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
    )
    nt.assert_true(
        vm_service.get().cpu.topology.sockets == 2
    )
    nt.assert_true(
        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
        )
    nt.assert_true(
        vm_service.get().cpu.topology.sockets == 1
    )
def add_vm_blank(api):
    engine = api.system_service()
    vms_service = engine.vms_service()

    vm_memory = 512 * MB
    vm_params = sdk4.types.Vm(
        name=VM0_NAME,
        memory=vm_memory,
        os=sdk4.types.OperatingSystem(type='rhel_7x64', ),
        type=sdk4.types.VmType.SERVER,
        high_availability=sdk4.types.HighAvailability(enabled=False, ),
        cluster=sdk4.types.Cluster(name=TEST_CLUSTER, ),
        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,
                                   type=sdk4.types.DisplayType.SPICE),
        usb=sdk4.types.Usb(
            enabled=True,
            type=sdk4.types.UsbType.NATIVE,
        ),
        memory_policy=sdk4.types.MemoryPolicy(
            ballooning=True,
            guaranteed=vm_memory // 2,
        ),
    )

    vms_service.add(vm_params)
    vm0_vm_service = test_utils.get_vm_service(engine, VM0_NAME)
    testlib.assert_true_within_short(
        lambda: vm0_vm_service.get().status == sdk4.types.VmStatus.DOWN)
示例#9
0
def test_incremental_backup_vm2(engine_api):
    engine = engine_api.system_service()
    disks_service = engine.disks_service()
    disk2 = disks_service.list(search='name={}'.format(DISK2_NAME))[0]
    vm2_backups_service = test_utils.get_vm_service(
        engine, VM2_NAME).backups_service()
    created_checkpoint_id = None

    # The first iteration will be a full VM backup (from_checkpoint_id=None)
    # and the second iteration will be an incremental VM backup.
    for _ in range(2):
        correlation_id = 'test_incremental_backup'
        backup = vm2_backups_service.add(
            types.Backup(disks=[types.Disk(id=disk2.id)],
                         from_checkpoint_id=created_checkpoint_id),
            query={'correlation_id': correlation_id})

        backup_service = vm2_backups_service.backup_service(backup.id)
        assertions.assert_true_within_long(
            lambda: backup_service.get().phase == types.BackupPhase.READY,
            allowed_exceptions=[sdk4.NotFoundError])

        backup = backup_service.get()
        created_checkpoint_id = backup.to_checkpoint_id

        backup_service.finalize()

        assertions.assert_true_within_long(
            lambda: len(vm2_backups_service.list()) == 0)
        assertions.assert_true_within_long(lambda: disks_service.disk_service(
            disk2.id).get().status == types.DiskStatus.OK)
def local_maintenance(prefix, api):
    logging.info("Waiting For System Stability...")
    time.sleep(wait_value)

    engine = api.system_service()
    vm_service = test_utils.get_vm_service(engine, VM_HE_NAME)
    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

    he_host = _current_running_host()

    host_service = hosts_service.host_service(id=he_host.id)

    prev_host_id = he_host.id

    logging.info("Performing Deactivation...")

    host_service.deactivate()

    testlib.assert_true_within_long(
        lambda: host_service.get().status == types.HostStatus.MAINTENANCE or
        host_service.get(all_content=True).hosted_engine.local_maintenance
    )

    logging.info("Performing Activation...")

    host_service.activate()

    testlib.assert_true_within_long(
        lambda: host_service.get().status == types.HostStatus.UNASSIGNED
    )

    logging.info("Waiting For System Stability...")

    time.sleep(wait_value)

    logging.info("Waiting For Maintenance...")

    testlib.assert_true_within_long(
        lambda: not host_service.get(all_content=True).hosted_engine.local_maintenance
    )

    logging.info("Waiting For Score...")

    testlib.assert_true_within_long(
        lambda: host_service.get(all_content=True).hosted_engine.score > 0
    )

    logging.info("Validating Migration...")

    he_host = _current_running_host()

    testlib.assert_true_within_short(
        lambda: prev_host_id != he_host.id
    )
def _verify_vm_state(engine, vm_name, state):
    vm_service = test_utils.get_vm_service(engine, vm_name)
    testlib.assert_true_within_long(
        lambda:
        vm_service.get().status == state
    )
    return vm_service
示例#12
0
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 add_disk(api):
    engine = api.system_service()
    vm0_service = test_utils.get_vm_service(engine, VM0_NAME)
    glance_disk = test_utils.get_disk_service(engine, GLANCE_DISK_NAME)

    nt.assert_true(vm0_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_NFS_NAME, ),
                ],
            ),
            interface=types.DiskInterface.VIRTIO,
            active=True,
            bootable=True,
        ), )

    disk_service = test_utils.get_disk_service(engine, GLANCE_DISK_NAME)

    testlib.assert_true_within_short(
        lambda: disk_service.get().status == types.DiskStatus.OK)
示例#14
0
def add_disk(api):
    engine = api.system_service()
    vm0_service = test_utils.get_vm_service(engine, VM0_NAME)
    vm0_disk_attachments_service = test_utils.get_disk_attachments_service(
        engine, VM0_NAME)

    vm0_disk_attachments_service.add(
        types.DiskAttachment(
            disk=types.Disk(
                name=DISK0_NAME,
                format=types.DiskFormat.COW,
                initial_size=10 * GB,
                provisioned_size=1,
                sparse=True,
                storage_domains=[
                    types.StorageDomain(name=MASTER_SD_NAME, ),
                ],
            ),
            interface=types.DiskInterface.VIRTIO,
            active=True,
            bootable=True,
        ), )

    disk0_service = test_utils.get_disk_service(engine, DISK0_NAME)
    disk0_attachment_service = vm0_disk_attachments_service.attachment_service(
        disk0_service.get().id)

    testlib.assert_true_within_long(
        lambda: disk0_attachment_service.get().active == True)
    testlib.assert_true_within_long(
        lambda: disk0_service.get().status == types.DiskStatus.OK)
示例#15
0
def hotplug_disk(api):
    vm_service = test_utils.get_vm_service(api.system_service(), VM0_NAME)
    disk_attachments_service = vm_service.disk_attachments_service()
    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 = api.system_service().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 and disk_service.get().status == types.DiskStatus.OK)
示例#16
0
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)
示例#17
0
def export_vm(api):
    engine = api.system_service()
    vm_service = test_utils.get_vm_service(engine, VM1_NAME)
    sd = engine.storage_domains_service().list(search=SD_TEMPLATES_NAME)[0]

    vm_service.export(storage_domain=types.StorageDomain(id=sd.id, ),
                      discard_snapshots=True,
                      async=True)
示例#18
0
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)
示例#19
0
def hotplug_cpu(api):
    engine = api.system_service()
    vms_service = engine.vms_service()
    vm_service = test_utils.get_vm_service(engine, VM0_NAME)
    new_cpu = vm_service.get().cpu
    new_cpu.topology.sockets = 2
    vm_service.update(vm=types.Vm(cpu=new_cpu))
    nt.assert_true(vm_service.get().cpu.topology.sockets == 2)
def add_disks(api):
    engine = api.system_service()
    vm_service = test_utils.get_vm_service(engine, VM0_NAME)
    glance_disk = test_utils.get_disk_service(engine, GLANCE_DISK_NAME)
    nt.assert_true(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)
        nt.assert_true(
            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
        )
示例#21
0
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 check_snapshot_with_memory(api):
    engine = api.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 verify_vm_import(api):
    engine = api.system_service()
    vm_service = test_utils.get_vm_service(engine, IMPORTED_VM_NAME)
    testlib.assert_true_within_short(
        lambda: vm_service.get().status == types.VmStatus.DOWN)

    # Remove the imported VM
    num_of_vms = len(engine.vms_service().list())
    vm_service.remove()
    nt.assert_true(len(engine.vms_service().list()) == (num_of_vms - 1))
示例#24
0
def add_disk(api):
    engine = api.system_service()
    vm_service = test_utils.get_vm_service(engine, VM0_NAME)
    glance_disk = test_utils.get_disk_service(engine, GLANCE_DISK_NAME)
    nt.assert_true(vm_service and glance_disk)

    vm_service.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)):
        disk_params.name = disk_name
        disk_params.storage_domains = [types.StorageDomain(name=sd_name, )]

        vm_service = test_utils.get_vm_service(engine, vm_name)
        nt.assert_true(vm_service.disk_attachments_service().add(
            types.DiskAttachment(disk=disk_params,
                                 interface=types.DiskInterface.VIRTIO)))

    for disk_name in (GLANCE_DISK_NAME, DISK1_NAME, DISK2_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 add_serial_console_vm2(api):
    engine = api.system_service()
    # Find the virtual machine. Note the use of the `all_content` parameter, it is
    # required in order to obtain additional information that isn't retrieved by
    # default, like the configuration of the serial console.
    vm = engine.vms_service().list(search='name={}'.format(VM2_NAME),
                                   all_content=True)[0]
    if not vm.console.enabled:
        vm_service = test_utils.get_vm_service(engine, VM2_NAME)
        vm_service.update(types.Vm(console=types.Console(enabled=True)))
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]:
        assertions.assert_true_within_short(
            lambda: vm_service.get().status == sdk4.types.VmStatus.DOWN)
示例#27
0
def test_add_disks(engine_api, cirros_image_glance_disk_name):
    engine = engine_api.system_service()
    vm_service = test_utils.get_vm_service(engine, VM0_NAME)
    glance_disk = test_utils.get_disk_service(
        engine,
        cirros_image_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,
        backup=types.DiskBackup.INCREMENTAL,
    )

    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 (cirros_image_glance_disk_name, DISK1_NAME, DISK2_NAME,
                      BACKUP_DISK_NAME):
        disk_service = test_utils.get_disk_service(engine, disk_name)
        assertions.assert_true_within_short(
            lambda: disk_service.get().status == types.DiskStatus.OK)
示例#28
0
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)
示例#29
0
def test_export_vm1(engine_api):
    engine = engine_api.system_service()
    vm_service = test_utils.get_vm_service(engine, VM1_NAME)
    host = test_utils.get_first_active_host_by_name(engine)

    with engine_utils.wait_for_event(
            engine, 1223):  # IMPORTEXPORT_STARTING_EXPORT_VM_TO_OVA event
        vm_service.export_to_path_on_host(host=types.Host(id=host.id),
                                          directory=OVA_DIR,
                                          filename=OVA_VM_EXPORT_NAME,
                                          async=True)
def export_vm1(api):
    engine = api.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 next_run_unplug_cpu(api):
    vm_service = test_utils.get_vm_service(api.system_service(), 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)
    nt.assert_true(vm_service.get().cpu.topology.sockets == 2)
    nt.assert_true(vm_service.get(next_run=True).cpu.topology.sockets == 1)
    vm_service.reboot()
    testlib.assert_true_within_long(
        lambda: vm_service.get().status == types.VmStatus.UP)
    nt.assert_true(vm_service.get().cpu.topology.sockets == 1)
示例#32
0
def hotunplug_disk(api):
    engine = api.system_service()
    vm_service = test_utils.get_vm_service(engine, VM0_NAME)
    disk_service = test_utils.get_disk_service(engine, DISK0_NAME)
    disk_attachments_service = vm_service.disk_attachments_service()
    disk_attachment = disk_attachments_service.attachment_service(
        disk_service.get().id)

    nt.assert_true(disk_attachment.update(types.DiskAttachment(active=False)))

    testlib.assert_true_within_short(
        lambda: disk_attachment.get().active == False)
def verify_vm1_exported(api):
    engine = api.system_service()
    vm_service = test_utils.get_vm_service(engine, VM1_NAME)
    testlib.assert_true_within_short(
        lambda: vm_service.get().status == 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)
示例#34
0
def local_maintenance(prefix, api):
    logging.info("Waiting For System Stability...")
    time.sleep(wait_value)

    engine = api.system_service()
    vm_service = test_utils.get_vm_service(engine, VM_HE_NAME)
    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

    he_host = _current_running_host()

    host_service = hosts_service.host_service(id=he_host.id)

    prev_host_id = he_host.id

    logging.info("Performing Deactivation...")

    host_service.deactivate()

    testlib.assert_true_within_long(
        lambda: host_service.get().status == types.HostStatus.MAINTENANCE or
        host_service.get(all_content=True).hosted_engine.local_maintenance)

    logging.info("Performing Activation...")

    host_service.activate()

    testlib.assert_true_within_long(
        lambda: host_service.get().status == types.HostStatus.UNASSIGNED)

    logging.info("Waiting For System Stability...")

    time.sleep(wait_value)

    logging.info("Waiting For Maintenance...")

    testlib.assert_true_within_long(lambda: not host_service.get(
        all_content=True).hosted_engine.local_maintenance)

    logging.info("Waiting For Score...")

    testlib.assert_true_within_long(
        lambda: host_service.get(all_content=True).hosted_engine.score > 0)

    logging.info("Validating Migration...")

    he_host = _current_running_host()

    testlib.assert_true_within_short(lambda: prev_host_id != he_host.id)
示例#35
0
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
    )
示例#36
0
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 preview_snapshot_with_memory(api):
    engine = api.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 next_run_unplug_cpu(api):
    engine = api.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)
    nt.assert_true(vm_service.get().cpu.topology.sockets == 2)
    nt.assert_true(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)
    nt.assert_true(vm_service.get().cpu.topology.sockets == 1)
def hotplug_memory(api):
    engine = api.system_service()
    vm_service = test_utils.get_vm_service(engine, VM0_NAME)
    new_memory = vm_service.get().memory * 2
    with test_utils.TestEvent(engine, 2039): # HOT_SET_MEMORY(2,039)
        vm_service.update(
            vm=types.Vm(
                memory=new_memory
            )
        )
        nt.assert_true(
            vm_service.get().memory == new_memory
        )
示例#40
0
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 hotplug_memory(prefix):
    api = prefix.virt_env.engine_vm().get_api_v4()
    engine = api.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
            )
        )
        nt.assert_true(
            vm_service.get().memory == new_memory
        )
    assert_vm_is_alive(prefix, VM0_NAME)
def suspend_resume_vm0(prefix):
    vm_host = _vm_host(prefix, VM0_NAME)
    ret = vm_host.ssh(['tail', '-1', VDSM_LOG])
    nt.assert_equals(ret.code, EX_OK)
    log_items = ret.out.split()
    global _log_time_before_suspend
    _log_time_before_suspend = log_items[0] + ' ' + log_items[1]  # date + time

    api = prefix.virt_env.engine_vm().get_api_v4()
    vm_service = test_utils.get_vm_service(api.system_service(), VM0_NAME)
    vm_service.suspend()
    testlib.assert_true_within_long(
        lambda: vm_service.get().status == types.VmStatus.SUSPENDED
    )

    vm_service.start()
def ha_recovery(prefix):
    engine = prefix.virt_env.engine_vm().get_api_v4().system_service()
    with test_utils.TestEvent(engine, [119, 9602, 506]):
        # VM_DOWN_ERROR event(119)
        # HA_VM_FAILED event event(9602)
        # VDS_INITIATED_RUN_VM event(506)
        vm_host = _vm_host(prefix, VM2_NAME)
        pid = vm_host.ssh(['pgrep', '-f', 'qemu.*guest=vm2'])
        vm_host.ssh(['kill', '-KILL', pid.out])

    vm_service = test_utils.get_vm_service(engine, VM2_NAME)
    testlib.assert_true_within_long(
        lambda:
        vm_service.get().status == types.VmStatus.UP
    )
    with test_utils.TestEvent(engine, 33): # USER_STOP_VM event
        vm_service.stop()
def remove_vm2_lease(api):
    engine = api.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 make_snapshot_with_memory(api):
    engine = api.system_service()
    vm_service = test_utils.get_vm_service(engine, VM0_NAME)
    disks_service = engine.disks_service()
    vm_disks_service = \
        test_utils.get_disk_attachments_service(engine, VM0_NAME)
    vm_disks = [disks_service.disk_service(attachment.disk.id).get()
                for attachment in vm_disks_service.list()]
    disk_attachments = [types.DiskAttachment(disk=types.Disk(id=disk.id))
                        for disk in vm_disks
                        if disk.storage_type != types.DiskStorageType.LUN]
    snapshots_service = vm_service.snapshots_service()
    snapshot_params = types.Snapshot(
        description=SNAPSHOT_DESC_MEM,
        persist_memorystate=True,
        disk_attachments=disk_attachments
    )
    with test_utils.TestEvent(engine, 45):  # USER_CREATE_SNAPSHOT event
        snapshots_service.add(snapshot_params)
def hotplug_cpu(prefix):
    api = prefix.virt_env.engine_vm().get_api_v4()
    engine = api.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
            )
        )
        nt.assert_true(
            vm_service.get().cpu.topology.sockets == 2
        )
    ret = _vm_ssh(prefix, VM0_NAME, ['lscpu'])
    nt.assert_equals(ret.code, 0)
    match = re.search(r'CPU\(s\):\s+(?P<cpus>[0-9]+)', ret.out)
    nt.assert_true(match.group('cpus') == '2')
def add_vm_pool(api):
    engine = api.system_service()
    pools_service = engine.vm_pools_service()
    pool_cluster = engine.clusters_service().list(search='name={}'.format(TEST_CLUSTER))[0]
    pool_template = engine.templates_service().list(search='name={}'.format(TEMPLATE_CIRROS))[0]
    with test_utils.TestEvent(engine, 302):
        pools_service.add(
            pool=types.VmPool(
                name=VMPOOL_NAME,
                cluster=pool_cluster,
                template=pool_template,
                use_latest_template_version=True,
            )
        )
    vm_service = test_utils.get_vm_service(engine, VMPOOL_NAME+'-1')
    testlib.assert_true_within_short(
        lambda:
        vm_service.get().status == types.VmStatus.DOWN,
        allowed_exceptions=[IndexError]
    )
def remove_backup_vm_and_backup_snapshot(api):
    engine = api.system_service()
    backup_vm_service = test_utils.get_vm_service(engine, BACKUP_VM_NAME)
    vm2_snapshots_service = test_utils.get_vm_snapshots_service(engine, VM2_NAME)
    vm2_snapshot = vm2_snapshots_service.list()[-1]
    # power-off backup-vm
    with test_utils.TestEvent(engine, [33, 61]):
        # VM_DOWN(61) event
        # USER_STOP_VM(33) event
        backup_vm_service.stop()
        testlib.assert_true_within_long(
            lambda:
            backup_vm_service.get().status == types.VmStatus.DOWN
        )
    # remove backup_vm
    num_of_vms = len(engine.vms_service().list())
    backup_vm_service.remove()
    nt.assert_true(len(engine.vms_service().list()) == (num_of_vms-1))
    with test_utils.TestEvent(engine, 342): # USER_REMOVE_SNAPSHOT event
        # remove vm2 snapshot
        vm2_snapshots_service.snapshot_service(vm2_snapshot.id).remove()
def vdsm_recovery(prefix):
    engine = prefix.virt_env.engine_vm().get_api_v4().system_service()
    vm_service = test_utils.get_vm_service(engine, VM0_NAME)
    host_id = vm_service.get().host.id
    host_service = engine.hosts_service().host_service(host_id)
    host_name = host_service.get().name
    vm_host = prefix.virt_env.get_vm(host_name)

    vm_host.service('vdsmd').stop()
    testlib.assert_true_within_short(
        lambda:
        vm_service.get().status == types.VmStatus.UNKNOWN
    )

    vm_host.service('vdsmd').start()
    testlib.assert_true_within_short(
        lambda:
        host_service.get().status == types.HostStatus.UP
    )
    testlib.assert_true_within_short(
        lambda:
        vm_service.get().status == types.VmStatus.UP
    )
def get_nics_on(engine, vm_name):
    return test_utils.get_vm_service(engine, vm_name).nics_service().list()
def _vm_host(prefix, vm_name):
    engine = prefix.virt_env.engine_vm().get_api_v4().system_service()
    vm_service = test_utils.get_vm_service(engine, vm_name)
    host_id = vm_service.get().host.id
    host_name = engine.hosts_service().host_service(host_id).get().name
    return prefix.virt_env.get_vm(host_name)
def create_nics_on_vm(engine, vm_name, profiles):
    vm2_service = test_utils.get_vm_service(engine, vm_name)
    _add_nics(vm2_service, profiles)