def assign_hosts_network_label(api): """ Assigns NETWORK_LABEL to first network interface of every host in cluster """ engine = api.system_service() def _assign_host_network_label(host): host_service = engine.hosts_service().host_service(id=host.id) nics_service = host_service.nics_service() nics = sorted(nics_service.list(), key=lambda n: n.name) nt.assert_greater_equal(len(nics), 1) nic = nics[0] nic_service = nics_service.nic_service(id=nic.id) labels_service = nic_service.network_labels_service() return labels_service.add( NetworkLabel( id=NETWORK_LABEL, host_nic=nic ) ) hosts = test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME) vec = utils.func_vector(_assign_host_network_label, [(h,) for h in hosts]) vt = utils.VectorThread(vec) vt.start_all() nt.assert_true(all(vt.join_all()))
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, )
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 install_cockpit_ovirt(prefix): def _install_cockpit_ovirt_on_host(host): ret = host.ssh(['yum', '-y', 'install', 'cockpit-ovirt-dashboard']) nt.assert_equals(ret.code, 0, '_install_cockpit_ovirt_on_host(): failed to install cockpit-ovirt-dashboard on host %s' % host) return True hosts = prefix.virt_env.host_vms() vec = utils.func_vector(_install_cockpit_ovirt_on_host, [(h,) for h in hosts]) vt = utils.VectorThread(vec) vt.start_all() nt.assert_true(all(vt.join_all()), 'not all threads finished: %s' % vt)
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 assign_hosts_network_label(api): """ Assigns NETWORK_LABEL to first network interface of every host in cluster """ def _assign_host_network_label(host): nics = host.nics.list() nt.assert_greater_equal(len(nics), 1) nic = nics[0] return nic.labels.add(params.Label(id=NETWORK_LABEL, host_nic=nic)) hosts = _hosts_in_cluster(CLUSTER_NAME) vec = utils.func_vector(_assign_host_network_label, [(h, ) for h in hosts]) vt = utils.VectorThread(vec) vt.start_all() nt.assert_true(all(vt.join_all()))
def add_hosts_3(api, hosts): 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) 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()))
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 add_hosts_3(api, hosts): 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) 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()))
def assign_hosts_network_label(api): """ Assigns NETWORK_LABEL to first network interface of every host in cluster """ def _assign_host_network_label(host): nics = sorted(host.nics.list(), key=lambda n: n.get_name()) nt.assert_greater_equal(len(nics), 1) nic = nics[0] return nic.labels.add( params.Label( id=NETWORK_LABEL, host_nic=nic ) ) hosts = test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME) vec = utils.func_vector(_assign_host_network_label, [(h,) for h in hosts]) vt = utils.VectorThread(vec) vt.start_all() nt.assert_true(all(vt.join_all()))
def do_engine_setup(prefix, answer_file=None, **kwargs): engine = prefix.virt_env.engine_vm() answer_file_src = os.path.join(CURDIR, 'answer-files', 'default.conf') if answer_file is not None: answer_file_src = answer_file engine.copy_to(answer_file_src, '/tmp/answer-file') with LogTask('Run engine-setup'): result = engine.ssh( ['engine-setup', '--config-append=/tmp/answer-file']) if result.code != 0: raise RuntimeError('Failed to run engine-setup') engine.ssh( ['rm', '-rf', '/dev/shm/yum', '/dev/shm/yumdb', '/dev/shm/*.rpm']) engine.ssh(['systemctl', 'stop', 'firewalld']) with LogTask('Configuring hosts'): 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='Default', ), root_password=vm.root_password(), override_iptables=True, ) return api.hosts.add(p) hosts = prefix.virt_env.host_vms() vec = func_vector(_add_host, [(h, ) for h in hosts]) vt = VectorThread(vec) vt.start_all() vt.join_all() for host in hosts: host.ssh(['rm', '-rf', '/dev/shm/yum', '/dev/shm/*.rpm'])