Пример #1
0
    def status(self):
        api = self.get_api_v4(check=True)
        sys_service = api.system_service().get()
        info = {'global': {}, 'items': {}}

        info['global']['version'] = \
            sys_service.product_info.version.full_version
        info['global']['web_ui'] = OrderedDict(
            [
                ('url', self.ip()),
                ('username', self.username),
                ('password', self.password),
            ]
        )

        for k, v in vars(sys_service.summary).viewitems():
            if isinstance(v, otypes.ApiSummaryItem):
                info['items'][k.lstrip('_')] = OrderedDict(
                    [
                        ('total', v.total),
                        ('active', v.active),
                    ]
                )

        return info
Пример #2
0
    def stop_all_hosts(self):
        api = self.get_api_v4(check=True)
        hosts_service = api.system_service().hosts_service()
        hosts = hosts_service.list(search='status=up')
        if hosts:
            self.stop_all_vms()
            for h in hosts:
                host_service = hosts_service.host_service(h.id)
                host_service.deactivate()
            time.sleep(10)

            def _host_is_maint():
                h_service = hosts_service.host_service(h.id)
                host_obj = h_service.get()
                if host_obj.status == sdk4.types.HostStatus.MAINTENANCE:
                    return True
                if host_obj.status == sdk4.types.HostStatus.NON_OPERATIONAL:
                    raise RuntimeError('Host %s is in non operational state' %
                                       h.name)
                elif host_obj.status == sdk4.types.HostStatus.INSTALL_FAILED:
                    raise RuntimeError('Host %s installation failed' % h.name)
                elif host_obj.status == sdk4.types.HostStatus.NON_RESPONSIVE:
                    raise RuntimeError('Host %s is in non responsive state' %
                                       h.name)

            for h in hosts:
                testlib.assert_true_within(_host_is_maint, timeout=5 * 60)
Пример #3
0
    def status(self):
        api = self.get_api_v4(check=True)
        sys_service = api.system_service().get()
        info = {'global': {}, 'items': {}}

        info['global']['version'] = \
            sys_service.product_info.version.full_version
        info['global']['web_ui'] = OrderedDict(
            [
                ('url', self.ip()),
                ('username', self.username),
                ('password', self.password),
            ]
        )

        for k, v in vars(sys_service.summary).viewitems():
            if isinstance(v, otypes.ApiSummaryItem):
                info['items'][k.lstrip('_')] = OrderedDict(
                    [
                        ('total', v.total),
                        ('active', v.active),
                    ]
                )

        return info
Пример #4
0
    def start_all_hosts(self, timeout=5 * 60):
        api = self.get_api_v4(check=True)
        hosts_service = api.system_service().hosts_service()
        hosts = hosts_service.list(search='status=maintenance')
        if hosts:

            def _host_is_up(host):
                h_service = hosts_service.host_service(host.id)
                host_obj = h_service.get()
                if host_obj.status == otypes.HostStatus.UP:
                    return True

                if host_obj.status == otypes.HostStatus.NON_OPERATIONAL:
                    raise RuntimeError('Host %s is in non operational state' %
                                       host.name)
                elif host_obj.status == otypes.HostStatus.INSTALL_FAILED:
                    raise RuntimeError('Host %s installation failed' %
                                       host.name)

            for host in hosts:
                host_service = hosts_service.host_service(host.id)
                host_service.activate()

            for host in hosts:
                testlib.assert_true_within(partial(_host_is_up, host),
                                           timeout=timeout)
Пример #5
0
    def update_clusters_cpu(self, timeout=2 * 60):
        cpu_family = self.get_ovirt_cpu_family()
        api = self.engine_vm().get_api_v4(check=True)
        clusters_service = api.system_service().clusters_service()
        clusters = clusters_service.list()

        if clusters is None:
            LOGGER.debug('no clusters found: skipping')
            return

        for cluster in clusters:
            if cluster.cpu.type == cpu_family:
                continue
            LOGGER.debug(
                ('found CPU cluster mismatch, current: {0}, required: '
                 '{1}').format(cluster.cpu.type, cpu_family))

            cluster_service = clusters_service.cluster_service(cluster.id)
            cluster_service.update(
                otypes.Cluster(cpu=otypes.Cpu(type=cpu_family)))

            def _assert_cluster_cpu(cluster):
                cluster = clusters_service.cluster_service(cluster.id).get()
                return cluster.cpu.type == cpu_family

            testlib.assert_true_within(partial(_assert_cluster_cpu, cluster),
                                       timeout=timeout)
            LOGGER.debug(('successfuly changed cluster id {0} to cpu family: '
                          '{1}').format(cluster.id, cpu_family))
Пример #6
0
    def status(self):
        api = self.get_api_v4(check=True)

        sys_service = api.system_service().get()
        print("Version: %s" % sys_service.product_info.version.full_version)
        print("Hosts: %d" % sys_service.summary.hosts.total)
        print("SDs: %d" % sys_service.summary.storage_domains.total)
        print("Users: %d" % sys_service.summary.users.total)
        print("Vms: %d" % sys_service.summary.vms.total)
Пример #7
0
    def stop_all_vms(self):
        api = self.get_api_v4(check=True)
        vms_service = api.system_service().vms_service()
        ids = self._search_vms(api, query='status=up')
        [vms_service.vm_service(id).stop() for id in ids]

        def _vm_is_down(id):
            vm_srv = vms_service.vm_service(id)
            vm = vm_srv.get()
            if vm.status == sdk4.types.VmStatus.DOWN:
                LOGGER.debug('Engine VM ID %s, is down', id)
                return True

        for id in ids:
            testlib.assert_true_within(functools.partial(_vm_is_down, id=id),
                                       timeout=5 * 60)
Пример #8
0
    def check_sds_status(self, status=None, timeout=5 * 60):
        # the default status cannot be used in the function header, because
        # the v4 sdk might not be available.
        if status is None:
            status = otypes.StorageDomainStatus.ACTIVE
        api = self.get_api_v4(check=True)
        dcs_service = api.system_service().data_centers_service()
        for dc in dcs_service.list():

            def _sds_state(dc_id):
                dc_service = dcs_service.data_center_service(dc_id)
                sds = dc_service.storage_domains_service()
                return all(sd.status == status for sd in sds.list())

            testlib.assert_true_within(partial(_sds_state, dc_id=dc.id),
                                       timeout=timeout)
Пример #9
0
    def start_all_vms(self, timeout=8 * 60):
        api = self.get_api_v4(check=True)
        vms_service = api.system_service().vms_service()
        ids = self._search_vms(api, query='status=down')
        [vms_service.vm_service(id).start() for id in ids]

        def _vm_is_up(id):
            vm_srv = vms_service.vm_service(id)
            vm = vm_srv.get()
            if vm.status == otypes.VmStatus.UP:
                LOGGER.debug('Engine VM ID %s, is UP', id)
                return True

        for id in ids:
            testlib.assert_true_within(partial(_vm_is_up, id=id),
                                       timeout=timeout)
Пример #10
0
    def stop_all_vms(self, timeout=5 * 60):
        api = self.get_api_v4(check=True)
        vms_service = api.system_service().vms_service()
        ids = self._search_vms(vms_service,
                               query='status=up and name!=HostedEngine')
        [vms_service.vm_service(id).stop() for id in ids]

        def _vm_is_down(srv, id):
            vm = srv.get()
            if vm.status == otypes.VmStatus.DOWN:
                LOGGER.debug('Engine VM ID %s, is down', id)
                return True

        for id in ids:
            vm_srv = vms_service.vm_service(id)
            testlib.assert_true_within(partial(_vm_is_down, srv=vm_srv, id=id),
                                       timeout=timeout)
Пример #11
0
 def get_api_v4_system_service(self):
     api = self.get_api_v4(False)
     return api.system_service()
Пример #12
0
 def _search_vms(self, api, query):
     vms_service = api.system_service().vms_service()
     return [vm.id for vm in vms_service.list(search=query)]
Пример #13
0
 def get_api_v4_system_service(self):
     api = self.get_api_v4(False)
     return api.system_service()