Example #1
0
def add_hosts(prefix):
    api = prefix.virt_env.engine_vm().get_api()

    def _add_host(vm):
        p = params.Host(
            name=vm.name(),
            address=vm.name(),
            cluster=params.Cluster(name=CLUSTER_NAME, ),
            root_password=vm.root_password(),
            override_iptables=True,
        )

        return api.hosts.add(p)

    hosts = prefix.virt_env.host_vms()
    vec = utils.func_vector(_add_host, [(h, ) for h in hosts])
    vt = utils.VectorThread(vec)
    vt.start_all()
    nt.assert_true(all(vt.join_all()))

    for host in hosts:
        testlib.assert_true_within(
            func=lambda: api.hosts.get(host.name()).status.state == 'up',
            timeout=LONG_TIMEOUT,
        )
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(
        func=(
            lambda:
                api.vms.get(
                    VM0_NAME,
                ).disks.get(DISK0_NAME).status.state == 'ok'
        ),
        timeout=SHORT_TIMEOUT,
    )
def vm_migrate(api):
    migrate_params = params.Action(host=params.Host(name=HOSTS[1], ), )
    api.vms.get(VM1_NAME).migrate(migrate_params)
    testlib.assert_true_within(
        func=lambda: api.vms.get(VM1_NAME).status.state == 'up',
        timeout=SHORT_TIMEOUT,
    )
def add_hosts(prefix):
    api = prefix.virt_env.engine_vm().get_api()

    def _add_host(vm):
        p = params.Host(
            name=vm.name(),
            address=vm.name(),
            cluster=params.Cluster(
                name=CLUSTER_NAME,
            ),
            root_password=vm.root_password(),
            override_iptables=True,
        )

        return api.hosts.add(p)

    hosts = prefix.virt_env.host_vms()
    vec = utils.func_vector(_add_host, [(h,) for h in hosts])
    vt = utils.VectorThread(vec)
    vt.start_all()
    nt.assert_true(all(vt.join_all()))

    for host in hosts:
        testlib.assert_true_within(
            func=lambda: api.hosts.get(host.name()).status.state == 'up',
            timeout=LONG_TIMEOUT,
        )
def add_vm_template(api):
    vm_params = params.VM(
        name=VM1_NAME,
        memory=4 * GB,
        cluster=params.Cluster(
            name=TEST_CLUSTER,
        ),
        template=params.Template(
            name=TEMPLATE_CENTOS7,
        ),
        display=params.Display(
            type_='spice',
        ),
    )
    api.vms.add(vm_params)
    testlib.assert_true_within(
        func=lambda: api.vms.get(VM1_NAME).status.state == 'down',
        timeout=LONG_TIMEOUT,
    )
    disk_name = api.vms.get(VM1_NAME).disks.list()[0].name
    testlib.assert_true_within(
        func=(
            lambda:
                api.vms.get(
                    VM1_NAME,
                ).disks.get(disk_name).status.state == 'ok'
        ),
        timeout=LONG_TIMEOUT,
    )
def _add_storage_domain(api, p):
    dc = api.datacenters.get(DC_NAME)
    sd = api.storagedomains.add(p)
    nt.assert_true(sd)
    nt.assert_true(
        api.datacenters.get(
            DC_NAME,
        ).storagedomains.add(
            api.storagedomains.get(
                sd.name,
            ),
        )
    )
    if dc.storagedomains.get(
        sd.name,
    ).status.state == 'maintenance':
        sd.activate()
        testlib.assert_true_within(
            func=(
                lambda:
                    dc.starage_domains.get(
                        sd.name,
                    ).status.state == 'active'
                ),
            timeout=LONG_TIMEOUT,
        )
def vm_run(api):
    start_params = params.Action(vm=params.VM(
        placement_policy=params.VmPlacementPolicy(host=params.Host(
            name=HOSTS[0], ), ), ), )
    api.vms.get(VM1_NAME).start(start_params)
    testlib.assert_true_within(
        func=lambda: api.vms.get(VM1_NAME).status.state == 'up',
        timeout=SHORT_TIMEOUT,
    )
def vm_migrate(api):
    migrate_params = params.Action(
        host=params.Host(
            name=HOSTS[1],
        ),
    )
    api.vms.get(VM1_NAME).migrate(migrate_params)
    testlib.assert_true_within(
        func=lambda: api.vms.get(VM1_NAME).status.state == 'up',
        timeout=SHORT_TIMEOUT,
    )
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(
        func=lambda: api.vms.get(VM0_NAME).status.state == 'down',
        timeout=SHORT_TIMEOUT,
    )
Example #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(
            func=lambda: api.templates.get(template.name).status.state == 'ok',
            timeout=SHORT_TIMEOUT,
        )
Example #11
0
def _add_storage_domain(api, p):
    dc = api.datacenters.get(DC_NAME)
    sd = api.storagedomains.add(p)
    nt.assert_true(sd)
    nt.assert_true(
        api.datacenters.get(DC_NAME, ).storagedomains.add(
            api.storagedomains.get(sd.name, ), ))
    if dc.storagedomains.get(sd.name, ).status.state == 'maintenance':
        sd.activate()
        testlib.assert_true_within(
            func=(lambda: dc.starage_domains.get(sd.name, ).status.state ==
                  'active'),
            timeout=LONG_TIMEOUT,
        )
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 vm_run(api):
    start_params = params.Action(
        vm=params.VM(
            placement_policy=params.VmPlacementPolicy(
                host=params.Host(
                    name=HOSTS[0],
                ),
            ),
        ),
    )
    api.vms.get(VM1_NAME).start(start_params)
    testlib.assert_true_within(
        func=lambda: api.vms.get(VM1_NAME).status.state == 'up',
        timeout=SHORT_TIMEOUT,
    )
def add_vm_template(api):
    vm_params = params.VM(
        name=VM1_NAME,
        memory=4 * GB,
        cluster=params.Cluster(name=TEST_CLUSTER, ),
        template=params.Template(name=TEMPLATE_CENTOS7, ),
        display=params.Display(type_='spice', ),
    )
    api.vms.add(vm_params)
    testlib.assert_true_within(
        func=lambda: api.vms.get(VM1_NAME).status.state == 'down',
        timeout=LONG_TIMEOUT,
    )
    disk_name = api.vms.get(VM1_NAME).disks.list()[0].name
    testlib.assert_true_within(
        func=(lambda: api.vms.get(VM1_NAME, ).disks.get(disk_name).status.state
              == 'ok'),
        timeout=LONG_TIMEOUT,
    )
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(
        func=lambda: api.vms.get(VM0_NAME).status.state == 'down',
        timeout=SHORT_TIMEOUT,
    )
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(
        func=(lambda: api.vms.get(VM0_NAME, ).disks.get(DISK0_NAME).status.
              state == 'ok'),
        timeout=SHORT_TIMEOUT,
    )
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(
            func=lambda: api.templates.get(template.name).status.state == 'ok',
            timeout=SHORT_TIMEOUT,
        )
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(
        func=(
            lambda:
                api.vms.get(VM0_NAME).snapshots.list()[-1].snapshot_status
                == 'ok'
        ),
        timeout=SHORT_TIMEOUT,
    )

    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(
        func=(
            lambda:
                api.vms.get(VM0_NAME).snapshots.list()[-1].snapshot_status
                == 'ok'
        ),
        timeout=SHORT_TIMEOUT,
    )

    api.vms.get(VM0_NAME).snapshots.list()[-2].delete()
    testlib.assert_true_within(
        func=(
            lambda:
                (len(api.vms.get(VM0_NAME).snapshots.list()) == 2) and
                (api.vms.get(VM0_NAME).snapshots.list()[-1].snapshot_status
                 == 'ok')
        ),
        timeout=SHORT_TIMEOUT,
    )
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(
        func=(lambda: api.vms.get(VM0_NAME).snapshots.list()[-1].
              snapshot_status == 'ok'),
        timeout=SHORT_TIMEOUT,
    )

    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(
        func=(lambda: api.vms.get(VM0_NAME).snapshots.list()[-1].
              snapshot_status == 'ok'),
        timeout=SHORT_TIMEOUT,
    )

    api.vms.get(VM0_NAME).snapshots.list()[-2].delete()
    testlib.assert_true_within(
        func=(lambda: (len(api.vms.get(VM0_NAME).snapshots.list()) == 2) and
              (api.vms.get(VM0_NAME).snapshots.list()[-1].snapshot_status ==
               'ok')),
        timeout=SHORT_TIMEOUT,
    )
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',
    )