def add_hosts(prefix):
    api = prefix.virt_env.engine_vm().get_api()

    def _add_host(vm):
        p = params.Host(
            name=vm.name(),
            address=vm.ip(),
            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(
            lambda: api.hosts.get(host.name()).status.state == 'up',
            timeout=15 * 60,
        )
Exemple #2
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.ip(),
            cluster=params.Cluster(
                name=CLUSTER_NAME,
            ),
            root_password=vm.root_password(),
            override_iptables=True,
        )

        return api.hosts.add(p)

    def _host_is_up():
        cur_state = api.hosts.get(host.name()).status.state

        if cur_state == 'up':
            return True

        if cur_state == 'install_failed':
            raise RuntimeError('Host %s failed to install' % host.name())

    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(_host_is_up, timeout=15 * 60)
def add_vm_template(api):
    sds = api.system_service().storage_domains_service()
    sd = sds.list(search='name=ovirt-image-repository')[0]
    sd_service = sds.storage_domain_service(sd.id)
    images_service = sd_service.images_service()
    images = images_service.list()

    image = next((i for i in images if i.name == GLANCE_IMAGE_TO_IMPORT), None)

    # Find the service that manages the image that we found in the previous
    # step:
    image_service = images_service.image_service(image.id)

    # Import the image:
    image_service.import_(
        import_as_template=True,
        template=sdk4.types.Template(name=VM_TEMPLATE),
        cluster=sdk4.types.Cluster(name=CLUSTER_NAME),
        storage_domain=sdk4.types.StorageDomain(name=SD_NFS_NAME))

    templates_service = api.system_service().templates_service()
    getTemplate = lambda: templates_service.list(search="name=%s" % VM_TEMPLATE
                                                 )
    testlib.assert_true_within(lambda: len(getTemplate()) == 1 and sdk4.types.
                               TemplateStatus.OK == getTemplate()[0].status,
                               timeout=300)
def add_hosts(prefix):
    api = prefix.virt_env.engine_vm().get_api()

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

        return api.hosts.add(p)

    def _host_is_up():
        cur_state = api.hosts.get(host.name()).status.state

        if cur_state == 'up':
            return True

        if cur_state == 'install_failed':
            raise RuntimeError('Host %s failed to install' % host.name())

    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(_host_is_up, timeout=15 * 60)
Exemple #5
0
def verify_add_hosts_4(api):
    hosts_service = api.system_service().hosts_service()
    total_hosts = hosts_service.list(search='datacenter={}'.format(DC_NAME))

    testlib.assert_true_within(
        lambda: _single_host_up(hosts_service, total_hosts),
        timeout=constants.ADD_HOST_TIMEOUT)
def verify_add_hosts_4(api):
    hosts_service = api.system_service().hosts_service()
    total_hosts = hosts_service.list(search='datacenter={}'.format(DC_NAME))

    testlib.assert_true_within(
        lambda: _single_host_up(hosts_service, total_hosts),
        timeout=constants.ADD_HOST_TIMEOUT
    )
Exemple #7
0
def verify_add_hosts(api):
    hosts_service = api.system_service().hosts_service()
    hosts_status = hosts_service.list(search='datacenter={}'.format(DC_NAME))
    total_hosts = len(hosts_status)
    dump_hosts = _host_status_to_print(hosts_service, hosts_status)
    LOGGER.debug('Host status, verify_add_hosts:\n {}'.format(dump_hosts))
    testlib.assert_true_within(
        lambda: _single_host_up(hosts_service, total_hosts),
        timeout=constants.ADD_HOST_TIMEOUT)
def _wait_for_engine_health(host):
    logging.info("Waiting for engine to start...")
    testlib.assert_true_within(
        lambda: any(v["engine-status"]["health"] == "good"
                    for k, v in _get_he_status(host).items() if k.isdigit()),
        constants.ENGINE_VM_RESTART_TIMEOUT,
    )

    logging.info("Engine is running.")
Exemple #9
0
def test_verify_add_all_hosts(prefix):
    api = prefix.virt_env.engine_vm().get_api_v4()
    hosts_service = api.system_service().hosts_service()
    total_hosts = len(
        hosts_service.list(search='datacenter={}'.format(DC_NAME)))

    testlib.assert_true_within(
        lambda: host_status_utils._all_hosts_up(hosts_service, total_hosts),
        timeout=constants.ADD_HOST_TIMEOUT)
def wait_engine(prefix):
    def _engine_is_up():
        engine = prefix.virt_env.engine_vm()
        try:
            if engine and engine.get_api():
                return True
        except:
            return

    testlib.assert_true_within(_engine_is_up, timeout=10 * 60)
def wait_engine(prefix):

    def _engine_is_up():
        engine = prefix.virt_env.engine_vm()
        try:
            if engine and engine.get_api():
                return True
        except:
            return

    testlib.assert_true_within(_engine_is_up, timeout=20 * 60)
def wait_engine(prefix):
    def _engine_is_up():
        print('API_V4: %s' % API_V4)
        engine = prefix.virt_env.engine_vm()
        try:
            if engine and engine.get_api_v4():
                return True
        except:
            return

    testlib.assert_true_within(_engine_is_up, timeout=20 * 60)
def verify_add_all_hosts(prefix):
    api = prefix.virt_env.engine_vm().get_api_v4()
    hosts_service = api.system_service().hosts_service()
    total_hosts = hosts_service.list(search='datacenter={}'.format(DC_NAME))

    testlib.assert_true_within(
        lambda: _all_hosts_up(hosts_service, total_hosts), 60 * 60)

    hosts = prefix.virt_env.host_vms()
    for host in hosts:
        host.ssh(['rm', '-rf', '/dev/shm/yum', '/dev/shm/*.rpm'])
Exemple #14
0
def suspend_resume_vm(api):
    nt.assert_true(api.vms.get(VM0_NAME).suspend())

    testlib.assert_true_within_long(
        lambda: api.vms.get(VM0_NAME).status.state == 'suspended')

    nt.assert_true(api.vms.get(VM0_NAME).start())

    # By the time https://bugzilla.redhat.com/show_bug.cgi?id=1503468
    # will be fixed, increase the timeout to 30 minutes
    testlib.assert_true_within(
        lambda: api.vms.get(VM0_NAME).status.state == 'up', timeout=60 * 30)
Exemple #15
0
def verify_add_all_hosts(prefix):
    api = prefix.virt_env.engine_vm().get_api_v4()
    hosts_service = api.system_service().hosts_service()
    total_hosts = hosts_service.list(search='datacenter={}'.format(DC_NAME))

    testlib.assert_true_within(
        lambda: _all_hosts_up(hosts_service, total_hosts),
        timeout=constants.ADD_HOST_TIMEOUT)

    hosts = prefix.virt_env.host_vms()
    for host in hosts:
        host.ssh(['rm', '-rf', '/var/cache/yum.*'])
def verify_add_all_hosts(prefix):
    api = prefix.virt_env.engine_vm().get_api_v4()
    hosts_service = api.system_service().hosts_service()
    total_hosts = hosts_service.list(search='datacenter={}'.format(DC_NAME))

    testlib.assert_true_within(
        lambda: _all_hosts_up(hosts_service, total_hosts),
        timeout=constants.ADD_HOST_TIMEOUT
    )

    hosts = prefix.virt_env.host_vms()
    for host in hosts:
        host.ssh(['rm', '-rf', '/dev/shm/yum', '/dev/shm/*.rpm'])
def verify_add_hosts_3(api, hosts):
    def _host_is_up():
        cur_state = api.hosts.get(host.name()).status.state

        if cur_state == 'up':
            return True

        if cur_state == 'install_failed':
            raise RuntimeError('Host %s failed to install' % host.name())
        if cur_state == 'non_operational':
            raise RuntimeError('Host %s is in non operational state' % host.name())

    for host in hosts:
        testlib.assert_true_within(_host_is_up, timeout=constants.ADD_HOST_TIMEOUT)
def verify_add_hosts_3(api, hosts):
    def _host_is_up():
        cur_state = api.hosts.get(host.name()).status.state

        if cur_state == 'up':
            return True

        if cur_state == 'install_failed':
            raise RuntimeError('Host %s failed to install' % host.name())
        if cur_state == 'non_operational':
            raise RuntimeError('Host %s is in non operational state' % host.name())

    for host in hosts:
        testlib.assert_true_within(_host_is_up, timeout=constants.ADD_HOST_TIMEOUT)
def add_hosts(prefix):
    api = prefix.virt_env.engine_vm().get_api_v4()
    hosts_service = api.system_service().hosts_service()

    def _add_host_4(vm):
        return hosts_service.add(
            sdk4.types.Host(
                name=vm.name(),
                description='host %s' % vm.name(),
                address=vm.name(),
                root_password=str(vm.root_password()),
                override_iptables=True,
                cluster=sdk4.types.Cluster(
                    name=CLUSTER_NAME,
                ),
            ),
        )

    def _host_is_up_4():
        host_service = hosts_service.host_service(api_host.id)
        host_obj = host_service.get()

        if host_obj.status == sdk4.types.HostStatus.INSTALLING:
            return False

        if host_obj.status == sdk4.types.HostStatus.UP:
            return True

        if host_obj.status == sdk4.types.HostStatus.NON_OPERATIONAL:
            raise RuntimeError('Host %s is in non operational state' %
                               api_host.name)
        if host_obj.status == sdk4.types.HostStatus.INSTALL_FAILED:
            raise RuntimeError('Host %s installation failed' % api_host.name)
        if host_obj.status == sdk4.types.HostStatus.NON_RESPONSIVE:
            raise RuntimeError('Host %s is in non responsive state' %
                               api_host.name)

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

    api_hosts = hosts_service.list()
    for api_host in api_hosts:
        testlib.assert_true_within(_host_is_up_4, timeout=constants.ADD_HOST_TIMEOUT)

    for host in hosts:
        host.ssh(['rm', '-rf', '/dev/shm/yum', '/dev/shm/*.rpm'])
def suspend_resume_vm(api):
    nt.assert_true(api.vms.get(VM0_NAME).suspend())

    testlib.assert_true_within_long(
        lambda:
        api.vms.get(VM0_NAME).status.state == 'suspended'
    )

    nt.assert_true(api.vms.get(VM0_NAME).start())

    # By the time https://bugzilla.redhat.com/show_bug.cgi?id=1503468
    # will be fixed, increase the timeout to 30 minutes
    testlib.assert_true_within(
        lambda: api.vms.get(VM0_NAME).status.state == 'up',
        timeout=60*30
    )
Exemple #21
0
def add_hosts(prefix):
    api = prefix.virt_env.engine_vm().get_api_v4()
    hosts_service = api.system_service().hosts_service()

    def _add_host_4(vm):
        return hosts_service.add(
            sdk4.types.Host(
                name=vm.name(),
                description='host %s' % vm.name(),
                address=vm.name(),
                root_password=str(vm.root_password()),
                override_iptables=True,
                cluster=sdk4.types.Cluster(name=CLUSTER_NAME, ),
            ), )

    def _host_is_up_4():
        host_service = hosts_service.host_service(api_host.id)
        host_obj = host_service.get()

        if host_obj.status == sdk4.types.HostStatus.INSTALLING:
            return False

        if host_obj.status == sdk4.types.HostStatus.UP:
            return True

        if host_obj.status == sdk4.types.HostStatus.NON_OPERATIONAL:
            raise RuntimeError('Host %s is in non operational state' %
                               api_host.name)
        if host_obj.status == sdk4.types.HostStatus.INSTALL_FAILED:
            raise RuntimeError('Host %s installation failed' % api_host.name)
        if host_obj.status == sdk4.types.HostStatus.NON_RESPONSIVE:
            raise RuntimeError('Host %s is in non responsive state' %
                               api_host.name)

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

    api_hosts = hosts_service.list()
    for api_host in api_hosts:
        testlib.assert_true_within(_host_is_up_4,
                                   timeout=constants.ADD_HOST_TIMEOUT)

    for host in hosts:
        host.ssh(['rm', '-rf', '/dev/shm/yum', '/dev/shm/*.rpm'])
Exemple #22
0
def edit_cluster(prefix):
    def _engine_is_up():
        engine = prefix.virt_env.engine_vm()
        try:
            if engine and engine.get_api():
                return True
        except:
            return

    cpu_family = prefix.virt_env.get_ovirt_cpu_family()
    # TBD: HE takes time to be online,
    # remove this when we figure out why
    testlib.assert_true_within(_engine_is_up, timeout=10 * 60)
    api = prefix.virt_env.engine_vm().get_api()
    cluster = api.clusters.get(name='Default')
    cluster.gluster_service = True
    nt.assert_true(cluster.update())
Exemple #23
0
def assert_finished_within(func,
                           engine,
                           timeout,
                           allowed_exceptions=None,
                           *args,
                           **kwargs):

    if 'query' in kwargs:
        if 'correlation_id' not in kwargs['query']:
            kwargs['query']['correlation_id'] = uuid.uuid4()
    else:
        kwargs['query'] = {'correlation_id': uuid.uuid4()}

    func(*args, **kwargs)

    testlib.assert_true_within(
        lambda: all_jobs_finished(engine, kwargs['query']['correlation_id']),
        timeout)
def edit_cluster(prefix):

    def _engine_is_up():
        engine = prefix.virt_env.engine_vm()
        try:
            if engine and engine.get_api():
                return True
        except:
            return

    cpu_family = prefix.virt_env.get_ovirt_cpu_family()
    # TBD: HE takes time to be online,
    # remove this when we figure out why
    testlib.assert_true_within(_engine_is_up, timeout=10 * 60)
    api = prefix.virt_env.engine_vm().get_api()
    cluster = api.clusters.get(name='Default')
    cluster.gluster_service = True
    nt.assert_true(
        cluster.update()
    )
Exemple #25
0
def assert_finished_within(
    func,
    engine,
    timeout,
    allowed_exceptions=None,
    *args,
    **kwargs
):

    if 'query' in kwargs:
        if 'correlation_id' not in kwargs['query']:
            kwargs['query']['correlation_id'] = uuid.uuid4()
    else:
        kwargs['query'] = {'correlation_id': uuid.uuid4()}

    func(*args, **kwargs)

    testlib.assert_true_within(
        lambda: all_jobs_finished(engine, kwargs['query']['correlation_id']),
        timeout
    )
Exemple #26
0
def wait_hosts(prefix):
    api = prefix.virt_env.engine_vm().get_api_v4()
    hosts_service = api.system_service().hosts_service()

    def _host_is_up():
        host_service = hosts_service.host_service(api_host.id)
        host_obj = host_service.get()
        if host_obj.status == sdk4.types.HostStatus.UP:
            return True

        if host_obj.status == sdk4.types.HostStatus.NON_OPERATIONAL:
            raise RuntimeError('Host %s is in non operational state' %
                               api_host.name)
        if host_obj.status == sdk4.types.HostStatus.INSTALL_FAILED:
            raise RuntimeError('Host %s installation failed' % api_host.name)
        if host_obj.status == sdk4.types.HostStatus.NON_RESPONSIVE:
            raise RuntimeError('Host %s is in non responsive state' %
                               api_host.name)

    api_hosts = hosts_service.list()
    nt.assert_equals(len(api_hosts), 3)
    for api_host in api_hosts:
        testlib.assert_true_within(_host_is_up, timeout=15 * 60)
def add_vm_template(api):
    sds = api.system_service().storage_domains_service()
    sd = sds.list(search='name=ovirt-image-repository')[0]
    sd_service = sds.storage_domain_service(sd.id)
    images_service = sd_service.images_service()
    images = images_service.list()

    image = next(
        (i for i in images if i.name == GLANCE_IMAGE_TO_IMPORT),
        None
    )

    # Find the service that manages the image that we found in the previous
    # step:
    image_service = images_service.image_service(image.id)

    # Import the image:
    image_service.import_(
        import_as_template=True,
        template=sdk4.types.Template(
            name=VM_TEMPLATE
        ),
        cluster=sdk4.types.Cluster(
            name=CLUSTER_NAME
        ),
        storage_domain=sdk4.types.StorageDomain(
            name=SD_NFS_NAME
        )
    )

    templates_service = api.system_service().templates_service()
    getTemplate = lambda: templates_service.list(search="name=%s" % VM_TEMPLATE)
    testlib.assert_true_within(
        lambda: len(getTemplate()) == 1 and
                sdk4.types.TemplateStatus.OK == getTemplate()[0].status,
        timeout=300
    )
Exemple #28
0
def verify_suspend_resume_vm(api):
    testlib.assert_true_within(
        func=lambda: api.vms.get(VM0_NAME).status.state == 'up',
        timeout=20 * 60)
def verify_add_hosts_4(api):
    hosts_service = api.system_service().hosts_service()
    total_hosts = hosts_service.list(search='datacenter={}'.format(DC_NAME))

    testlib.assert_true_within(
        lambda: _single_host_up(hosts_service, total_hosts), 60 * 60)
def verify_suspend_resume_vm0(api):
    # By the time https://bugzilla.redhat.com/show_bug.cgi?id=1503468
    # will be fixed, increase the timeout to 30 minutes
    testlib.assert_true_within(
        lambda: api.vms.get(VM0_NAME).status.state == 'up', timeout=60 * 30)