def vm_migrate(prefix):
    api = prefix.virt_env.engine_vm().get_api()
    host_names = [h.name() for h in prefix.virt_env.host_vms()]

    migrate_params = params.Action(
        host=params.Host(name=sorted(host_names)[1]), )
    api.vms.get(VM1_NAME).migrate(migrate_params)
    testlib.assert_true_within_short(
        lambda: api.vms.get(VM1_NAME).status.state == 'up', )
def vm_run(prefix):
    api = prefix.virt_env.engine_vm().get_api()
    host_names = [h.name() for h in prefix.virt_env.host_vms()]

    start_params = params.Action(vm=params.VM(
        placement_policy=params.VmPlacementPolicy(
            host=params.Host(name=sorted(host_names)[0]), ), ), )
    api.vms.get(VM1_NAME).start(start_params)
    testlib.assert_true_within_short(
        lambda: api.vms.get(VM1_NAME).status.state == 'up', )
Exemplo n.º 3
0
def import_templates(api):
    templates = api.storagedomains.get('templates', ).templates.list(
        unregistered=True, )

    for template in templates:
        template.register(action=params.Action(cluster=params.Cluster(
            name=CLUSTER_NAME, ), ), )

    for template in api.templates.list():
        testlib.assert_true_within_short(
            lambda: api.templates.get(template.name).status.state == 'ok', )
def add_vm_blank(api):
    vm_params = params.VM(
        name=VM0_NAME,
        memory=1 * GB,
        cluster=params.Cluster(name=TEST_CLUSTER, ),
        template=params.Template(name=TEMPLATE_BLANK, ),
        display=params.Display(type_='spice', ),
    )
    api.vms.add(vm_params)
    testlib.assert_true_within_short(
        lambda: api.vms.get(VM0_NAME).status.state == 'down', )
def vm_migrate(prefix):
    api = prefix.virt_env.engine_vm().get_api()
    host_names = [h.name() for h in prefix.virt_env.host_vms()]

    migrate_params = params.Action(
        host=params.Host(
            name=sorted(host_names)[1]
        ),
    )
    api.vms.get(VM1_NAME).migrate(migrate_params)
    testlib.assert_true_within_short(
        lambda: api.vms.get(VM1_NAME).status.state == 'up',
    )
def snapshot_live_merge(api):
    disk = api.vms.get(VM1_NAME).disks.list()[0]
    disk_id = disk.id
    disk_name = disk.name

    live_snap1_params = params.Snapshot(
        description='live_snap1',
        persist_memorystate=True,
        disks=params.Disks(disk=[
            params.Disk(id=disk_id, ),
        ], ),
    )
    api.vms.get(VM1_NAME).snapshots.add(live_snap1_params)
    testlib.assert_true_within(
        func=(lambda: api.vms.get(VM1_NAME).snapshots.list()[-1].
              snapshot_status == 'ok'),
        timeout=SHORT_TIMEOUT,
    )

    live_snap2_params = params.Snapshot(
        description='live_snap2',
        persist_memorystate=True,
        disks=params.Disks(disk=[
            params.Disk(id=disk_id, ),
        ], ),
    )
    api.vms.get(VM1_NAME).snapshots.add(live_snap2_params)
    for i, _ in enumerate(api.vms.get(VM1_NAME).snapshots.list()):
        testlib.assert_true_within(
            func=(lambda: (api.vms.get(VM1_NAME).snapshots.list()[i].
                           snapshot_status == 'ok')),
            timeout=SHORT_TIMEOUT,
        )

    api.vms.get(VM1_NAME).snapshots.list()[-2].delete()

    testlib.assert_true_within_long(
        lambda: len(api.vms.get(VM1_NAME).snapshots.list()) == 2, )

    for i, _ in enumerate(api.vms.get(VM1_NAME).snapshots.list()):
        testlib.assert_true_within_long(
            lambda: (api.vms.get(VM1_NAME).snapshots.list()[i].snapshot_status
                     == 'ok'), )
    testlib.assert_true_within_short(
        lambda: api.vms.get(VM1_NAME).status.state == 'up', )

    testlib.assert_true_within_long(
        lambda: api.vms.get(VM1_NAME).disks.get(disk_name).status.state ==
        'ok', )
def add_disk(api):
    disk_params = params.Disk(
        name=DISK0_NAME,
        size=10 * GB,
        provisioned_size=1,
        interface='virtio',
        format='cow',
        storage_domains=params.StorageDomains(storage_domain=[
            params.StorageDomain(name='nfs', ),
        ], ),
        status=None,
        sparse=True,
        bootable=True,
    )
    api.vms.get(VM0_NAME).disks.add(disk_params)
    testlib.assert_true_within_short(lambda: api.vms.get(VM0_NAME).disks.get(
        DISK0_NAME).status.state == 'ok')
def vm_run(prefix):
    api = prefix.virt_env.engine_vm().get_api()
    host_names = [h.name() for h in prefix.virt_env.host_vms()]

    start_params = params.Action(
        vm=params.VM(
            placement_policy=params.VmPlacementPolicy(
                host=params.Host(
                    name=sorted(host_names)[0]
                ),
            ),
        ),
    )
    api.vms.get(VM1_NAME).start(start_params)
    testlib.assert_true_within_short(
        lambda: api.vms.get(VM1_NAME).status.state == 'up',
    )
def add_vm_blank(api):
    vm_params = params.VM(
        name=VM0_NAME,
        memory=1 * GB,
        cluster=params.Cluster(
            name=TEST_CLUSTER,
        ),
        template=params.Template(
            name=TEMPLATE_BLANK,
        ),
        display=params.Display(
            type_='spice',
        ),
    )
    api.vms.add(vm_params)
    testlib.assert_true_within_short(
        lambda: api.vms.get(VM0_NAME).status.state == 'down',
    )
Exemplo n.º 10
0
def import_templates(api):
    templates = api.storagedomains.get(
        'templates',
    ).templates.list(
        unregistered=True,
    )

    for template in templates:
        template.register(
            action=params.Action(
                cluster=params.Cluster(
                    name=CLUSTER_NAME,
                ),
            ),
        )

    for template in api.templates.list():
        testlib.assert_true_within_short(
            lambda: api.templates.get(template.name).status.state == 'ok',
        )
def snapshot_merge(api):
    dead_snap1_params = params.Snapshot(
        description='dead_snap1',
        persist_memorystate=False,
        disks=params.Disks(disk=[
            params.Disk(id=api.vms.get(VM0_NAME).disks.get(DISK0_NAME).id, ),
        ], ),
    )
    api.vms.get(VM0_NAME).snapshots.add(dead_snap1_params)
    testlib.assert_true_within_short(lambda: api.vms.get(VM0_NAME).snapshots.
                                     list()[-1].snapshot_status == 'ok')

    dead_snap2_params = params.Snapshot(
        description='dead_snap2',
        persist_memorystate=False,
        disks=params.Disks(disk=[
            params.Disk(id=api.vms.get(VM0_NAME).disks.get(DISK0_NAME).id, ),
        ], ),
    )
    api.vms.get(VM0_NAME).snapshots.add(dead_snap2_params)
    testlib.assert_true_within_short(lambda: api.vms.get(VM0_NAME).snapshots.
                                     list()[-1].snapshot_status == 'ok')

    api.vms.get(VM0_NAME).snapshots.list()[-2].delete()
    testlib.assert_true_within_short(
        lambda: (len(api.vms.get(VM0_NAME).snapshots.list()) == 2) and
        (api.vms.get(VM0_NAME).snapshots.list()[-1].snapshot_status == 'ok'), )
def add_disk(api):
    disk_params = params.Disk(
        name=DISK0_NAME,
        size=10 * GB,
        provisioned_size=1,
        interface='virtio',
        format='cow',
        storage_domains=params.StorageDomains(
            storage_domain=[
                params.StorageDomain(
                    name='nfs',
                ),
            ],
        ),
        status=None,
        sparse=True,
        bootable=True,
    )
    api.vms.get(VM0_NAME).disks.add(disk_params)
    testlib.assert_true_within_short(
        lambda:
        api.vms.get(VM0_NAME).disks.get(DISK0_NAME).status.state == 'ok'
    )
def snapshot_merge(api):
    dead_snap1_params = params.Snapshot(
        description='dead_snap1',
        persist_memorystate=False,
        disks=params.Disks(
            disk=[
                params.Disk(
                    id=api.vms.get(VM0_NAME).disks.get(DISK0_NAME).id,
                ),
            ],
        ),
    )
    api.vms.get(VM0_NAME).snapshots.add(dead_snap1_params)
    testlib.assert_true_within_short(
        lambda:
        api.vms.get(VM0_NAME).snapshots.list()[-1].snapshot_status == 'ok'
    )

    dead_snap2_params = params.Snapshot(
        description='dead_snap2',
        persist_memorystate=False,
        disks=params.Disks(
            disk=[
                params.Disk(
                    id=api.vms.get(VM0_NAME).disks.get(DISK0_NAME).id,
                ),
            ],
        ),
    )
    api.vms.get(VM0_NAME).snapshots.add(dead_snap2_params)
    testlib.assert_true_within_short(
        lambda:
        api.vms.get(VM0_NAME).snapshots.list()[-1].snapshot_status == 'ok'
    )

    api.vms.get(VM0_NAME).snapshots.list()[-2].delete()
    testlib.assert_true_within_short(
        lambda:
        (len(api.vms.get(VM0_NAME).snapshots.list()) == 2) and
        (api.vms.get(VM0_NAME).snapshots.list()[-1].snapshot_status
         == 'ok'),
    )
def snapshot_live_merge(api):
    disk = api.vms.get(VM1_NAME).disks.list()[0]
    disk_id = disk.id
    disk_name = disk.name

    live_snap1_params = params.Snapshot(
        description='live_snap1',
        persist_memorystate=True,
        disks=params.Disks(
            disk=[
                params.Disk(
                    id=disk_id,
                ),
            ],
        ),
    )
    api.vms.get(VM1_NAME).snapshots.add(live_snap1_params)
    testlib.assert_true_within(
        func=(
            lambda:
                api.vms.get(VM1_NAME).snapshots.list()[-1].snapshot_status
                == 'ok'
        ),
        timeout=SHORT_TIMEOUT,
    )

    live_snap2_params = params.Snapshot(
        description='live_snap2',
        persist_memorystate=True,
        disks=params.Disks(
            disk=[
                params.Disk(
                    id=disk_id,
                ),
            ],
        ),
    )
    api.vms.get(VM1_NAME).snapshots.add(live_snap2_params)
    for i, _ in enumerate(api.vms.get(VM1_NAME).snapshots.list()):
        testlib.assert_true_within(
            func=(
                lambda:
                    (api.vms.get(VM1_NAME).snapshots.list()[i].snapshot_status
                     == 'ok')
            ),
            timeout=SHORT_TIMEOUT,
        )

    api.vms.get(VM1_NAME).snapshots.list()[-2].delete()

    testlib.assert_true_within_long(
        lambda: len(api.vms.get(VM1_NAME).snapshots.list()) == 2,
    )

    for i, _ in enumerate(api.vms.get(VM1_NAME).snapshots.list()):
        testlib.assert_true_within_long(
            lambda:
                (api.vms.get(VM1_NAME).snapshots.list()[i].snapshot_status
                 == 'ok'),
        )
    testlib.assert_true_within_short(
        lambda: api.vms.get(VM1_NAME).status.state == 'up',
    )

    testlib.assert_true_within_long(
        lambda:
            api.vms.get(VM1_NAME).disks.get(disk_name).status.state == 'ok',
    )