def test_filename_not_found(self): tasker, workflow = self.prepare() plugin = ReactorConfigPlugin(tasker, workflow, config_path='/not-found') with pytest.raises(Exception): plugin.run()
def test_bad_version(self, tmpdir): filename = os.path.join(str(tmpdir), 'config.yaml') with open(filename, 'w') as fp: fp.write("version: 2") tasker, workflow = self.prepare() plugin = ReactorConfigPlugin(tasker, workflow, config_path=str(tmpdir)) with pytest.raises(ValueError): plugin.run()
def test_odcs_config_invalid_default_signing_intent(self, tmpdir): filename = str(tmpdir.join('config.yaml')) with open(filename, 'w') as fp: fp.write(dedent("""\ version: 1 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 """)) tasker, workflow = self.prepare() plugin = ReactorConfigPlugin(tasker, workflow, config_path=str(tmpdir)) assert plugin.run() is None with pytest.raises(ValueError) as exc_info: get_config(workflow).get_odcs_config() message = str(exc_info.value) assert message == dedent("""\ unknown signing intent name "spam", valid names: unsigned, beta, release """.rstrip())
def test_odcs_config_invalid_default_signing_intent(self, tmpdir): filename = str(tmpdir.join('config.yaml')) with open(filename, 'w') as fp: fp.write( dedent("""\ version: 1 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 """)) tasker, workflow = self.prepare() plugin = ReactorConfigPlugin(tasker, workflow, config_path=str(tmpdir)) assert plugin.run() is None with pytest.raises(ValueError) as exc_info: get_config(workflow).get_odcs_config() message = str(exc_info.value) assert message == dedent("""\ unknown signing intent name "spam", valid names: unsigned, beta, release """.rstrip())
def test_bad_cluster_config(self, tmpdir, caplog, config, errors): filename = os.path.join(str(tmpdir), 'config.yaml') with open(filename, 'w') as fp: fp.write(dedent(config)) tasker, workflow = self.prepare() plugin = ReactorConfigPlugin(tasker, workflow, config_path=str(tmpdir)) with caplog.atLevel(logging.ERROR), pytest.raises(ValidationError): plugin.run() captured_errs = [x.message for x in caplog.records()] for error in errors: try: # Match regexp assert any(filter(error.match, captured_errs)) except AttributeError: # String comparison assert error in captured_errs
def test_odcs_config(self, tmpdir, default): filename = str(tmpdir.join('config.yaml')) with open(filename, 'w') as fp: fp.write(dedent("""\ version: 1 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))) tasker, workflow = self.prepare() plugin = ReactorConfigPlugin(tasker, workflow, config_path=str(tmpdir)) assert plugin.run() is None odcs_config = get_config(workflow).get_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_filename(self, tmpdir, basename): filename = os.path.join(str(tmpdir), basename or 'config.yaml') with open(filename, 'w'): pass tasker, workflow = self.prepare() plugin = ReactorConfigPlugin(tasker, workflow, config_path=str(tmpdir), basename=filename) assert plugin.run() is None
def test_good_cluster_config(self, tmpdir, config, clusters): filename = os.path.join(str(tmpdir), 'config.yaml') with open(filename, 'w') as fp: fp.write(dedent(config)) tasker, workflow = self.prepare() plugin = ReactorConfigPlugin(tasker, workflow, config_path=str(tmpdir)) assert plugin.run() == None conf = get_config(workflow) enabled = conf.get_enabled_clusters_for_platform('platform') assert set([(x.name, x.max_concurrent_builds) for x in enabled]) == set(clusters)
def test_good_cluster_config(self, tmpdir, config, clusters): filename = os.path.join(str(tmpdir), 'config.yaml') with open(filename, 'w') as fp: fp.write(dedent(config)) tasker, workflow = self.prepare() plugin = ReactorConfigPlugin(tasker, workflow, config_path=str(tmpdir)) assert plugin.run() is None conf = get_config(workflow) enabled = conf.get_enabled_clusters_for_platform('platform') assert set([(x.name, x.max_concurrent_builds) for x in enabled]) == set(clusters)
def test_invalid_schema_resource(self, tmpdir, caplog, schema): class FakeProvider(object): def get_resource_stream(self, pkg, rsc): return io.BufferedReader(io.BytesIO(schema)) # pkg_resources.resource_stream() cannot be mocked directly # Instead mock the module-level function it calls. (flexmock(pkg_resources).should_receive('get_provider').and_return( FakeProvider())) filename = os.path.join(str(tmpdir), 'config.yaml') with open(filename, 'w'): pass tasker, workflow = self.prepare() plugin = ReactorConfigPlugin(tasker, workflow, config_path=str(tmpdir)) with caplog.atLevel(logging.ERROR), pytest.raises(Exception): plugin.run() captured_errs = [x.message for x in caplog.records()] assert any("cannot validate" in x for x in captured_errs)
def test_invalid_schema_resource(self, tmpdir, caplog, schema): class FakeProvider(object): def get_resource_stream(self, pkg, rsc): return io.BufferedReader(io.BytesIO(schema)) # pkg_resources.resource_stream() cannot be mocked directly # Instead mock the module-level function it calls. (flexmock(pkg_resources) .should_receive('get_provider') .and_return(FakeProvider())) filename = os.path.join(str(tmpdir), 'config.yaml') with open(filename, 'w'): pass tasker, workflow = self.prepare() plugin = ReactorConfigPlugin(tasker, workflow, config_path=str(tmpdir)) with caplog.atLevel(logging.ERROR), pytest.raises(Exception): plugin.run() captured_errs = [x.message for x in caplog.records()] assert any("cannot validate" in x for x in captured_errs)
def test_no_schema_resource(self, tmpdir, caplog): class FakeProvider(object): def get_resource_stream(self, pkg, rsc): raise IOError # pkg_resources.resource_stream() cannot be mocked directly # Instead mock the module-level function it calls. (flexmock(pkg_resources).should_receive('get_provider').and_return( FakeProvider())) filename = os.path.join(str(tmpdir), 'reactor_config.yaml') with open(filename, 'w'): pass tasker, workflow = self.prepare() plugin = ReactorConfigPlugin(tasker, workflow, config_path=filename) with caplog.atLevel(logging.ERROR): with pytest.raises(Exception): plugin.run() captured_errs = [x.message for x in caplog.records()] assert "unable to extract JSON schema, cannot validate" in captured_errs
def test_good_cluster_config(self, tmpdir, reactor_config_map, config, clusters): if reactor_config_map and config: os.environ['REACTOR_CONFIG'] = dedent(config) else: filename = os.path.join(str(tmpdir), 'config.yaml') with open(filename, 'w') as fp: fp.write(dedent(config)) tasker, workflow = self.prepare() plugin = ReactorConfigPlugin(tasker, workflow, config_path=str(tmpdir)) assert plugin.run() is None os.environ.pop('REACTOR_CONFIG', None) conf = get_config(workflow) enabled = conf.get_enabled_clusters_for_platform('platform') assert set([(x.name, x.max_concurrent_builds) for x in enabled]) == set(clusters)
def test_odcs_config(self, tmpdir, default): filename = str(tmpdir.join('config.yaml')) with open(filename, 'w') as fp: fp.write(dedent("""\ version: 1 odcs: signing_intents: - name: release keys: [R123] - name: beta keys: [R123, B456] - name: unsigned keys: [] default_signing_intent: {default} """.format(default=default))) tasker, workflow = self.prepare() plugin = ReactorConfigPlugin(tasker, workflow, config_path=str(tmpdir)) assert plugin.run() is None odcs_config = get_config(workflow).get_odcs_config() assert odcs_config.default_signing_intent == default assert odcs_config.signing_intents == [ {'name': 'unsigned', 'keys': [], 'restrictiveness': 0}, {'name': 'beta', 'keys': ['R123', 'B456'], 'restrictiveness': 1}, {'name': 'release', 'keys': ['R123'], 'restrictiveness': 2}, ] with pytest.raises(ValueError): odcs_config.get_signing_intent_by_name('missing') 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([])['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'])
def test_cluster_client_config_path(self, tmpdir, reactor_config_map, extra_config, fallback, error): config = 'version: 1' if extra_config: config += '\n' + extra_config if reactor_config_map and config: os.environ['REACTOR_CONFIG'] = config else: filename = os.path.join(str(tmpdir), 'config.yaml') with open(filename, 'w') as fp: fp.write(config) tasker, workflow = self.prepare() plugin = ReactorConfigPlugin(tasker, workflow, config_path=str(tmpdir)) assert plugin.run() is None os.environ.pop('REACTOR_CONFIG', None) if error: with pytest.raises(error): get_clusters_client_config_path(workflow, fallback) else: path = get_clusters_client_config_path(workflow, fallback) assert path == '/the/path/osbs.conf'
def test_odcs_config_invalid_default_signing_intent(self, tmpdir): filename = str(tmpdir.join('config.yaml')) with open(filename, 'w') as fp: fp.write(dedent("""\ version: 1 odcs: signing_intents: - name: release keys: [R123] - name: beta keys: [R123, B456] - name: unsigned keys: [] default_signing_intent: spam """)) tasker, workflow = self.prepare() plugin = ReactorConfigPlugin(tasker, workflow, config_path=str(tmpdir)) assert plugin.run() is None with pytest.raises(ValueError) as exc_info: get_config(workflow).get_odcs_config() assert 'unknown signing intent' in str(exc_info.value)
def test_odcs_config_invalid_default_signing_intent(self, tmpdir): filename = str(tmpdir.join('config.yaml')) with open(filename, 'w') as fp: fp.write( dedent("""\ version: 1 odcs: signing_intents: - name: release keys: [R123] - name: beta keys: [R123, B456] - name: unsigned keys: [] default_signing_intent: spam """)) tasker, workflow = self.prepare() plugin = ReactorConfigPlugin(tasker, workflow, config_path=str(tmpdir)) assert plugin.run() is None with pytest.raises(ValueError) as exc_info: get_config(workflow).get_odcs_config() assert 'unknown signing intent' in str(exc_info.value)
def test_odcs_config(self, tmpdir, default): filename = str(tmpdir.join('config.yaml')) with open(filename, 'w') as fp: fp.write( dedent("""\ version: 1 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))) tasker, workflow = self.prepare() plugin = ReactorConfigPlugin(tasker, workflow, config_path=str(tmpdir)) assert plugin.run() is None odcs_config = get_config(workflow).get_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_odcs_config(self, tmpdir, default): filename = str(tmpdir.join('config.yaml')) with open(filename, 'w') as fp: fp.write( dedent("""\ version: 1 odcs: signing_intents: - name: release keys: [R123] - name: beta keys: [R123, B456] - name: unsigned keys: [] default_signing_intent: {default} """.format(default=default))) tasker, workflow = self.prepare() plugin = ReactorConfigPlugin(tasker, workflow, config_path=str(tmpdir)) assert plugin.run() is None odcs_config = get_config(workflow).get_odcs_config() assert odcs_config.default_signing_intent == default assert odcs_config.signing_intents == [ { 'name': 'unsigned', 'keys': [], 'restrictiveness': 0 }, { 'name': 'beta', 'keys': ['R123', 'B456'], 'restrictiveness': 1 }, { 'name': 'release', 'keys': ['R123'], 'restrictiveness': 2 }, ] with pytest.raises(ValueError): odcs_config.get_signing_intent_by_name('missing') 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([])['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'])