def test_get_methods(self, parse_from, method, tmpdir, caplog, monkeypatch): if parse_from == 'raw': conf = Configuration(raw_config=yaml.safe_load(REACTOR_CONFIG_MAP)) elif parse_from == 'env': monkeypatch.setenv(REACTOR_CONFIG_ENV_NAME, dedent(REACTOR_CONFIG_MAP)) conf = Configuration(env_name=REACTOR_CONFIG_ENV_NAME) elif parse_from == 'file': filename = str(tmpdir.join('config.yaml')) with open(filename, 'w') as fp: fp.write(dedent(REACTOR_CONFIG_MAP)) conf = Configuration(config_path=filename) real_attr = getattr(conf, method) output = real_attr reactor_config_map = yaml.safe_load(REACTOR_CONFIG_MAP) if method == 'registry': expected = reactor_config_map['registry'] else: expected = reactor_config_map[method] if method == 'registry': # since there will only be exactly one registry registry = expected reguri = RegistryURI(registry.get('url')) regdict = {'uri': reguri.docker_uri, 'version': reguri.version} regdict['secret'] = reactor_config_map['registries_cfg_path'] regdict['insecure'] = registry.get('insecure', False) regdict['expected_media_types'] = registry.get( 'expected_media_types', []) assert output == regdict return if method == 'source_registry': expect = { 'uri': RegistryURI(expected['url']), 'insecure': expected.get('insecure', False) } assert output['insecure'] == expect['insecure'] assert output['uri'].uri == expect['uri'].uri return assert output == expected os.environ.pop(REACTOR_CONFIG_ENV_NAME, None) if parse_from == 'raw': log_msg = "reading config from raw_config kwarg" elif parse_from == 'env': log_msg = f"reading config from {REACTOR_CONFIG_ENV_NAME} env variable" elif parse_from == 'file': log_msg = f"reading config from {filename}" assert log_msg in caplog.text
def test_odcs_config_invalid_default_signing_intent(self, tmpdir): config = """\ odcs: signing_intents: - name: release keys: [R123] - name: beta keys: [R123, B456] - name: unsigned keys: [] default_signing_intent: spam api_url: http://odcs.example.com auth: ssl_certs_dir: /var/run/secrets/atomic-reactor/odcssecret """ config += "\n" + REQUIRED_CONFIG filename = str(tmpdir.join('config.yaml')) with open(filename, 'w') as fp: fp.write(dedent(config)) conf = Configuration(config_path=filename) with pytest.raises(ValueError) as exc_info: getattr(conf, 'odcs_config') message = str(exc_info.value) assert message == dedent("""\ unknown signing intent name "spam", valid names: unsigned, beta, release """.rstrip())
def test_run_ok(self, tmpdir, workflow, source_dir): workflow.data.plugin_failed = True receivers = ['*****@*****.**', '*****@*****.**'] dockerfile = source_dir / DOCKERFILE_FILENAME dockerfile.write_text(MOCK_DOCKERFILE, "utf-8") flexmock(workflow, df_path=str(dockerfile)) mock_store_metadata_results(workflow) smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.bar.com', } rcm = {'version': 1, 'smtp': smtp_map, 'openshift': {'url': 'https://something.com'}} workflow.conf = Configuration(raw_config=rcm) add_koji_map_in_workflow(workflow, hub_url='/', root_url='', ssl_certs_dir='/certs') p = SendMailPlugin(workflow, from_address='*****@*****.**', smtp_host='smtp.spam.com', send_on=[]) (flexmock(p).should_receive('_should_send') .with_args(False, False).and_return(True)) flexmock(p).should_receive('_get_receivers_list').and_return(receivers) flexmock(p).should_receive('_send_mail').with_args(receivers, str, str, None) p.run()
def test_get_koji_session(self, config, raise_error): required_config = """\ version: 1 source_registry: url: source_registry.com registries: - url: registry_url openshift: url: openshift_url """ config += "\n" + required_config if raise_error: with pytest.raises(Exception): read_yaml(config, 'schemas/config.json') return config_json = read_yaml(config, 'schemas/config.json') auth_info = { "proxyuser": config_json['koji']['auth'].get('proxyuser'), "ssl_certs_dir": config_json['koji']['auth'].get('ssl_certs_dir'), "krb_principal": config_json['koji']['auth'].get('krb_principal'), "krb_keytab": config_json['koji']['auth'].get('krb_keytab_path') } use_fast_upload = config_json['koji'].get('use_fast_upload', True) conf = Configuration(raw_config=config_json) (flexmock(atomic_reactor.utils.koji).should_receive( 'create_koji_session').with_args( config_json['koji']['hub_url'], auth_info, use_fast_upload).once().and_return(True)) get_koji_session(conf)
def test_get_registry(self, config, exc): required_config = dedent("""\ version: 1 koji: hub_url: / root_url: '' auth: {} openshift: url: openshift_url source_registry: url: source_registry.com """) config += "\n" + required_config config_json = read_yaml(config, 'schemas/config.json') expected = { 'uri': 'container-registry.example.com', 'insecure': False, 'expected_media_types': [], 'version': 'v2', } if 'registries_cfg_path' in config: expected[ 'secret'] = '/var/run/secrets/atomic-reactor/v2-registry-dockercfg' conf = Configuration(raw_config=config_json) if exc is None: assert conf.registry == expected else: with exc: getattr(conf, 'registry')
def test_get_email_from_koji_obj(self, has_kerberos, email_domain, expected_email, workflow): session = MockedClientSession('', has_kerberos=has_kerberos) flexmock(koji, ClientSession=lambda hub, opts: session) workflow.data.postbuild_results[KojiImportPlugin.key] = MOCK_KOJI_BUILD_ID smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.bar.com', 'domain': email_domain, } rcm = {'version': 1, 'smtp': smtp_map, 'openshift': {'url': 'https://something.com'}} workflow.conf = Configuration(raw_config=rcm) add_koji_map_in_workflow(workflow, hub_url='/', root_url='', ssl_certs_dir='/certs') p = SendMailPlugin(workflow, email_domain=email_domain) koji_task_owner = get_koji_task_owner(p.session, p.koji_task_id) try: found_email = p._get_email_from_koji_obj(koji_task_owner) assert expected_email == found_email except RuntimeError as exc: if not email_domain: assert str(exc) == "Empty email_domain specified" else: assert str(exc) == "Koji task owner name is missing"
def test_update_dockerfile_images_from_config(self, tmp_path, images_exist, organization): config = REQUIRED_CONFIG if organization: config += "\nregistries_organization: " + organization config_yaml = tmp_path / 'config.yaml' config_yaml.write_text(dedent(config), "utf-8") if images_exist: parent_images = ['parent:latest', 'base:latest'] if organization: expect_images = [ImageName.parse('source_registry.com/organization/base:latest'), ImageName.parse('source_registry.com/organization/parent:latest')] else: expect_images = [ImageName.parse('source_registry.com/base:latest'), ImageName.parse('source_registry.com/parent:latest')] else: parent_images = [] dockerfile_images = DockerfileImages(parent_images) conf = Configuration(config_path=str(config_yaml)) conf.update_dockerfile_images_from_config(dockerfile_images) if images_exist: assert len(dockerfile_images) == 2 assert dockerfile_images.keys() == expect_images else: assert not dockerfile_images
def test_run_ok_and_send(self, workflow): workflow.data.plugin_failed = True class SMTP(object): def sendmail(self, from_addr, to, msg): pass def quit(self): pass smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.spam.com', } rcm = {'version': 1, 'smtp': smtp_map, 'openshift': {'url': 'https://something.com'}} workflow.conf = Configuration(raw_config=rcm) add_koji_map_in_workflow(workflow, hub_url='/', root_url='', ssl_certs_dir='/certs') receivers = ['*****@*****.**', '*****@*****.**'] p = SendMailPlugin(workflow, from_address='*****@*****.**', smtp_host='smtp.spam.com', send_on=[]) (flexmock(p).should_receive('_should_send') .with_args(False, False).and_return(True)) flexmock(p).should_receive('_get_receivers_list').and_return(receivers) flexmock(p).should_receive('_get_image_name_and_repos').and_return(('foobar', ['foo/bar:baz', 'foo/bar:spam'])) smtp_inst = SMTP() flexmock(smtplib).should_receive('SMTP').and_return(smtp_inst) p.run()
def test_odcs_config_deprecated_signing_intent(self, tmpdir, caplog): config = """\ odcs: signing_intents: - name: release keys: [R123] deprecated_keys: [R122] default_signing_intent: release api_url: http://odcs.example.com auth: ssl_certs_dir: /var/run/secrets/atomic-reactor/odcssecret """ config += "\n" + REQUIRED_CONFIG filename = str(tmpdir.join('config.yaml')) with open(filename, 'w') as fp: fp.write(dedent(config)) conf = Configuration(config_path=filename) odcs_config = conf.odcs_config signing_intent = odcs_config.get_signing_intent_by_keys(['R123']) assert signing_intent['name'] == 'release' assert 'contain deprecated entries' not in caplog.text signing_intent = odcs_config.get_signing_intent_by_keys( ['R123', 'R122']) assert signing_intent['name'] == 'release' assert 'contain deprecated entries' in caplog.text
def test_get_remote_hosts(self, config, expected_slots_dir, expected_enabled_hosts): config += "\n" + REQUIRED_CONFIG config_json = read_yaml(config, 'schemas/config.json') conf = Configuration(raw_config=config_json) remote_hosts = conf.remote_hosts assert expected_slots_dir == remote_hosts['slots_dir'] pools = remote_hosts['pools'] assert len(pools), 'Remote hosts do not have 2 architectures' assert len( pools['x86_64']) == 2, '2 entries expected for x86_64 architecture' assert sorted(pools['x86_64']) == sorted( ['remote-host1.x86_64', 'remote-host2.x86_64']) assert len( pools['ppc64le']) == 1, '1 entry expected for ppc64le architecture' host1_x86_64 = pools['x86_64']['remote-host1.x86_64'] assert host1_x86_64['auth'] == 'foo', 'Unexpected SSH key path' assert host1_x86_64[ 'socket_path'] == '/user/foo/podman.sock', 'Unexpected socket path' host2_x86_64 = pools['x86_64']['remote-host2.x86_64'] assert host2_x86_64['username'] == 'bar', 'Unexpected user name' host3_ppc64le = pools['ppc64le']['remote-host3.ppc64le'] assert host3_ppc64le['slots'] == 3, 'Unexpected number of slots' for arch in ['x86_64', 'ppc64le']: enabled_hosts = [ host for host, items in pools[arch].items() if items['enabled'] ] assert enabled_hosts == expected_enabled_hosts[arch]
def test_run_invalid_receivers(self, caplog, workflow): workflow.data.plugin_failed = True error_addresses = ['*****@*****.**'] mock_store_metadata_results(workflow) smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.bar.com', 'error_addresses': ['*****@*****.**'], } rcm = {'version': 1, 'smtp': smtp_map, 'openshift': {'url': 'https://something.com'}} workflow.conf = Configuration(raw_config=rcm) add_koji_map_in_workflow(workflow, hub_url='/', root_url='', ssl_certs_dir='/certs') p = SendMailPlugin(workflow, from_address='*****@*****.**', smtp_host='smtp.spam.com', send_on=[], error_addresses=error_addresses) (flexmock(p).should_receive('_should_send') .with_args(False, False).and_return(True)) flexmock(p).should_receive('_get_receivers_list').and_return([]) flexmock(p).should_receive('_get_image_name_and_repos').and_return(('foobar', ['foo/bar:baz', 'foo/bar:spam'])) p.run() assert 'no valid addresses in requested addresses. Doing nothing' in caplog.text
def test_send_mail(self, throws_exception, workflow): smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.bar.com', } rcm = {'version': 1, 'smtp': smtp_map, 'openshift': {'url': 'https://something.com'}} workflow.conf = Configuration(raw_config=rcm) add_koji_map_in_workflow(workflow, hub_url='/', root_url='', ssl_certs_dir='/certs') p = SendMailPlugin(workflow, from_address='*****@*****.**', smtp_host='smtp.spam.com') class SMTP(object): def sendmail(self, from_addr, to, msg): pass def quit(self): pass smtp_inst = SMTP() flexmock(smtplib).should_receive('SMTP').and_return(smtp_inst) sendmail_chain = (flexmock(smtp_inst).should_receive('sendmail'). with_args('*****@*****.**', ['*****@*****.**'], str)) if throws_exception: sendmail_chain.and_raise(smtplib.SMTPException, "foo") flexmock(smtp_inst).should_receive('quit') if throws_exception: with pytest.raises(SMTPException) as e: p._send_mail(['*****@*****.**'], 'subject', 'body') assert str(e.value) == 'foo' else: p._send_mail(['*****@*****.**'], 'subject', 'body')
def test_get_receiver_list(self, additional_addresses, expected_receivers, workflow): session = MockedClientSession('', has_kerberos=True) pathinfo = MockedPathInfo('https://koji') flexmock(koji, ClientSession=lambda hub, opts: session, PathInfo=pathinfo) kwargs = { 'url': 'https://something.com', 'smtp_host': 'smtp.bar.com', 'from_address': '*****@*****.**', 'additional_addresses': additional_addresses } workflow.data.postbuild_results[KojiImportPlugin.key] = MOCK_KOJI_BUILD_ID smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.bar.com', 'send_to_submitter': False, 'send_to_pkg_owner': False, 'additional_addresses': additional_addresses } rcm = {'version': 1, 'smtp': smtp_map, 'openshift': {'url': 'https://something.com'}} workflow.conf = Configuration(raw_config=rcm) add_koji_map_in_workflow(workflow, hub_url=None, root_url='https://koji/', ssl_certs_dir='/certs') p = SendMailPlugin(workflow, **kwargs) if expected_receivers is not None: assert sorted(expected_receivers) == sorted(p._get_receivers_list()) else: with pytest.raises(RuntimeError) as ex: p._get_receivers_list() assert str(ex.value) == 'No recipients found'
def test_run_fails_to_obtain_receivers(self, workflow): MockEnv(workflow).mock_build_outcome(failed=True) error_addresses = ['*****@*****.**'] mock_store_metadata_results(workflow) smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.bar.com', 'error_addresses': ['*****@*****.**'], } rcm = {'version': 1, 'smtp': smtp_map, 'openshift': {'url': 'https://something.com'}} workflow.conf = Configuration(raw_config=rcm) add_koji_map_in_workflow(workflow, hub_url='/', root_url='', ssl_certs_dir='/certs') p = SendMailPlugin(workflow, from_address='*****@*****.**', smtp_host='smtp.spam.com', send_on=[], error_addresses=error_addresses) (flexmock(p).should_receive('_should_send') .with_args(False, False).and_return(True)) flexmock(p).should_receive('_get_receivers_list').and_raise(RuntimeError()) flexmock(p).should_receive('_get_image_name_and_repos').and_return(('foobar', ['foo/bar:baz', 'foo/bar:spam'])) flexmock(p).should_receive('_send_mail').with_args(error_addresses, str, str, None) p.run()
def test_run_ok(self, tmpdir, workflow, source_dir): MockEnv(workflow).mock_build_outcome(failed=True) receivers = ['*****@*****.**', '*****@*****.**'] mock_dockerfile(workflow) mock_store_metadata_results(workflow) smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.bar.com', } rcm = {'version': 1, 'smtp': smtp_map, 'openshift': {'url': 'https://something.com'}} workflow.conf = Configuration(raw_config=rcm) add_koji_map_in_workflow(workflow, hub_url='/', root_url='', ssl_certs_dir='/certs') p = SendMailPlugin(workflow, from_address='*****@*****.**', smtp_host='smtp.spam.com', send_on=[]) (flexmock(p).should_receive('_should_send') .with_args(False, False).and_return(True)) flexmock(p).should_receive('_get_receivers_list').and_return(receivers) flexmock(p).should_receive('_send_mail').with_args(receivers, str, str, None) p.run()
def test_failed_logs(self, workflow, source_dir, error_type): # just test a random combination of the method inputs and hope it's ok for other # combinations session = MockedClientSession('', has_kerberos=True) pathinfo = MockedPathInfo('https://koji') flexmock(koji, ClientSession=lambda hub, opts: session, PathInfo=pathinfo) kwargs = { 'url': 'https://something.com', 'smtp_host': 'smtp.bar.com', 'from_address': '*****@*****.**', 'to_koji_submitter': True, 'to_koji_pkgowner': False, } mock_store_metadata_results(workflow) workflow.data.plugins_results[KojiImportPlugin.key] = MOCK_KOJI_BUILD_ID mock_dockerfile(workflow) smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.bar.com', 'send_to_submitter': True, 'send_to_pkg_owner': False, } rcm = {'version': 1, 'smtp': smtp_map, 'openshift': {'url': 'https://something.com'}} workflow.conf = Configuration(raw_config=rcm) add_koji_map_in_workflow(workflow, hub_url='/', root_url='', ssl_certs_dir='/certs') p = SendMailPlugin(workflow, **kwargs) _, _, fail_logs = p._render_mail(False, False) assert not fail_logs
def remote_hosts_unlocking_recovery(job_args: dict) -> None: config = Configuration(config_path=job_args['config_file']) osbs = get_openshift_session(config, job_args['namespace']) remote_host_pools = config.remote_hosts.get("pools") for platform in remote_host_pools.keys(): platform_pool = remote_host.RemoteHostsPool.from_config( config.remote_hosts, platform) for host in platform_pool.hosts: logger.info("Checking occupied slots for platform: %s on host: %s", platform, host.hostname) for slot in range(host.slots): prid = host.prid_in_slot(slot) if not prid: continue logger.info("slot: %s is occupied by prid: %s", slot, prid) if not osbs.build_not_finished(prid): logger.info('prid: %s finished, will unlock slot: %s', prid, slot) host.unlock(slot, prid)
def test_get_docker_registry(self, config, exc): required_config = """\ version: 1 koji: hub_url: / root_url: '' auth: {} openshift: url: openshift_url source_registry: url: source_registry.com """ config += "\n" + required_config config_json = read_yaml(config, 'schemas/config.json') expected = { 'url': 'https://container-registry.example.com', 'insecure': False, 'secret': '/var/run/secrets/atomic-reactor/v2-registry-dockercfg' } conf = Configuration(raw_config=config_json) if exc is None: docker_registry = conf.docker_registry assert docker_registry == expected else: with pytest.raises(exc): getattr(conf, 'docker_registry')
def test_get_build_image_override(self, config, expect): config += "\n" + REQUIRED_CONFIG config_json = read_yaml(config, 'schemas/config.json') conf = Configuration(raw_config=config_json) build_image_override = conf.build_image_override assert build_image_override == expect
def test_odcs_config(self, tmpdir, default): config = """\ odcs: signing_intents: - name: release keys: [R123, R234] - name: beta keys: [R123, B456, B457] - name: unsigned keys: [] default_signing_intent: {default} api_url: http://odcs.example.com auth: ssl_certs_dir: /var/run/secrets/atomic-reactor/odcssecret """.format(default=default) config += "\n" + REQUIRED_CONFIG filename = str(tmpdir.join('config.yaml')) with open(filename, 'w') as fp: fp.write(dedent(config)) conf = Configuration(config_path=filename) odcs_config = conf.odcs_config assert odcs_config.default_signing_intent == default unsigned_intent = {'name': 'unsigned', 'keys': [], 'restrictiveness': 0} beta_intent = {'name': 'beta', 'keys': ['R123', 'B456', 'B457'], 'restrictiveness': 1} release_intent = {'name': 'release', 'keys': ['R123', 'R234'], 'restrictiveness': 2} assert odcs_config.signing_intents == [ unsigned_intent, beta_intent, release_intent ] assert odcs_config.get_signing_intent_by_name('release') == release_intent assert odcs_config.get_signing_intent_by_name('beta') == beta_intent assert odcs_config.get_signing_intent_by_name('unsigned') == unsigned_intent with pytest.raises(ValueError): odcs_config.get_signing_intent_by_name('missing') assert odcs_config.get_signing_intent_by_keys(['R123', 'R234'])['name'] == 'release' assert odcs_config.get_signing_intent_by_keys('R123 R234')['name'] == 'release' assert odcs_config.get_signing_intent_by_keys(['R123'])['name'] == 'release' assert odcs_config.get_signing_intent_by_keys('R123')['name'] == 'release' assert odcs_config.get_signing_intent_by_keys(['R123', 'B456'])['name'] == 'beta' assert odcs_config.get_signing_intent_by_keys(['B456', 'R123'])['name'] == 'beta' assert odcs_config.get_signing_intent_by_keys('B456 R123')['name'] == 'beta' assert odcs_config.get_signing_intent_by_keys('R123 B456 ')['name'] == 'beta' assert odcs_config.get_signing_intent_by_keys(['B456'])['name'] == 'beta' assert odcs_config.get_signing_intent_by_keys('B456')['name'] == 'beta' assert odcs_config.get_signing_intent_by_keys([])['name'] == 'unsigned' assert odcs_config.get_signing_intent_by_keys('')['name'] == 'unsigned' with pytest.raises(ValueError): assert odcs_config.get_signing_intent_by_keys(['missing']) with pytest.raises(ValueError): assert odcs_config.get_signing_intent_by_keys(['R123', 'R234', 'B457'])
def test_koji_recepients_exception(self, exception_location, expected_receivers, workflow): if exception_location == 'empty_owner': koji_build_id = None else: koji_build_id = MOCK_KOJI_BUILD_ID has_kerberos = exception_location != 'empty_email_domain' session = MockedClientSession('', has_kerberos=has_kerberos) if exception_location == 'koji_connection': (flexmock(session) .should_receive('ssl_login') .and_raise(RuntimeError, "xyz")) elif exception_location == 'submitter': (flexmock(session) .should_receive('getTaskInfo') .and_raise(RuntimeError, "xyz")) elif exception_location == 'owner': (flexmock(session) .should_receive('getPackageConfig') .and_raise(RuntimeError, "xyz")) flexmock(koji, ClientSession=lambda hub, opts: session, PathInfo=MockedPathInfo) kwargs = { 'url': 'https://something.com', 'smtp_host': 'smtp.bar.com', 'from_address': '*****@*****.**', 'to_koji_submitter': True, 'to_koji_pkgowner': True } smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.bar.com', 'send_to_submitter': True, 'send_to_pkg_owner': True, } if exception_location != 'empty_email_domain': kwargs['email_domain'] = MOCK_EMAIL_DOMAIN smtp_map['domain'] = MOCK_EMAIL_DOMAIN workflow.data.postbuild_results[KojiImportPlugin.key] = koji_build_id if exception_location == 'empty_submitter': workflow.user_params['koji_task_id'] = None else: workflow.user_params['koji_task_id'] = MOCK_KOJI_TASK_ID rcm = {'version': 1, 'smtp': smtp_map, 'openshift': {'url': 'https://something.com'}} workflow.conf = Configuration(raw_config=rcm) add_koji_map_in_workflow(workflow, hub_url='/', root_url='', ssl_certs_dir='/certs') p = SendMailPlugin(workflow, **kwargs) if not expected_receivers: with pytest.raises(RuntimeError): p._get_receivers_list() else: receivers = p._get_receivers_list() assert sorted(receivers) == sorted(expected_receivers)
def test_skip_plugin(self, caplog, workflow): rcm = {'version': 1, 'openshift': {'url': 'https://something.com'}} workflow.conf = Configuration(raw_config=rcm) add_koji_map_in_workflow(workflow, hub_url='/', root_url='', ssl_certs_dir='/certs') p = SendMailPlugin(workflow) p.run() log_msg = 'no smtp configuration, skipping plugin' assert log_msg in caplog.text
def test_get_openshift_session(self, config, raise_error): required_config = """\ version: 1 koji: hub_url: / root_url: '' auth: {} source_registry: url: source_registry.com registries: - url: registry_url """ config += "\n" + required_config if raise_error: with pytest.raises(Exception): read_yaml(config, 'schemas/config.json') return config_json = read_yaml(config, 'schemas/config.json') auth_info = { 'openshift_url': config_json['openshift']['url'], 'verify_ssl': not config_json['openshift'].get('insecure', False), 'use_auth': False, 'conf_file': None, 'namespace': 'namespace', } if config_json['openshift'].get('auth'): if config_json['openshift']['auth'].get('krb_keytab_path'): auth_info['kerberos_keytab'] =\ config_json['openshift']['auth'].get('krb_keytab_path') if config_json['openshift']['auth'].get('krb_principal'): auth_info['kerberos_principal'] =\ config_json['openshift']['auth'].get('krb_principal') if config_json['openshift']['auth'].get('krb_cache_path'): auth_info['kerberos_ccache'] =\ config_json['openshift']['auth'].get('krb_cache_path') if config_json['openshift']['auth'].get('ssl_certs_dir'): auth_info['client_cert'] =\ os.path.join(config_json['openshift']['auth'].get('ssl_certs_dir'), 'cert') auth_info['client_key'] =\ os.path.join(config_json['openshift']['auth'].get('ssl_certs_dir'), 'key') auth_info['use_auth'] = config_json['openshift']['auth'].get('enable', False) (flexmock(osbs.conf.Configuration) .should_call('__init__') .with_args(**auth_info) .once()) (flexmock(osbs.api.OSBS) .should_call('__init__') .once()) conf = Configuration(raw_config=config_json) get_openshift_session(conf, 'namespace')
def set_reactor_config(self, config): """ Set reactor config map in the workflow :param config: dict or Configuration, if dict, will be converted to Configuration """ if not isinstance(config, Configuration): config = Configuration(raw_config=config) self._reactor_config_map = config self.workflow.conf = config return self
def test_get_flatpak_metadata(self, config, expect): config += "\n" + REQUIRED_CONFIG config_json = read_yaml(config, 'schemas/config.json') conf = Configuration(raw_config=config_json) if expect: base_image = conf.flatpak_metadata assert base_image == expect else: with pytest.raises(KeyError): getattr(conf, 'flatpak_metadata')
def test_get_platform_to_goarch_mapping(self, config, expect): config += "\n" + REQUIRED_CONFIG config_json = read_yaml(config, 'schemas/config.json') conf = Configuration(raw_config=config_json) platform_to_goarch = conf.platform_to_goarch_mapping goarch_to_platform = conf.goarch_to_platform_mapping for plat, goarch in expect.items(): assert platform_to_goarch[plat] == goarch assert goarch_to_platform[goarch] == plat
def test_get_pull_registries(self, config, expected): config += "\n" + REQUIRED_CONFIG config_json = read_yaml(config, 'schemas/config.json') conf = Configuration(raw_config=config_json) pull_registries = conf.pull_registries # RegistryURI does not implement equality, check URI as string for reg in pull_registries + expected: reg['uri'] = reg['uri'].uri assert pull_registries == expected
def test_get_smtp_session(self, config, raise_error): config += "\n" + REQUIRED_CONFIG if raise_error: with pytest.raises(Exception): read_yaml(config, 'schemas/config.json') return config_json = read_yaml(config, 'schemas/config.json') conf = Configuration(raw_config=config_json) (flexmock(smtplib.SMTP).should_receive('__init__').with_args( config_json['smtp']['host']).once().and_return(None)) get_smtp_session(conf)
def test_good_cluster_config(self, tmpdir, config, clusters, defined_platforms): config += "\n" + REQUIRED_CONFIG filename = os.path.join(str(tmpdir), 'config.yaml') with open(filename, 'w') as fp: fp.write(dedent(config)) conf = Configuration(config_path=filename) enabled = conf.get_enabled_clusters_for_platform('platform') assert {(x.name, x.max_concurrent_builds) for x in enabled} == set(clusters) for platform in defined_platforms: assert conf.cluster_defined_for_platform(platform)
def reactor_config(self): """ Get reactor config map (from the ReactorConfigPlugin's workspace) If config does not exist, it will be created, i.e. you can do: >>> env = MockEnv(workflow) >>> env.reactor_config.conf['sources_command'] = 'fedpkg sources' :return: ReactorConfig instance """ if not self._reactor_config_map: config = Configuration(raw_config={'version': 1}) self._reactor_config_map = config self.workflow.conf = config return self._reactor_config_map