Exemplo n.º 1
0
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)
Exemplo n.º 2
0
def add_snapshot_for_backup(api):
    engine = api.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,
        )
Exemplo n.º 3
0
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, )
Exemplo n.º 4
0
def live_storage_migration(api):
    engine = api.system_service()
    disk_service = test_utils.get_disk_service(engine, DISK0_NAME)
    correlation_id = uuid.uuid4()
    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.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
    )
Exemplo n.º 5
0
def snapshot_cold_merge(engine_api):
    engine = engine_api.system_service()
    vm1_snapshots_service = test_utils.get_vm_snapshots_service(
        engine, VM1_NAME)
    if vm1_snapshots_service is None:
        pytest.skip('Glance is not available')

    disk = engine.disks_service().list(
        search='name={} and vm_names={}'.format(DISK1_NAME, VM1_NAME))[0]

    dead_snap1_params = types.Snapshot(
        description=SNAPSHOT_DESC_1,
        persist_memorystate=False,
        disk_attachments=[types.DiskAttachment(disk=types.Disk(id=disk.id))])
    correlation_id = uuid.uuid4()

    vm1_snapshots_service.add(dead_snap1_params,
                              query={'correlation_id': correlation_id})

    assertions.assert_true_within_long(
        lambda: test_utils.all_jobs_finished(engine, correlation_id))
    assertions.assert_true_within_long(lambda: vm1_snapshots_service.list()[
        -1].snapshot_status == types.SnapshotStatus.OK)

    dead_snap2_params = types.Snapshot(
        description=SNAPSHOT_DESC_2,
        persist_memorystate=False,
        disk_attachments=[types.DiskAttachment(disk=types.Disk(id=disk.id))])
    correlation_id_snap2 = uuid.uuid4()

    vm1_snapshots_service.add(dead_snap2_params,
                              query={'correlation_id': correlation_id_snap2})

    assertions.assert_true_within_long(
        lambda: test_utils.all_jobs_finished(engine, correlation_id_snap2))
    assertions.assert_true_within_long(lambda: vm1_snapshots_service.list()[
        -1].snapshot_status == types.SnapshotStatus.OK)

    snapshot = vm1_snapshots_service.list()[-2]
    vm1_snapshots_service.snapshot_service(snapshot.id).remove()

    assertions.assert_true_within_long(
        lambda: len(vm1_snapshots_service.list()) == 2)
    assertions.assert_true_within_long(lambda: vm1_snapshots_service.list()[
        -1].snapshot_status == types.SnapshotStatus.OK)
Exemplo n.º 6
0
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 snapshot_merge(api):
    engine = api.system_service()
    vm0_snapshots_service = test_utils.get_vm_snapshots_service(
        engine, VM0_NAME)

    disk = engine.disks_service().list(
        search='name={}'.format(GLANCE_DISK_NAME))[0]

    dead_snap1_params = types.Snapshot(
        description='dead_snap1',
        persist_memorystate=False,
        disk_attachments=[types.DiskAttachment(disk=types.Disk(id=disk.id))])

    correlation_id = uuid.uuid4()
    vm0_snapshots_service.add(dead_snap1_params,
                              query={'correlation_id': correlation_id})
    testlib.assert_true_within_short(
        lambda: test_utils.all_jobs_finished(engine, correlation_id))
    testlib.assert_true_within_short(lambda: vm0_snapshots_service.list()[
        -1].snapshot_status == types.SnapshotStatus.OK)

    dead_snap2_params = types.Snapshot(
        description='dead_snap2',
        persist_memorystate=False,
        disk_attachments=[types.DiskAttachment(disk=types.Disk(id=disk.id))])

    correlation_id_snap2 = uuid.uuid4()

    vm0_snapshots_service.add(dead_snap2_params,
                              query={'correlation_id': correlation_id_snap2})
    testlib.assert_true_within_short(
        lambda: test_utils.all_jobs_finished(engine, correlation_id_snap2))
    testlib.assert_true_within_short(lambda: vm0_snapshots_service.list()[
        -1].snapshot_status == types.SnapshotStatus.OK)

    snapshot = vm0_snapshots_service.list()[-2]
    vm0_snapshots_service.snapshot_service(snapshot.id).remove()
    testlib.assert_true_within_short(
        lambda: (len(vm0_snapshots_service.list()) == 2) and
        (vm0_snapshots_service.list()[-1].snapshot_status == types.
         SnapshotStatus.OK), )
Exemplo n.º 8
0
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))
Exemplo n.º 9
0
def remove_vm_pool(api):
    engine = api.system_service()
    pool_service = test_utils.get_pool_service(
        engine,
        VMPOOL_NAME,
    )
    correlation_id = uuid.uuid4()
    pool_service.remove(query={'correlation_id': correlation_id})
    vm_pools_service = api.system_service().vm_pools_service()
    nt.assert_true(len(vm_pools_service.list()) == 0)
    testlib.assert_true_within_long(
        lambda: test_utils.all_jobs_finished(engine, correlation_id))
Exemplo n.º 10
0
def remove_vm_pool(api):
    engine = api.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.system_service().vm_pools_service()
        nt.assert_true(
            len(vm_pools_service.list()) == 0
        )
    testlib.assert_true_within_long(
        lambda:
        test_utils.all_jobs_finished(engine, correlation_id)
    )
Exemplo n.º 11
0
def update_vm_pool(api):
    engine = api.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}
    )
    nt.assert_true(
        pool_service.get().max_user_vms == 2
    )
    testlib.assert_true_within_long(
        lambda:
        test_utils.all_jobs_finished(engine, correlation_id)
    )
Exemplo n.º 12
0
def test_hotunplug_disk(engine_api):
    engine = engine_api.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 engine_utils.wait_for_event(engine, 2002):
        # USER_HOTUNPLUG_DISK(2,002)
        correlation_id = 'test_hotunplug_disk'
        assert disk_attachment.update(types.DiskAttachment(active=False),
                                      query={'correlation_id': correlation_id})
        assertions.assert_true_within_long(
            lambda: test_utils.all_jobs_finished(engine, correlation_id))

        assertions.assert_true_within_short(
            lambda: disk_service.get().status == types.DiskStatus.OK)

        assertions.assert_true_within_short(
            lambda: disk_attachment.get().active == False)
def test_deactivate_storage_domain(engine_api):
    # TODO: uncomment once VnicSetup checks are fixed.
    # 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

    assertions.assert_true_within_short(
        _deactivate_with_running_ovf_update_task)

    # Wait for the storage deactivation to be finished.
    # TODO Fix the code on engine, so the status will be changed once the operation finished (BZ 1949101).
    assertions.assert_true_within_short(
        lambda: test_utils.all_jobs_finished(engine, correlation_id)
    )
    assertions.assert_true_within_short(
        lambda:
        test_utils.get_attached_storage_domain(
            dc, SD_SECOND_NFS_NAME).status == ovirtsdk4.types.StorageDomainStatus.MAINTENANCE
    )
Exemplo n.º 14
0
def snapshot_cold_merge(api):
    engine = api.system_service()
    vm1_snapshots_service = test_utils.get_vm_snapshots_service(engine, VM1_NAME)
    if vm1_snapshots_service is None:
        raise SkipTest('Glance is not available')

    disk = engine.disks_service().list(search='name={}'.format(DISK1_NAME))[0]

    dead_snap1_params = types.Snapshot(
        description=SNAPSHOT_DESC_1,
        persist_memorystate=False,
        disk_attachments=[
            types.DiskAttachment(
                disk=types.Disk(
                    id=disk.id
                )
            )
        ]
    )
    correlation_id = uuid.uuid4()

    vm1_snapshots_service.add(dead_snap1_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:
        vm1_snapshots_service.list()[-1].snapshot_status == types.SnapshotStatus.OK
    )

    dead_snap2_params = types.Snapshot(
        description=SNAPSHOT_DESC_2,
        persist_memorystate=False,
        disk_attachments=[
            types.DiskAttachment(
                disk=types.Disk(
                    id=disk.id
                )
            )
        ]
    )
    correlation_id_snap2 = uuid.uuid4()

    vm1_snapshots_service.add(dead_snap2_params,
                              query={'correlation_id': correlation_id_snap2})

    testlib.assert_true_within_long(
        lambda:
        test_utils.all_jobs_finished(engine, correlation_id_snap2)
    )
    testlib.assert_true_within_long(
        lambda:
        vm1_snapshots_service.list()[-1].snapshot_status == types.SnapshotStatus.OK
    )

    snapshot = vm1_snapshots_service.list()[-2]
    vm1_snapshots_service.snapshot_service(snapshot.id).remove()

    testlib.assert_true_within_long(
        lambda:
        len(vm1_snapshots_service.list()) == 2
    )
    testlib.assert_true_within_long(
        lambda:
        vm1_snapshots_service.list()[-1].snapshot_status == types.SnapshotStatus.OK
    )
Exemplo n.º 15
0
def snapshot_merge(api):
    engine = api.system_service()
    vm0_snapshots_service = test_utils.get_vm_snapshots_service(engine, VM0_NAME)

    disk = engine.disks_service().list(search='name={}'.format(DISK0_NAME))[0]

    dead_snap1_params = types.Snapshot(
        description='dead_snap1',
        persist_memorystate=False,
        disk_attachments=[
            types.DiskAttachment(
                disk=types.Disk(
                    id=disk.id
                )
            )
        ]
    )

    correlation_id = uuid.uuid4()
    vm0_snapshots_service.add(
        dead_snap1_params,
        query={'correlation_id': correlation_id}
    )
    testlib.assert_true_within_short(
        lambda:
        test_utils.all_jobs_finished(engine, correlation_id)
    )
    testlib.assert_true_within_short(
        lambda:
        vm0_snapshots_service.list()[-1].snapshot_status == types.SnapshotStatus.OK
    )

    dead_snap2_params = types.Snapshot(
        description='dead_snap2',
        persist_memorystate=False,
        disk_attachments=[
            types.DiskAttachment(
                disk=types.Disk(
                    id=disk.id
                )
            )
        ]
    )

    correlation_id_snap2 = uuid.uuid4()

    vm0_snapshots_service.add(
        dead_snap2_params,
        query={'correlation_id': correlation_id_snap2}
    )
    testlib.assert_true_within_short(
        lambda:
        test_utils.all_jobs_finished(engine, correlation_id_snap2)
    )
    testlib.assert_true_within_short(
        lambda:
        vm0_snapshots_service.list()[-1].snapshot_status == types.SnapshotStatus.OK
    )

    snapshot = vm0_snapshots_service.list()[-2]
    vm0_snapshots_service.snapshot_service(snapshot.id).remove()
    testlib.assert_true_within_short(
        lambda:
        (len(vm0_snapshots_service.list()) == 2) and
        (vm0_snapshots_service.list()[-1].snapshot_status == types.SnapshotStatus.OK),
    )
Exemplo n.º 16
0
def test_verify_vm_import(engine_api):
    engine = engine_api.system_service()
    correlation_id = "test_validate_ova_import_vm"
    assertions.assert_true_within_long(
        lambda: test_utils.all_jobs_finished(engine, correlation_id))
    _verify_vm_state(engine, IMPORTED_VM_NAME, types.VmStatus.DOWN)