def session_multihost(request): """Multihost plugin fixture for session scope""" if pytest.num_ad > 0: mh = make_multihost_fixture( request, descriptions=[ { 'type': 'sssd', 'hosts': { 'master': pytest.num_masters, 'atomic': pytest.num_atomic, 'replica': pytest.num_replicas, 'client': pytest.num_clients, 'other': pytest.num_others, } }, { 'type': 'ad', 'hosts': { 'ad': pytest.num_ad, }, }, ], config_class=QeConfig, ) else: mh = make_multihost_fixture( request, descriptions=[ { 'type': 'sssd', 'hosts': { 'master': pytest.num_masters, 'atomic': pytest.num_atomic, 'replica': pytest.num_replicas, 'client': pytest.num_clients, 'other': pytest.num_others, } }, ], config_class=QeConfig, ) mh.domain = mh.config.domains[0] mh.master = mh.domain.hosts_by_role('master') mh.atomic = mh.domain.hosts_by_role('atomic') mh.replica = mh.domain.hosts_by_role('replica') mh.client = mh.domain.hosts_by_role('client') mh.others = mh.domain.hosts_by_role('other') if pytest.num_ad > 0: mh.ad = [] for i in range(1, pytest.num_ad + 1): print(i) print(mh.config.domains[i].hosts_by_role('ad')) mh.ad.extend(mh.config.domains[i].hosts_by_role('ad')) yield mh
def mh(request, class_integration_logs): """IPA's multihost fixture object """ cls = request.cls domain_description = { 'type': 'IPA', 'hosts': { 'master': 1, 'replica': cls.num_replicas, 'client': cls.num_clients, }, } domain_description['hosts'].update( {role: 1 for role in cls.required_extra_roles}) domain_descriptions = [domain_description] for _i in range(cls.num_ad_domains): domain_descriptions.append({ 'type': 'AD', 'hosts': {'ad': 1, 'ad_subdomain': 1, 'ad_treedomain': 1}, }) mh = make_multihost_fixture( request, domain_descriptions, config_class=Config, _config=get_global_config(), ) mh.domain = mh.config.domains[0] [mh.master] = mh.domain.hosts_by_role('master') mh.replicas = mh.domain.hosts_by_role('replica') mh.clients = mh.domain.hosts_by_role('client') cls.logs_to_collect = class_integration_logs def collect_log(host, filename): logger.info('Adding %s:%s to list of logs to collect', host.external_hostname, filename) class_integration_logs.setdefault(host, []).append(filename) print(mh.config) for host in mh.config.get_all_hosts(): host.add_log_collector(collect_log) logger.info('Preparing host %s', host.hostname) tasks.prepare_host(host) setup_class(cls, mh) mh._pytestmh_request.addfinalizer(lambda: teardown_class(cls)) yield mh.install() for host in cls.get_all_hosts(): host.remove_log_collector(collect_log) collect_test_logs(request.node, class_integration_logs, request.config)
def mh(request, class_integration_logs): """IPA's multihost fixture object """ cls = request.cls domain_description = { 'type': 'IPA', 'hosts': { 'master': 1, 'replica': cls.num_replicas, 'client': cls.num_clients, }, } domain_description['hosts'].update( {role: 1 for role in cls.required_extra_roles}) domain_descriptions = [domain_description] for _i in range(cls.num_ad_domains): domain_descriptions.append({ 'type': 'AD', 'hosts': {'ad': 1, 'ad_subdomain': 1}, }) mh = make_multihost_fixture( request, domain_descriptions, config_class=Config, _config=get_global_config(), ) mh.domain = mh.config.domains[0] [mh.master] = mh.domain.hosts_by_role('master') mh.replicas = mh.domain.hosts_by_role('replica') mh.clients = mh.domain.hosts_by_role('client') cls.logs_to_collect = class_integration_logs def collect_log(host, filename): log.info('Adding %s:%s to list of logs to collect' % (host.external_hostname, filename)) class_integration_logs.setdefault(host, []).append(filename) print(mh.config) for host in mh.config.get_all_hosts(): host.add_log_collector(collect_log) cls.log.info('Preparing host %s', host.hostname) tasks.prepare_host(host) setup_class(cls, mh) mh._pytestmh_request.addfinalizer(lambda: teardown_class(cls)) yield mh.install() for host in cls.get_all_hosts(): host.remove_log_collector(collect_log) collect_test_logs(request.node, class_integration_logs, request.config)
def multihost(request): conf = get_conf_dict() mh = pytest_multihost.make_multihost_fixture( request, descriptions=[ { 'hosts': { 'local': 1, }, }, ], _config=Config.from_dict(conf), ) assert conf == get_conf_dict() mh.host = mh.config.domains[0].hosts[0] return mh.install()
def multihost_baduser(request, transport_class): conf = get_conf_dict() mh = pytest_multihost.make_multihost_fixture( request, descriptions=[ { 'hosts': { 'badusername': 1, }, }, ], _config=Config.from_dict(conf), ) mh.host = mh.config.domains[0].hosts[0] mh.host.transport_class = transport_class return mh.install()
def multihost(request, transport_class): conf = get_conf_dict() mh = pytest_multihost.make_multihost_fixture( request, descriptions=[ { 'hosts': { 'local': 1, }, }, ], _config=Config.from_dict(conf), ) assert conf == get_conf_dict() mh.host = mh.config.domains[0].hosts[0] mh.host.transport_class = transport_class assert isinstance(mh.host.transport, transport_class) return mh.install()
def session_multihost(request): mh = make_multihost_fixture( request, descriptions = [ { 'type': 'cs', 'hosts': { 'master': 1, 'clone' : 1 } }, ], config_class=QeConfig) mh.domain = mh.config.domains[0] [mh.master] = mh.domain.hosts_by_role('master') [mh.clone] = mh.domain.hosts_by_role('clone') return mh
def mh(request, class_integration_logs): """IPA's multihost fixture object """ cls = request.cls domain_description = { 'type': 'IPA', 'hosts': { 'master': 1, 'replica': cls.num_replicas, 'client': cls.num_clients, }, } domain_description['hosts'].update( {role: 1 for role in cls.required_extra_roles}) domain_descriptions = [domain_description] for _i in range(cls.num_ad_domains): domain_descriptions.append({ 'type': 'AD', 'hosts': {'ad': 1} }) for _i in range(cls.num_ad_subdomains): domain_descriptions.append({ 'type': 'AD_SUBDOMAIN', 'hosts': {'ad_subdomain': 1} }) for _i in range(cls.num_ad_treedomains): domain_descriptions.append({ 'type': 'AD_TREEDOMAIN', 'hosts': {'ad_treedomain': 1} }) mh = make_multihost_fixture( request, domain_descriptions, config_class=Config, _config=get_global_config(), ) mh.domain = mh.config.domains[0] [mh.master] = mh.domain.hosts_by_role('master') mh.replicas = mh.domain.hosts_by_role('replica') mh.clients = mh.domain.hosts_by_role('client') ad_domains = mh.config.ad_domains if ad_domains: mh.ads = [] for domain in ad_domains: mh.ads.extend(domain.hosts_by_role('ad')) mh.ad_subdomains = [] for domain in ad_domains: mh.ad_subdomains.extend(domain.hosts_by_role('ad_subdomain')) mh.ad_treedomains = [] for domain in ad_domains: mh.ad_treedomains.extend(domain.hosts_by_role('ad_treedomain')) cls.logs_to_collect = class_integration_logs.class_logs if logger.isEnabledFor(logging.INFO): logger.info(pformat(mh.config.to_dict())) for ipa_host in mh.config.get_all_ipa_hosts(): class_integration_logs.set_logs(ipa_host, make_class_logs(ipa_host)) for host in mh.config.get_all_hosts(): logger.info('Preparing host %s', host.hostname) tasks.prepare_host(host) add_compat_attrs(cls, mh) def fin(): del_compat_attrs(cls) mh._pytestmh_request.addfinalizer(fin) try: yield mh.install() finally: # the 'mh' fixture depends on 'class_integration_logs' one, # thus, the class logs collecting happens *after* the teardown # of 'mh' fixture. The 'uninstall' is among the finalizers of 'mh'. # This means that the logs collected here are the IPA *uninstall* # logs and the 'install' ones can be removed during the IPA # uninstall phase. To address this problem(e.g. installation error) # the install logs will be collected into '{nodeid}-install' directory # while the uninstall ones into '{nodeid}-uninstall'. class_logs = class_integration_logs.class_logs collect_test_logs(request.node, class_logs, request.config, suffix='-install')
def mh(request, class_integration_logs): """IPA's multihost fixture object """ cls = request.cls domain_description = { 'type': 'IPA', 'hosts': { 'master': 1, 'replica': cls.num_replicas, 'client': cls.num_clients, }, } domain_description['hosts'].update( {role: 1 for role in cls.required_extra_roles}) domain_descriptions = [domain_description] for _i in range(cls.num_ad_domains): domain_descriptions.append({'type': 'AD', 'hosts': {'ad': 1}}) for _i in range(cls.num_ad_subdomains): domain_descriptions.append({ 'type': 'AD_SUBDOMAIN', 'hosts': { 'ad_subdomain': 1 } }) for _i in range(cls.num_ad_treedomains): domain_descriptions.append({ 'type': 'AD_TREEDOMAIN', 'hosts': { 'ad_treedomain': 1 } }) mh = make_multihost_fixture( request, domain_descriptions, config_class=Config, _config=get_global_config(), ) mh.domain = mh.config.domains[0] [mh.master] = mh.domain.hosts_by_role('master') mh.replicas = mh.domain.hosts_by_role('replica') mh.clients = mh.domain.hosts_by_role('client') ad_domains = mh.config.ad_domains if ad_domains: mh.ads = [] for domain in ad_domains: mh.ads.extend(domain.hosts_by_role('ad')) mh.ad_subdomains = [] for domain in ad_domains: mh.ad_subdomains.extend(domain.hosts_by_role('ad_subdomain')) mh.ad_treedomains = [] for domain in ad_domains: mh.ad_treedomains.extend(domain.hosts_by_role('ad_treedomain')) cls.logs_to_collect = class_integration_logs def collect_log(host, filename): logger.info('Adding %s:%s to list of logs to collect', host.external_hostname, filename) class_integration_logs.setdefault(host, []).append(filename) print(mh.config) for host in mh.config.get_all_hosts(): host.add_log_collector(collect_log) logger.info('Preparing host %s', host.hostname) tasks.prepare_host(host) add_compat_attrs(cls, mh) def fin(): del_compat_attrs(cls) mh._pytestmh_request.addfinalizer(fin) try: yield mh.install() finally: hosts = list(cls.get_all_hosts()) for host in hosts: host.remove_log_collector(collect_log) collect_test_logs(request.node, class_integration_logs, request.config) collect_systemd_journal(request.node, hosts, request.config)