def test_get_odcs_session(self, tmpdir, fallback, config, raise_error): tasker, workflow = self.prepare() workflow.plugin_workspace[ReactorConfigPlugin.key] = {} if raise_error: with pytest.raises(Exception): read_yaml(config, 'schemas/config.json') return config_json = read_yaml(config, 'schemas/config.json') auth_info = {'insecure': config_json['odcs'].get('insecure', False)} if 'openidc_dir' in config_json['odcs']['auth']: config_json['odcs']['auth']['openidc_dir'] = str(tmpdir) filename = str(tmpdir.join('token')) with open(filename, 'w') as fp: fp.write("my_token") auth_info['token'] = "my_token" ssl_dir_raise = False if 'ssl_certs_dir' in config_json['odcs']['auth']: if config_json['odcs']['auth']['ssl_certs_dir'] != "nonexistent": config_json['odcs']['auth']['ssl_certs_dir'] = str(tmpdir) filename = str(tmpdir.join('cert')) with open(filename, 'w') as fp: fp.write("my_cert") auth_info['cert'] = filename else: ssl_dir_raise = True fallback_map = {} if fallback: fallback_map = { 'auth': deepcopy(auth_info), 'api_url': config_json['odcs']['api_url'] } fallback_map['auth']['ssl_certs_dir'] = config_json['odcs'][ 'auth'].get('ssl_certs_dir') fallback_map['auth']['openidc_dir'] = config_json['odcs'][ 'auth'].get('openidc_dir') else: workflow.plugin_workspace[ReactorConfigPlugin.key][WORKSPACE_CONF_KEY] =\ ReactorConfig(config_json) if not ssl_dir_raise: (flexmock(atomic_reactor.odcs_util.ODCSClient).should_receive( '__init__').with_args(config_json['odcs']['api_url'], **auth_info).once().and_return(None)) get_odcs_session(workflow, fallback_map) else: with pytest.raises(KeyError): get_odcs_session(workflow, fallback_map)
def test_get_odcs_session(self, tmpdir, fallback, config, raise_error): tasker, workflow = self.prepare() workflow.plugin_workspace[ReactorConfigPlugin.key] = {} if raise_error: with pytest.raises(Exception): read_yaml(config, 'schemas/config.json') return config_json = read_yaml(config, 'schemas/config.json') auth_info = {'insecure': config_json['odcs'].get('insecure', False)} if 'openidc_dir' in config_json['odcs']['auth']: config_json['odcs']['auth']['openidc_dir'] = str(tmpdir) filename = str(tmpdir.join('token')) with open(filename, 'w') as fp: fp.write("my_token") auth_info['token'] = "my_token" ssl_dir_raise = False if 'ssl_certs_dir' in config_json['odcs']['auth']: if config_json['odcs']['auth']['ssl_certs_dir'] != "nonexistent": config_json['odcs']['auth']['ssl_certs_dir'] = str(tmpdir) filename = str(tmpdir.join('cert')) with open(filename, 'w') as fp: fp.write("my_cert") auth_info['cert'] = filename else: ssl_dir_raise = True fallback_map = {} if fallback: fallback_map = {'auth': deepcopy(auth_info), 'api_url': config_json['odcs']['api_url']} fallback_map['auth']['ssl_certs_dir'] = config_json['odcs']['auth'].get('ssl_certs_dir') fallback_map['auth']['openidc_dir'] = config_json['odcs']['auth'].get('openidc_dir') else: workflow.plugin_workspace[ReactorConfigPlugin.key][WORKSPACE_CONF_KEY] =\ ReactorConfig(config_json) if not ssl_dir_raise: (flexmock(atomic_reactor.odcs_util.ODCSClient) .should_receive('__init__') .with_args(config_json['odcs']['api_url'], **auth_info) .once() .and_return(None)) get_odcs_session(workflow, fallback_map) else: with pytest.raises(KeyError): get_odcs_session(workflow, fallback_map)
def _load_composes(self): odcs_client = get_odcs_session(self.workflow, fallback=NO_FALLBACK) self.log.info(odcs_client) composes = [] for compose_id in self.compose_ids: composes.append(odcs_client.wait_for_compose(compose_id)) return composes
def _resolve_compose(self): odcs_client = get_odcs_session(self.workflow, self.odcs_fallback) self.read_configs_general() modules = self.data.get('modules', []) if not modules: raise RuntimeError( '"compose" config has no modules, a module is required for Flatpaks' ) source_spec = modules[0] if len(modules) > 1: self.log.info( "compose config contains multiple modules," "using first module %s", source_spec) module = split_module_spec(source_spec) self.log.info( "Resolving module compose for name=%s, stream=%s, version=%s", module.name, module.stream, module.version) noprofile_spec = module.to_str(include_profile=False) if self.compose_ids: if len(self.compose_ids) > 1: self.log.info("Multiple compose_ids, using first compose %d", self.compose_ids[0]) self.compose_id = self.compose_ids[0] if self.compose_id is None: self.compose_id = odcs_client.start_compose( source_type='module', source=noprofile_spec)['id'] compose_info = odcs_client.wait_for_compose(self.compose_id) if compose_info['state_name'] != "done": raise RuntimeError("Compose cannot be retrieved, state='%s'" % compose_info['state_name']) compose_source = compose_info['source'] self.log.info("Resolved list of modules: %s", compose_source) resolved_modules = self._resolve_modules(compose_source) base_module = resolved_modules[module.name] assert base_module.stream == module.stream if module.version is not None: assert base_module.version == module.version return ComposeInfo(source_spec=source_spec, compose_id=self.compose_id, base_module=base_module, modules=resolved_modules, repo_url=compose_info['result_repo'] + '/$basearch/os/')
def odcs_client(self): if not self._odcs_client: self._odcs_client = get_odcs_session(self.workflow, self.odcs_fallback) return self._odcs_client
def _resolve_compose(self): odcs_config = get_config(self.workflow).get_odcs_config() odcs_client = get_odcs_session(self.workflow, self.odcs_fallback) self.read_configs_general() modules = self.data.get('modules', []) if not modules: raise RuntimeError('"compose" config has no modules, a module is required for Flatpaks') source_spec = modules[0] if len(modules) > 1: self.log.info("compose config contains multiple modules," "using first module %s", source_spec) module = ModuleSpec.from_str(source_spec) self.log.info("Resolving module compose for name=%s, stream=%s, version=%s", module.name, module.stream, module.version) noprofile_spec = module.to_str(include_profile=False) if self.compose_ids: if len(self.compose_ids) > 1: self.log.info("Multiple compose_ids, using first compose %d", self.compose_ids[0]) self.compose_id = self.compose_ids[0] if self.signing_intent_name is not None: signing_intent_name = self.signing_intent_name else: signing_intent_name = self.data.get('signing_intent', odcs_config.default_signing_intent) signing_intent = odcs_config.get_signing_intent_by_name(signing_intent_name) if self.compose_id is None: arches = sorted(get_platforms(self.workflow)) self.compose_id = odcs_client.start_compose(source_type='module', source=noprofile_spec, sigkeys=signing_intent['keys'], arches=arches)['id'] compose_info = odcs_client.wait_for_compose(self.compose_id) if compose_info['state_name'] != "done": raise RuntimeError("Compose cannot be retrieved, state='%s'" % compose_info['state_name']) compose_source = compose_info['source'] self.log.info("Resolved list of modules: %s", compose_source) resolved_modules = self._resolve_modules(compose_source) base_module = resolved_modules[module.name] assert base_module.stream == module.stream if module.version is not None: assert base_module.version == module.version return ComposeInfo(source_spec=source_spec, compose_id=self.compose_id, base_module=base_module, modules=resolved_modules, repo_url=compose_info['result_repo'] + '/$basearch/os/', signing_intent=signing_intent_name, signing_intent_overridden=self.signing_intent_name is not None)
def odcs_client(self): if not self._odcs_client: self._odcs_client = get_odcs_session(self.workflow, self.odcs_fallback) return self._odcs_client
def odcs_client(self): if not self._odcs_client: self._odcs_client = get_odcs_session(self.workflow) return self._odcs_client