def __init__(self, tasker, workflow, url=None, verify_ssl=True, use_auth=True, blocksize=None, target=None, poll_interval=5): """ constructor :param tasker: ContainerTasker instance :param workflow: DockerBuildWorkflow instance :param url: string, URL for OSv3 instance :param verify_ssl: bool, verify OSv3 SSL certificate? :param use_auth: bool, initiate authentication with OSv3? :param blocksize: int, blocksize to use for uploading files :param target: str, koji target :param poll_interval: int, seconds between Koji task status requests """ super(KojiImportBase, self).__init__(tasker, workflow) self.openshift_fallback = { 'url': url, 'insecure': not verify_ssl, 'auth': {'enable': use_auth} } self.blocksize = blocksize self.target = target self.poll_interval = poll_interval self.osbs = get_openshift_session(self.workflow, self.openshift_fallback) self.build_id = None self.koji_task_id = None self.session = None self.reserve_build = get_koji(self.workflow).get('reserve_build', False) self.delegate_enabled = get_koji(self.workflow).get('delegate_task', True) self.rebuild = is_rebuild(self.workflow)
def run(self): """ :return: dict, binary image koji build id and nvr, and path to directory with downloaded sources """ self.set_koji_image_build_data() self.check_lookaside_cache_usage() signing_intent = self.get_signing_intent() koji_config = get_koji(self.workflow, {}) insecure = koji_config.get('insecure_download', False) urls = self.get_srpm_urls(signing_intent['keys'], insecure=insecure) urls_remote = self.get_remote_urls() if not urls and not urls_remote: msg = "No srpms or remote sources found for source container," \ " would produce empty source container image" self.log.error(msg) raise RuntimeError(msg) sources_dir = None remote_sources_dir = None if urls: sources_dir = self.download_sources(urls, insecure=insecure) if urls_remote: remote_sources_dir = self.download_sources(urls_remote, insecure=insecure, download_dir=self.REMOTE_SOUCES_DOWNLOAD_DIR) return { 'sources_for_koji_build_id': self.koji_build_id, 'sources_for_nvr': self.koji_build_nvr, 'image_sources_dir': sources_dir, 'remote_sources_dir': remote_sources_dir, 'signing_intent': self.signing_intent, }
def __init__(self, tasker, workflow, hub=None, target=None, koji_ssl_certs_dir=None, append=False): """ constructor :param tasker: ContainerTasker instance :param workflow: DockerBuildWorkflow instance :param hub: string, koji hub (xmlrpc) :param target: unused - backwards compatibility :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. :param append: if True, the release will be obtained by appending a '.' and a unique integer to the release label in the dockerfile. """ # call parent constructor super(BumpReleasePlugin, self).__init__(tasker, workflow) self.koji_fallback = { 'hub_url': hub, 'auth': { 'ssl_certs_dir': koji_ssl_certs_dir, } } self.append = append self.xmlrpc = get_koji_session(self.workflow, self.koji_fallback) koji_setting = get_koji(self.workflow, self.koji_fallback) self.reserve_build = koji_setting.get('reserve_build', False)
def download_files(self, downloads): artifacts_path = os.path.join(self.workdir, self.DOWNLOAD_DIR) koji_config = get_koji(self.workflow) insecure = koji_config.get('insecure_download', False) self.log.debug('%d files to download', len(downloads)) session = util.get_retrying_requests_session() for index, download in enumerate(downloads): dest_path = os.path.join(artifacts_path, download.dest) dest_dir = dest_path.rsplit('/', 1)[0] dest_filename = dest_path.rsplit('/', 1)[-1] if not os.path.exists(dest_dir): os.makedirs(dest_dir) self.log.debug('%d/%d downloading %s', index + 1, len(downloads), download.url) download_url(url=download.url, dest_dir=dest_dir, insecure=insecure, session=session, dest_filename=dest_filename, expected_checksums=download.checksums)
def download_sources(self, download_queue): remote_source_files = [] downloads_path = os.path.join(self.workdir, self.DOWNLOAD_DIR) session = util.get_retrying_requests_session() self.log.debug('%d files to download', len(download_queue)) koji_config = get_koji(self.workflow) insecure = koji_config.get('insecure_download', False) for index, download in enumerate(download_queue): dest_filename = download.dest if not re.fullmatch(r'^[\w\-.]+$', dest_filename): dest_filename = session.head(download.url).headers.get( "Content-disposition").split("filename=")[1].replace( '"', '') dest_path = os.path.join(downloads_path, dest_filename) dest_dir = os.path.dirname(dest_path) if not os.path.exists(dest_dir): os.makedirs(dest_dir) self.log.debug('%d/%d downloading %s', index + 1, len(download_queue), download.url) download_url(url=download.url, dest_dir=dest_dir, insecure=insecure, session=session, dest_filename=dest_filename, expected_checksums=download.checksums) checksum_type = list(download.checksums.keys())[0] remote_source_files.append({ 'file': dest_path, 'metadata': { 'type': KOJI_BTYPE_REMOTE_SOURCE_FILE, 'checksum_type': checksum_type, 'checksum': download.checksums[checksum_type], 'filename': dest_filename, 'filesize': os.path.getsize(dest_path), 'extra': { 'source-url': download.url, 'artifacts': self.source_url_to_artifacts[download.url], 'typeinfo': { KOJI_BTYPE_REMOTE_SOURCE_FILE: {} }, }, } }) return remote_source_files
def set_koji_task_annotations_whitelist(self, annotations): """Whitelist annotations to be included in koji task output Allow annotations whose names are listed in task_annotations_whitelist koji's configuration to be included in the build_annotations.json file, which will be attached in the koji task output. """ koji_config = get_koji(self.workflow, {}) whitelist = koji_config.get('task_annotations_whitelist') if whitelist: annotations['koji_task_annotations_whitelist'] = whitelist
def __init__( self, tasker, workflow, koji_target=None, signing_intent=None, compose_ids=tuple(), repourls=None, minimum_time_to_expire=MINIMUM_TIME_TO_EXPIRE, ): """ :param tasker: ContainerTasker instance :param workflow: DockerBuildWorkflow instance :param koji_target: str, koji target contains build tag to be used when requesting compose from "tag" :param signing_intent: override the signing intent from git repo configuration :param compose_ids: use the given compose_ids instead of requesting a new one :param repourls: list of str, URLs to the repo files :param minimum_time_to_expire: int, used in deciding when to extend compose's time to expire in seconds """ super(ResolveComposesPlugin, self).__init__(tasker, workflow) if signing_intent and compose_ids: raise ValueError( 'signing_intent and compose_ids cannot be used at the same time' ) self.signing_intent = signing_intent self.compose_ids = compose_ids self.koji_target = koji_target if koji_target: if not get_koji(self.workflow)['hub_url']: raise ValueError( 'koji_hub is required when koji_target is used') self.minimum_time_to_expire = minimum_time_to_expire self._koji_session = None self._odcs_client = None self.odcs_config = None self.compose_config = None self.composes_info = None self._parent_signing_intent = None self.repourls = repourls or [] self.has_complete_repos = len(self.repourls) > 0 self.plugin_result = self.workflow.prebuild_results.get( PLUGIN_KOJI_PARENT_KEY) self.all_compose_ids = list(self.compose_ids) self.parent_compose_ids = []
def __init__(self, tasker, workflow, kojihub=None, url=None, verify_ssl=True, use_auth=True, koji_ssl_certs=None, koji_proxy_user=None, koji_principal=None, koji_keytab=None, blocksize=None, target=None, poll_interval=5): """ constructor :param tasker: ContainerTasker instance :param workflow: DockerBuildWorkflow instance :param kojihub: string, koji hub (xmlrpc) :param url: string, URL for OSv3 instance :param verify_ssl: bool, verify OSv3 SSL certificate? :param use_auth: bool, initiate authentication with OSv3? :param koji_ssl_certs: str, path to 'cert', 'ca', 'serverca' :param koji_proxy_user: str, user to log in as (requires hub config) :param koji_principal: str, Kerberos principal (must specify keytab) :param koji_keytab: str, keytab name (must specify principal) :param blocksize: int, blocksize to use for uploading files :param target: str, koji target :param poll_interval: int, seconds between Koji task status requests """ super(KojiImportPlugin, self).__init__(tasker, workflow) self.koji_fallback = { 'hub_url': kojihub, 'auth': { 'proxyuser': koji_proxy_user, 'ssl_certs_dir': koji_ssl_certs, 'krb_principal': str(koji_principal), 'krb_keytab_path': str(koji_keytab) } } self.openshift_fallback = { 'url': url, 'insecure': not verify_ssl, 'auth': {'enable': use_auth} } self.blocksize = blocksize self.target = target self.poll_interval = poll_interval self.osbs = get_openshift_session(self.workflow, self.openshift_fallback) self.build_id = None self.session = None self.reserve_build = get_koji(self.workflow, self.koji_fallback).get('reserve_build', False) self.source_build = bool(self.workflow.build_result.oci_image_path)
def __init__(self, tasker, workflow, target=None, append=False): """ constructor :param tasker: ContainerTasker instance :param workflow: DockerBuildWorkflow instance :param target: unused - backwards compatibility :param append: if True, the release will be obtained by appending a '.' and a unique integer to the release label in the dockerfile. """ # call parent constructor super(BumpReleasePlugin, self).__init__(tasker, workflow) self.append = append self.xmlrpc = get_koji_session(self.workflow) koji_setting = get_koji(self.workflow) self.reserve_build = koji_setting.get('reserve_build', False)
def __init__(self, tasker, workflow, triggered_after_koji_task=None): """ constructor :param tasker: ContainerTasker instance :param workflow: DockerBuildWorkflow instance :param triggered_after_koji_task: int, original koji task for autorebuild, provided only when this plugin creates new koji task for autorebuild """ # call parent constructor super(KojiDelegatePlugin, self).__init__(tasker, workflow) koji_setting = get_koji(self.workflow, NO_FALLBACK) self.delegate_enabled = koji_setting.get('delegate_task', True) self.task_priority = koji_setting.get('delegated_task_priority', None) self.triggered_after_koji_task = triggered_after_koji_task self.metadata = get_build_json().get("metadata", {}) self.kojisession = get_koji_session(self.workflow, NO_FALLBACK) self.osbs = None
def run(self): """ :return: dict, binary image koji build id and nvr, and path to directory with downloaded sources """ self.set_koji_image_build_data() self.check_lookaside_cache_usage() signing_intent = self.get_signing_intent() koji_config = get_koji(self.workflow) insecure = koji_config.get('insecure_download', False) urls = self.get_srpm_urls(signing_intent['keys'], insecure=insecure) urls_remote, remote_sources_map = self.get_remote_urls() urls_maven = (self.get_kojifile_source_urls() + self.get_remote_file_urls() + self.get_pnc_source_urls()) if not any([urls, urls_remote, urls_maven]): msg = "No srpms or remote sources or maven sources found for source" \ " container, would produce empty source container image" self.log.error(msg) raise RuntimeError(msg) sources_dir = None remote_sources_dir = None maven_sources_dir = None if urls: sources_dir = self.download_sources(urls, insecure=insecure) if urls_remote: remote_sources_dir = self.download_sources(urls_remote, insecure=insecure, download_dir=self.REMOTE_SOURCES_DOWNLOAD_DIR ) self.exclude_files_from_remote_sources(remote_sources_map, remote_sources_dir) if urls_maven: maven_sources_dir = self.download_sources(urls_maven, insecure=insecure, download_dir=self.MAVEN_SOURCES_DOWNLOAD_DIR) return { 'sources_for_koji_build_id': self.koji_build_id, 'sources_for_nvr': self.koji_build_nvr, 'image_sources_dir': sources_dir, 'remote_sources_dir': remote_sources_dir, 'maven_sources_dir': maven_sources_dir, 'signing_intent': self.signing_intent, }
def run(self): """ :return: dict, binary image koji build id and nvr, and path to directory with downloaded sources """ self.set_koji_image_build_data() signing_intent = self.get_signing_intent() koji_config = get_koji(self.workflow, {}) insecure = koji_config.get('insecure_download', False) urls = self.get_srpm_urls(signing_intent['keys'], insecure=insecure) if not urls: msg = "No srpms found for source container, would produce empty source container image" self.log.error(msg) raise RuntimeError(msg) sources_dir = self.download_sources(urls, insecure=insecure) return { 'sources_for_koji_build_id': self.koji_build_id, 'sources_for_nvr': self.koji_build_nvr, 'image_sources_dir': sources_dir, 'signing_intent': self.signing_intent, }
def adjust_config_kwargs(self): koji_fallback = { 'hub_url': self.config_kwargs.get('koji_hub'), 'root_url': self.config_kwargs.get('koji_root') } koji_map = get_koji(self.workflow, koji_fallback) self.config_kwargs['koji_hub'] = koji_map['hub_url'] self.config_kwargs['koji_root'] = koji_map['root_url'] odcs_fallback = { 'api_url': self.config_kwargs.get('odcs_url'), 'insecure': self.config_kwargs.get('odcs_insecure') } odcs_map = get_odcs(self.workflow, odcs_fallback) self.config_kwargs['odcs_url'] = odcs_map['api_url'] self.config_kwargs['odcs_insecure'] = odcs_map.get('insecure', False) smtp_fallback = { 'host': self.config_kwargs.get('smtp_host'), 'from_address': self.config_kwargs.get('smtp_from'), 'domain': self.config_kwargs.get('smtp_email_domain'), 'send_to_submitter': self.config_kwargs.get('smtp_to_submitter'), 'send_to_pkg_owner': self.config_kwargs.get('smtp_to_pkgowner') } additional_addresses = self.config_kwargs.get('smtp_error_addresses') error_addresses = self.config_kwargs.get('smtp_additional_addresses') smtp_fallback['additional_addresses'] =\ additional_addresses.split(',') if additional_addresses else () smtp_fallback['error_addresses'] = error_addresses.split( ',') if error_addresses else () smtp_map = get_smtp(self.workflow, smtp_fallback) self.config_kwargs['smtp_additional_addresses'] =\ ','.join(smtp_map.get('additional_addresses', ())) self.config_kwargs['smtp_email_domain'] = smtp_map.get('domain') self.config_kwargs['smtp_error_addresses'] = ','.join( smtp_map.get('error_addresses', ())) self.config_kwargs['smtp_from'] = smtp_map['from_address'] self.config_kwargs['smtp_host'] = smtp_map['host'] self.config_kwargs['smtp_to_pkgowner'] = smtp_map.get( 'send_to_pkg_owner', False) self.config_kwargs['smtp_to_submitter'] = smtp_map.get( 'send_to_submitter', False) source_reg = self.config_kwargs.get('source_registry_uri') souce_registry = get_source_registry( self.workflow, {'uri': RegistryURI(source_reg) if source_reg else None})['uri'] self.config_kwargs[ 'source_registry_uri'] = souce_registry.uri if souce_registry else None artifacts = self.config_kwargs.get('artifacts_allowed_domains') self.config_kwargs['artifacts_allowed_domains'] =\ ','.join(get_artifacts_allowed_domains( self.workflow, artifacts.split(',') if artifacts else ())) equal_labels_fallback = [] equal_labels_str = self.config_kwargs.get('equal_labels') if equal_labels_str: label_groups = [x.strip() for x in equal_labels_str.split(',')] for label_group in label_groups: equal_labels_fallback.append( [label.strip() for label in label_group.split(':')]) equal_labels = get_image_equal_labels(self.workflow, equal_labels_fallback) if equal_labels: equal_labels_sets = [] for equal_set in equal_labels: equal_labels_sets.append(':'.join(equal_set)) equal_labels_string = ','.join(equal_labels_sets) self.config_kwargs['equal_labels'] = equal_labels_string self.config_kwargs['prefer_schema1_digest'] =\ get_prefer_schema1_digest(self.workflow, self.config_kwargs.get('prefer_schema1_digest')) registry_api_ver = self.config_kwargs.get('registry_api_versions') self.config_kwargs['registry_api_versions'] =\ ','.join(get_content_versions(self.workflow, registry_api_ver.split(',') if registry_api_ver else ())) self.config_kwargs['yum_proxy'] =\ get_yum_proxy(self.workflow, self.config_kwargs.get('yum_proxy')) self.config_kwargs['sources_command'] =\ get_sources_command(self.workflow, self.config_kwargs.get('sources_command'))
def __init__( self, tasker, workflow, odcs_url=None, odcs_insecure=False, odcs_openidc_secret_path=None, odcs_ssl_secret_path=None, koji_target=None, koji_hub=None, koji_ssl_certs_dir=None, signing_intent=None, compose_ids=tuple(), minimum_time_to_expire=MINIMUM_TIME_TO_EXPIRE, ): """ :param tasker: DockerTasker instance :param workflow: DockerBuildWorkflow instance :param odcs_url: URL of ODCS (On Demand Compose Service) :param odcs_insecure: If True, don't check SSL certificates for `odcs_url` :param odcs_openidc_secret_path: directory to look in for a `token` file :param odcs_ssl_secret_path: directory to look in for `cert` file - a PEM file containing both cert and key :param koji_target: str, contains build tag to be used when requesting compose from "tag" :param koji_hub: str, koji hub (xmlrpc), required if koji_target is used :param koji_ssl_certs_dir: str, path to "cert", and "serverca" used when Koji's identity certificate is not trusted :param signing_intent: override the signing intent from git repo configuration :param compose_ids: use the given compose_ids instead of requesting a new one :param minimum_time_to_expire: int, used in deciding when to extend compose's time to expire in seconds """ super(ResolveComposesPlugin, self).__init__(tasker, workflow) if signing_intent and compose_ids: raise ValueError( 'signing_intent and compose_ids cannot be used at the same time' ) self.signing_intent = signing_intent self.compose_ids = compose_ids self.odcs_fallback = { 'api_url': odcs_url, 'insecure': odcs_insecure, 'auth': { 'ssl_certs_dir': odcs_ssl_secret_path, 'openidc_dir': odcs_openidc_secret_path } } self.koji_target = koji_target self.koji_fallback = { 'hub_url': koji_hub, 'auth': { 'ssl_certs_dir': koji_ssl_certs_dir } } if koji_target: if not get_koji(self.workflow, self.koji_fallback)['hub_url']: raise ValueError( 'koji_hub is required when koji_target is used') self.minimum_time_to_expire = minimum_time_to_expire self._koji_session = None self._odcs_client = None self.odcs_config = None self.compose_config = None self.composes_info = None self._parent_signing_intent = None
def adjust_config_kwargs(self): koji_fallback = { 'hub_url': self.config_kwargs.get('koji_hub'), 'root_url': self.config_kwargs.get('koji_root') } koji_map = get_koji(self.workflow, koji_fallback) self.config_kwargs['koji_hub'] = koji_map['hub_url'] self.config_kwargs['koji_root'] = koji_map['root_url'] odcs_fallback = { 'api_url': self.config_kwargs.get('odcs_url'), 'insecure': self.config_kwargs.get('odcs_insecure') } odcs_map = get_odcs(self.workflow, odcs_fallback) self.config_kwargs['odcs_url'] = odcs_map['api_url'] self.config_kwargs['odcs_insecure'] = odcs_map.get('insecure', False) pulp_fallback = {'name': self.config_kwargs.get('pulp_registry_name')} pulp_map = get_pulp(self.workflow, pulp_fallback) self.config_kwargs['pulp_registry_name'] = pulp_map['name'] smtp_fallback = { 'host': self.config_kwargs.get('smtp_host'), 'from_address': self.config_kwargs.get('smtp_from'), 'domain': self.config_kwargs.get('smtp_email_domain'), 'send_to_submitter': self.config_kwargs.get('smtp_to_submitter'), 'send_to_pkg_owner': self.config_kwargs.get('smtp_to_pkgowner') } additional_addresses = self.config_kwargs.get('smtp_error_addresses') error_addresses = self.config_kwargs.get('smtp_additional_addresses') smtp_fallback['additional_addresses'] =\ additional_addresses.split(',') if additional_addresses else () smtp_fallback['error_addresses'] = error_addresses.split(',') if error_addresses else () smtp_map = get_smtp(self.workflow, smtp_fallback) self.config_kwargs['smtp_additional_addresses'] =\ ','.join(smtp_map.get('additional_addresses', ())) self.config_kwargs['smtp_email_domain'] = smtp_map.get('domain') self.config_kwargs['smtp_error_addresses'] = ','.join(smtp_map.get('error_addresses', ())) self.config_kwargs['smtp_from'] = smtp_map['from_address'] self.config_kwargs['smtp_host'] = smtp_map['host'] self.config_kwargs['smtp_to_pkgowner'] = smtp_map.get('send_to_pkg_owner', False) self.config_kwargs['smtp_to_submitter'] = smtp_map.get('send_to_submitter', False) source_reg = self.config_kwargs.get('source_registry_uri') souce_registry = get_source_registry(self.workflow, { 'uri': RegistryURI(source_reg) if source_reg else None})['uri'] self.config_kwargs['source_registry_uri'] = souce_registry.uri if souce_registry else None artifacts = self.config_kwargs.get('artifacts_allowed_domains') self.config_kwargs['artifacts_allowed_domains'] =\ ','.join(get_artifacts_allowed_domains( self.workflow, artifacts.split(',') if artifacts else ())) equal_labels_fallback = [] equal_labels_str = self.config_kwargs.get('equal_labels') if equal_labels_str: label_groups = [x.strip() for x in equal_labels_str.split(',')] for label_group in label_groups: equal_labels_fallback.append([label.strip() for label in label_group.split(':')]) equal_labels = get_image_equal_labels(self.workflow, equal_labels_fallback) if equal_labels: equal_labels_sets = [] for equal_set in equal_labels: equal_labels_sets.append(':'.join(equal_set)) equal_labels_string = ','.join(equal_labels_sets) self.config_kwargs['equal_labels'] = equal_labels_string self.config_kwargs['prefer_schema1_digest'] =\ get_prefer_schema1_digest(self.workflow, self.config_kwargs.get('prefer_schema1_digest')) registry_api_ver = self.config_kwargs.get('registry_api_versions') self.config_kwargs['registry_api_versions'] =\ ','.join(get_content_versions(self.workflow, registry_api_ver.split(',') if registry_api_ver else ())) self.config_kwargs['yum_proxy'] =\ get_yum_proxy(self.workflow, self.config_kwargs.get('yum_proxy')) self.config_kwargs['sources_command'] =\ get_sources_command(self.workflow, self.config_kwargs.get('sources_command'))
def __init__(self, tasker, workflow, smtp_host=None, from_address=None, send_on=(AUTO_CANCELED, AUTO_FAIL, MANUAL_SUCCESS, MANUAL_FAIL), url=None, error_addresses=(), additional_addresses=(), email_domain=None, koji_hub=None, koji_root=None, koji_proxyuser=None, koji_ssl_certs_dir=None, koji_krb_principal=None, koji_krb_keytab=None, to_koji_submitter=False, to_koji_pkgowner=False, use_auth=None, verify_ssl=None): """ constructor :param tasker: DockerTasker instance :param workflow: DockerBuildWorkflow instance :param send_on: list of str, list of build states when a notification should be sent see 'allowed_states' constant and rules in '_should_send' function :param url: str, URL to OSv3 instance where the build logs are stored :param smtp_host: str, URL of SMTP server to use to send the message (e.g. "foo.com:25") :param from_address: str, the "From" of the notification email :param error_addresses: list of str, list of email addresses where to send an email if an error occurred (e.g. if we can't find out who to notify about the failed build) :param additional_addresses: list of str, always send a message to these email addresses :param email_domain: str, email domain used when email addresses cannot be fetched via kerberos principal :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 to_koji_submitter: bool, send a message to the koji submitter :param to_koji_pkgowner: bool, send messages to koji package owners """ super(SendMailPlugin, self).__init__(tasker, workflow) self.submitter = self.DEFAULT_SUBMITTER self.send_on = set(send_on) self.smtp_fallback = { 'host': smtp_host, 'from_address': from_address, 'additional_addresses': list(additional_addresses), 'error_addresses': list(error_addresses), 'domain': email_domain, 'send_to_submitter': to_koji_submitter, 'send_to_pkg_owner': to_koji_pkgowner } smtp = get_smtp(self.workflow, self.smtp_fallback) self.additional_addresses = smtp.get('additional_addresses', ()) self.from_address = smtp['from_address'] self.error_addresses = smtp.get('error_addresses', ()) self.email_domain = smtp.get('domain') self.to_koji_submitter = smtp.get('send_to_submitter', False) self.to_koji_pkgowner = smtp.get('send_to_pkg_owner', False) 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.openshift_fallback = { 'url': url, 'insecure': not verify_ssl, 'auth': {'enable': use_auth} } self.url = get_openshift(self.workflow, self.openshift_fallback)['url'] try: metadata = get_build_json().get("metadata", {}) self.koji_task_id = int(metadata['labels']['koji-task-id']) except Exception: self.log.exception("Failed to fetch koji task ID") self.koji_task_id = None else: self.log.info("Koji task ID: %s", self.koji_task_id) self.koji_build_id = self.workflow.exit_results.get(KojiImportPlugin.key) if not self.koji_build_id: self.koji_build_id = self.workflow.exit_results.get(KojiPromotePlugin.key) if not self.koji_build_id: self.log.info("Failed to fetch koji build ID") else: self.log.info("Koji build ID: %s", self.koji_build_id) else: self.log.info("Koji build ID: %s", self.koji_build_id) self.session = None if get_koji(self.workflow, self.koji_fallback)['hub_url']: try: self.session = get_koji_session(self.workflow, self.koji_fallback) except Exception: self.log.exception("Failed to connect to koji") self.session = None else: self.log.info("Koji connection established")
def __init__(self, tasker, workflow, smtp_host=None, from_address=None, send_on=(AUTO_CANCELED, AUTO_FAIL, MANUAL_SUCCESS, MANUAL_FAIL), url=None, error_addresses=(), additional_addresses=(), email_domain=None, koji_hub=None, koji_root=None, koji_proxyuser=None, koji_ssl_certs_dir=None, koji_krb_principal=None, koji_krb_keytab=None, to_koji_submitter=False, to_koji_pkgowner=False, use_auth=None, verify_ssl=None): """ constructor :param tasker: DockerTasker instance :param workflow: DockerBuildWorkflow instance :param send_on: list of str, list of build states when a notification should be sent see 'allowed_states' constant and rules in '_should_send' function :param url: str, URL to OSv3 instance where the build logs are stored :param smtp_host: str, URL of SMTP server to use to send the message (e.g. "foo.com:25") :param from_address: str, the "From" of the notification email :param error_addresses: list of str, list of email addresses where to send an email if an error occurred (e.g. if we can't find out who to notify about the failed build) :param additional_addresses: list of str, always send a message to these email addresses :param email_domain: str, email domain used when email addresses cannot be fetched via kerberos principal :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 to_koji_submitter: bool, send a message to the koji submitter :param to_koji_pkgowner: bool, send messages to koji package owners """ super(SendMailPlugin, self).__init__(tasker, workflow) self.submitter = self.DEFAULT_SUBMITTER self.send_on = set(send_on) self.smtp_fallback = { 'host': smtp_host, 'from_address': from_address, 'additional_addresses': list(additional_addresses), 'error_addresses': list(error_addresses), 'domain': email_domain, 'send_to_submitter': to_koji_submitter, 'send_to_pkg_owner': to_koji_pkgowner } smtp = get_smtp(self.workflow, self.smtp_fallback) self.additional_addresses = smtp.get('additional_addresses', ()) self.from_address = smtp['from_address'] self.error_addresses = smtp.get('error_addresses', ()) self.email_domain = smtp.get('domain') self.to_koji_submitter = smtp.get('send_to_submitter', False) self.to_koji_pkgowner = smtp.get('send_to_pkg_owner', False) 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.openshift_fallback = { 'url': url, 'insecure': not verify_ssl, 'auth': { 'enable': use_auth } } self.url = get_openshift(self.workflow, self.openshift_fallback)['url'] try: metadata = get_build_json().get("metadata", {}) self.koji_task_id = int(metadata['labels']['koji-task-id']) except Exception: self.log.exception("Failed to fetch koji task ID") self.koji_task_id = None else: self.log.info("Koji task ID: %s", self.koji_task_id) self.koji_build_id = self.workflow.exit_results.get( KojiImportPlugin.key) if not self.koji_build_id: self.koji_build_id = self.workflow.exit_results.get( KojiPromotePlugin.key) if not self.koji_build_id: self.log.info("Failed to fetch koji build ID") else: self.log.info("Koji build ID: %s", self.koji_build_id) else: self.log.info("Koji build ID: %s", self.koji_build_id) self.session = None if get_koji(self.workflow, self.koji_fallback)['hub_url']: try: self.session = get_koji_session(self.workflow, self.koji_fallback) except Exception: self.log.exception("Failed to connect to koji") self.session = None else: self.log.info("Koji connection established")
def __init__(self, tasker, workflow, odcs_url=None, odcs_insecure=False, odcs_openidc_secret_path=None, odcs_ssl_secret_path=None, koji_target=None, koji_hub=None, koji_ssl_certs_dir=None, signing_intent=None, compose_ids=tuple(), repourls=None, minimum_time_to_expire=MINIMUM_TIME_TO_EXPIRE, ): """ :param tasker: DockerTasker instance :param workflow: DockerBuildWorkflow instance :param odcs_url: URL of ODCS (On Demand Compose Service) :param odcs_insecure: If True, don't check SSL certificates for `odcs_url` :param odcs_openidc_secret_path: directory to look in for a `token` file :param odcs_ssl_secret_path: directory to look in for `cert` file - a PEM file containing both cert and key :param koji_target: str, contains build tag to be used when requesting compose from "tag" :param koji_hub: str, koji hub (xmlrpc), required if koji_target is used :param koji_ssl_certs_dir: str, path to "cert", and "serverca" used when Koji's identity certificate is not trusted :param signing_intent: override the signing intent from git repo configuration :param compose_ids: use the given compose_ids instead of requesting a new one :param repourls: list of str, URLs to the repo files :param minimum_time_to_expire: int, used in deciding when to extend compose's time to expire in seconds """ super(ResolveComposesPlugin, self).__init__(tasker, workflow) if signing_intent and compose_ids: raise ValueError('signing_intent and compose_ids cannot be used at the same time') self.signing_intent = signing_intent self.compose_ids = compose_ids self.odcs_fallback = { 'api_url': odcs_url, 'insecure': odcs_insecure, 'auth': { 'ssl_certs_dir': odcs_ssl_secret_path, 'openidc_dir': odcs_openidc_secret_path } } self.koji_target = koji_target self.koji_fallback = { 'hub_url': koji_hub, 'auth': { 'ssl_certs_dir': koji_ssl_certs_dir } } if koji_target: if not get_koji(self.workflow, self.koji_fallback)['hub_url']: raise ValueError('koji_hub is required when koji_target is used') self.minimum_time_to_expire = minimum_time_to_expire self._koji_session = None self._odcs_client = None self.odcs_config = None self.compose_config = None self.composes_info = None self._parent_signing_intent = None self.repourls = repourls or [] self.inherit = self.workflow.source.config.inherit self.plugin_result = self.workflow.prebuild_results.get(PLUGIN_KOJI_PARENT_KEY) self.allow_inheritance = self.inherit and not (is_scratch_build() or is_isolated_build()) self.all_compose_ids = list(self.compose_ids)