def __init__(self, tasker, workflow, target, hub=None, root=None, proxy=None, koji_ssl_certs_dir=None): """ constructor :param tasker: DockerTasker instance :param workflow: DockerBuildWorkflow instance :param target: string, koji target to use as a source :param hub: string, koji hub (xmlrpc) :param root: string, koji root (storage) :param koji_ssl_certs_dir: str, path to "cert", "ca", and "serverca" Note that this plugin requires koji_ssl_certs_dir set if Koji certificate is not trusted by CA bundle. """ # call parent constructor super(KojiPlugin, self).__init__(tasker, workflow) self.target = target self.koji_fallback = { 'hub_url': hub, 'root_url': root, 'auth': { 'ssl_certs_dir': koji_ssl_certs_dir } } self.xmlrpc = get_koji_session(self.workflow, self.koji_fallback) self.pathinfo = get_koji_path_info(self.workflow, self.koji_fallback) self.proxy = get_yum_proxy(self.workflow, proxy)
def __init__( self, tasker, workflow, koji_build_id=None, koji_build_nvr=None, signing_intent=None, ): """ :param tasker: ContainerTasker instance :param workflow: DockerBuildWorkflow instance :param koji_build_id: int, container image koji build id :param koji_build_nvr: str, container image koji build NVR :param signing_intent: str, ODCS signing intent name """ if not koji_build_id and not koji_build_nvr: err_msg = ('{} expects either koji_build_id or koji_build_nvr to be defined' .format(self.__class__.__name__)) raise TypeError(err_msg) type_errors = [] if koji_build_id is not None and not isinstance(koji_build_id, int): type_errors.append('koji_build_id must be an int. Got {}'.format(type(koji_build_id))) if koji_build_nvr is not None and not isinstance(koji_build_nvr, string_types): type_errors.append('koji_build_nvr must be a str. Got {}' .format(type(koji_build_nvr))) if type_errors: raise TypeError(type_errors) super(FetchSourcesPlugin, self).__init__(tasker, workflow) self.koji_build = None self.koji_build_id = koji_build_id self.koji_build_nvr = koji_build_nvr self.signing_intent = signing_intent self.session = get_koji_session(self.workflow, NO_FALLBACK) self.pathinfo = get_koji_path_info(self.workflow, NO_FALLBACK)
def __init__(self, tasker, workflow, koji_hub=None, koji_root=None, koji_proxyuser=None, koji_ssl_certs_dir=None, koji_krb_principal=None, koji_krb_keytab=None, allowed_domains=None): """ :param tasker: DockerTasker instance :param workflow: DockerBuildWorkflow instance :param koji_hub: str, koji hub (xmlrpc) :param koji_root: str, koji root (storage) :param koji_proxyuser: str, proxy user :param koji_ssl_certs_dir: str, path to "cert", "ca", and "serverca" :param koji_krb_principal: str, name of Kerberos principal :param koji_krb_keytab: str, Kerberos keytab :param allowed_domains: list<str>: list of domains that are allowed to be used when fetching artifacts by URL (case insensitive) """ super(FetchMavenArtifactsPlugin, self).__init__(tasker, workflow) self.koji_fallback = { 'hub_url': koji_hub, 'root_url': koji_root, 'auth': { 'proxyuser': koji_proxyuser, 'ssl_certs_dir': koji_ssl_certs_dir, 'krb_principal': str(koji_krb_principal), 'krb_keytab_path': str(koji_krb_keytab) } } self.path_info = get_koji_path_info(self.workflow, self.koji_fallback) all_allowed_domains = get_artifacts_allowed_domains(self.workflow, allowed_domains or []) self.allowed_domains = set(domain.lower() for domain in all_allowed_domains or []) self.workdir = self.workflow.source.get_build_file_path()[1] self.session = None
def _get_logs_url(self): url = None try: pathinfo = get_koji_path_info(self.workflow, self.koji_fallback) url = '/'.join([pathinfo.work(), pathinfo.taskrelpath(self.koji_task_id)]) except Exception: self.log.exception("Failed to fetch logs from koji") if self.url and self.workflow.openshift_build_selflink: url = urljoin(self.url, self.workflow.openshift_build_selflink + '/log') return url
def test_get_koji_path_info(self, fallback, root_url): tasker, workflow = self.prepare() workflow.plugin_workspace[ReactorConfigPlugin.key] = {} config = { 'version': 1, 'koji': { 'hub_url': 'https://koji.example.com/hub', 'auth': { 'ssl_certs_dir': '/var/certs' } } } expected_root_url = 'https://koji.example.com/root' if root_url: config['koji']['root_url'] = root_url config_yaml = yaml.safe_dump(config) expect_error = not root_url if expect_error: with pytest.raises(Exception): read_yaml(config_yaml, 'schemas/config.json') return parsed_config = read_yaml(config_yaml, 'schemas/config.json') fallback_map = {} if fallback: fallback_map = deepcopy(config['koji']) else: workflow.plugin_workspace[ReactorConfigPlugin.key][WORKSPACE_CONF_KEY] = \ ReactorConfig(parsed_config) (flexmock(koji.PathInfo) .should_receive('__init__') .with_args(topdir=expected_root_url) .once()) get_koji_path_info(workflow, fallback_map)
def test_get_koji_path_info(self, fallback, root_url): tasker, workflow = self.prepare() workflow.plugin_workspace[ReactorConfigPlugin.key] = {} config = { 'version': 1, 'koji': { 'hub_url': 'https://koji.example.com/hub', 'auth': { 'ssl_certs_dir': '/var/certs' } } } expected_root_url = 'https://koji.example.com/root' if root_url: config['koji']['root_url'] = root_url config_yaml = yaml.safe_dump(config) expect_error = not root_url if expect_error: with pytest.raises(Exception): read_yaml(config_yaml, 'schemas/config.json') return parsed_config = read_yaml(config_yaml, 'schemas/config.json') fallback_map = {} if fallback: fallback_map = deepcopy(config['koji']) else: workflow.plugin_workspace[ReactorConfigPlugin.key][WORKSPACE_CONF_KEY] = \ ReactorConfig(parsed_config) (flexmock(koji.PathInfo).should_receive('__init__').with_args( topdir=expected_root_url).once()) get_koji_path_info(workflow, fallback_map)
def get_koji_operator_manifest_url(self): """Construct URL for downloading manifest from koji task work server_dir :rtype: str :return: URL of koji operator manifests archive """ server_dir = get_koji_upload_dir(self.workflow) pathinfo = get_koji_path_info(self.workflow, NO_FALLBACK) file_url = "{}/work/{}/{}".format(pathinfo.topdir, server_dir, OPERATOR_MANIFESTS_ARCHIVE) return file_url
def __init__(self, tasker, workflow, target=None, proxy=None): """ constructor :param tasker: ContainerTasker instance :param workflow: DockerBuildWorkflow instance :param target: string, koji target to use as a source """ # call parent constructor super(KojiPlugin, self).__init__(tasker, workflow) self.target = target self.xmlrpc = get_koji_session(self.workflow) self.pathinfo = get_koji_path_info(self.workflow) self.proxy = get_yum_proxy(self.workflow, proxy)
def __init__(self, tasker, workflow, allowed_domains=None): """ :param tasker: ContainerTasker instance :param workflow: DockerBuildWorkflow instance :param allowed_domains: list<str>: list of domains that are allowed to be used when fetching artifacts by URL (case insensitive) """ super(FetchMavenArtifactsPlugin, self).__init__(tasker, workflow) self.path_info = get_koji_path_info(self.workflow) all_allowed_domains = get_artifacts_allowed_domains( self.workflow, allowed_domains or []) self.allowed_domains = set(domain.lower() for domain in all_allowed_domains or []) self.workdir = self.workflow.source.get_build_file_path()[1] self.session = None
def __init__(self, tasker, workflow, koji_hub=None, koji_root=None, koji_proxyuser=None, koji_ssl_certs_dir=None, koji_krb_principal=None, koji_krb_keytab=None, allowed_domains=None): """ :param tasker: ContainerTasker instance :param workflow: DockerBuildWorkflow instance :param koji_hub: str, koji hub (xmlrpc) :param koji_root: str, koji root (storage) :param koji_proxyuser: str, proxy user :param koji_ssl_certs_dir: str, path to "cert", "ca", and "serverca" :param koji_krb_principal: str, name of Kerberos principal :param koji_krb_keytab: str, Kerberos keytab :param allowed_domains: list<str>: list of domains that are allowed to be used when fetching artifacts by URL (case insensitive) """ super(FetchMavenArtifactsPlugin, self).__init__(tasker, workflow) self.koji_fallback = { 'hub_url': koji_hub, 'root_url': koji_root, 'auth': { 'proxyuser': koji_proxyuser, 'ssl_certs_dir': koji_ssl_certs_dir, 'krb_principal': str(koji_krb_principal), 'krb_keytab_path': str(koji_krb_keytab) } } self.path_info = get_koji_path_info(self.workflow, self.koji_fallback) all_allowed_domains = get_artifacts_allowed_domains( self.workflow, allowed_domains or []) self.allowed_domains = set(domain.lower() for domain in all_allowed_domains or []) self.workdir = self.workflow.source.get_build_file_path()[1] self.session = None
def _get_logs_url(self): url = None if self.koji_task_id: # build via koji tasks try: pathinfo = get_koji_path_info(self.workflow) url = '/'.join( [pathinfo.work(), pathinfo.taskrelpath(self.koji_task_id)]) except Exception: self.log.exception("Failed to fetch logs from koji") else: self.log.info("Logs URL: no koji task") # openshift build log URL, if possible (direct osbs-client builds) if not url and self.url and self.workflow.openshift_build_selflink: self.log.info("Logs URL: using openshift log path") url = urljoin(self.url, self.workflow.openshift_build_selflink + '/log') return url