Example #1
0
    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"
Example #2
0
    def get_build(self, metadata, worker_metadatas):
        start_time = int(atomic_reactor_start_time)
        extra = {'image': {}, 'osbs_build': {'subtypes': []}}

        self._update_extra(extra, metadata, worker_metadatas)

        koji_task_id = metadata.get('labels', {}).get('koji-task-id')
        if koji_task_id is not None:
            self.log.info("build configuration created by Koji Task ID %s",
                          koji_task_id)
            try:
                extra['container_koji_task_id'] = int(koji_task_id)
                self.koji_task_id = int(koji_task_id)
            except ValueError:
                self.log.error("invalid task ID %r", koji_task_id, exc_info=1)

        koji_task_owner = get_koji_task_owner(self.session, koji_task_id).get('name')
        extra['submitter'] = self.session.getLoggedInUser()['name']

        self.set_media_types(extra, worker_metadatas)

        build = {
            'start_time': start_time,
            'end_time': int(time.time()),
            'extra': extra,
            'owner': koji_task_owner,
        }

        self._update_build(build)

        return build
    def get_koji_user(self):
        unknown_user = self.workflow.conf.cachito.get('unknown_user', 'unknown_user')
        try:
            koji_task_id = int(self.workflow.user_params.get('koji_task_id'))
        except (ValueError, TypeError, AttributeError):
            msg = 'Unable to get koji user: Invalid Koji task ID'
            self.log.warning(msg)
            return unknown_user

        koji_session = get_koji_session(self.workflow.conf)
        return get_koji_task_owner(koji_session, koji_task_id).get('name', unknown_user)
Example #4
0
    def get_build(self):
        start_time = int(atomic_reactor_start_time)
        koji_task_owner = get_koji_task_owner(self.session,
                                              self.koji_task_id).get('name')

        build = {
            'start_time': start_time,
            'end_time': int(time.time()),
            'extra': self._get_build_extra(),
            'owner': koji_task_owner,
        }

        self._update_build(build)

        return build
Example #5
0
    def get_build(self):
        start_time = get_pipeline_run_start_time(
            self.workflow.osbs, self.workflow.pipeline_run_name)
        start_ts = start_time.timestamp()
        koji_task_owner = get_koji_task_owner(self.session,
                                              self.koji_task_id).get('name')

        build = {
            'start_time': int(start_ts),
            'end_time': int(time.time()),
            'extra': self._get_build_extra(),
            'owner': koji_task_owner,
        }

        self._update_build(build)

        return build
Example #6
0
    def get_koji_user(self):
        unknown_user = get_cachito(self.workflow).get('unknown_user',
                                                      'unknown_user')
        try:
            metadata = get_build_json()['metadata']
        except KeyError:
            msg = 'Unable to get koji user: No build metadata'
            self.log.warning(msg)
            return unknown_user

        try:
            koji_task_id = int(metadata.get('labels').get('koji-task-id'))
        except (ValueError, TypeError, AttributeError):
            msg = 'Unable to get koji user: Invalid Koji task ID'
            self.log.warning(msg)
            return unknown_user

        koji_session = get_koji_session(self.workflow)
        return get_koji_task_owner(koji_session,
                                   koji_task_id).get('name', unknown_user)
Example #7
0
    def test_get_email_from_koji_obj(self, monkeypatch, has_kerberos,
                                     koji_task_id, email_domain, expected_email):
        class WF(object):
            exit_results = {
                KojiImportPlugin.key: MOCK_KOJI_BUILD_ID
            }
            plugin_workspace = {}

        monkeypatch.setenv("BUILD", json.dumps({
            'metadata': {
                'labels': {
                    'koji-task-id': koji_task_id,
                },
                'name': {},
            }
        }))

        session = MockedClientSession('', has_kerberos=has_kerberos)
        flexmock(koji, ClientSession=lambda hub, opts: session)
        workflow = WF()

        workflow.plugin_workspace[ReactorConfigPlugin.key] = {}
        workflow.plugin_workspace[ReactorConfigPlugin.key][WORKSPACE_CONF_KEY] =\
            ReactorConfig({'version': 1})
        add_koji_map_in_workflow(workflow, hub_url='/', root_url='',
                                 ssl_certs_dir='/certs')

        p = SendMailPlugin(None, 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"
Example #8
0
 def _get_koji_submitter(self):
     koji_task_owner = get_koji_task_owner(self.session, self.koji_task_id)
     koji_task_owner_email = self._get_email_from_koji_obj(koji_task_owner)
     self.submitter = koji_task_owner_email
     return koji_task_owner_email
    def get_build(self, metadata, worker_metadatas):
        start_time = int(atomic_reactor_start_time)
        extra = {'image': {}, 'osbs_build': {'subtypes': []}}

        if not self.source_build:
            labels = Labels(df_parser(self.workflow.builder.df_path,
                                      workflow=self.workflow).labels)
            _, component = labels.get_name_and_value(Labels.LABEL_TYPE_COMPONENT)
            _, version = labels.get_name_and_value(Labels.LABEL_TYPE_VERSION)
            _, release = labels.get_name_and_value(Labels.LABEL_TYPE_RELEASE)

            source = self.workflow.source
            if not isinstance(source, GitSource):
                raise RuntimeError('git source required')

            extra['image']['autorebuild'] = is_rebuild(self.workflow)
            if self.workflow.triggered_after_koji_task:
                extra['image']['triggered_after_koji_task'] =\
                    self.workflow.triggered_after_koji_task

            try:
                isolated = str(metadata['labels']['isolated']).lower() == 'true'
            except (IndexError, AttributeError, KeyError):
                isolated = False
            self.log.info("build is isolated: %r", isolated)
            extra['image']['isolated'] = isolated

            fs_result = self.workflow.prebuild_results.get(AddFilesystemPlugin.key)
            if fs_result is not None:
                try:
                    fs_task_id = fs_result['filesystem-koji-task-id']
                except KeyError:
                    self.log.error("%s: expected filesystem-koji-task-id in result",
                                   AddFilesystemPlugin.key)
                else:
                    try:
                        task_id = int(fs_task_id)
                    except ValueError:
                        self.log.error("invalid task ID %r", fs_task_id, exc_info=1)
                    else:
                        extra['filesystem_koji_task_id'] = task_id

            extra['image'].update(get_parent_image_koji_data(self.workflow))

            flatpak_compose_info = get_flatpak_compose_info(self.workflow)
            if flatpak_compose_info:
                koji_metadata = flatpak_compose_info.koji_metadata()
                koji_metadata['flatpak'] = True
                extra['image'].update(koji_metadata)
                extra['osbs_build']['subtypes'].append('flatpak')

            resolve_comp_result = self.workflow.prebuild_results.get(PLUGIN_RESOLVE_COMPOSES_KEY)
            if resolve_comp_result:
                extra['image']['odcs'] = {
                    'compose_ids': [item['id'] for item in resolve_comp_result['composes']],
                    'signing_intent': resolve_comp_result['signing_intent'],
                    'signing_intent_overridden': resolve_comp_result['signing_intent_overridden'],
                }
            if self.workflow.all_yum_repourls:
                extra['image']['yum_repourls'] = self.workflow.all_yum_repourls

            self.set_help(extra, worker_metadatas)
            self.set_operators_metadata(extra, worker_metadatas)
            self.set_remote_sources_metadata(extra)

            self.set_go_metadata(extra)
            self.set_group_manifest_info(extra, worker_metadatas)
            extra['osbs_build']['kind'] = KOJI_KIND_IMAGE_BUILD
            extra['osbs_build']['engine'] = self.workflow.builder.tasker.build_method
            if has_operator_appregistry_manifest(self.workflow):
                extra['osbs_build']['subtypes'].append(KOJI_SUBTYPE_OP_APPREGISTRY)
            if has_operator_bundle_manifest(self.workflow):
                extra['osbs_build']['subtypes'].append(KOJI_SUBTYPE_OP_BUNDLE)
        else:
            source_result = self.workflow.prebuild_results[PLUGIN_FETCH_SOURCES_KEY]
            extra['image']['sources_for_nvr'] = source_result['sources_for_nvr']
            extra['image']['sources_signing_intent'] = source_result['signing_intent']
            extra['osbs_build']['kind'] = KOJI_KIND_IMAGE_SOURCE_BUILD
            extra['osbs_build']['engine'] = KOJI_SOURCE_ENGINE

        koji_task_id = metadata.get('labels', {}).get('koji-task-id')
        if koji_task_id is not None:
            self.log.info("build configuration created by Koji Task ID %s",
                          koji_task_id)
            try:
                extra['container_koji_task_id'] = int(koji_task_id)
            except ValueError:
                self.log.error("invalid task ID %r", koji_task_id, exc_info=1)

        koji_task_owner = get_koji_task_owner(self.session, koji_task_id).get('name')
        extra['submitter'] = self.session.getLoggedInUser()['name']

        self.set_media_types(extra, worker_metadatas)

        build = {
            'start_time': start_time,
            'end_time': int(time.time()),
            'extra': extra,
            'owner': koji_task_owner,
        }
        if self.source_build:
            build.update({
                'name': self.workflow.koji_source_nvr['name'],
                'version': self.workflow.koji_source_nvr['version'],
                'release': self.workflow.koji_source_nvr['release'],
                'source': self.workflow.koji_source_source_url,
            })
        else:
            build.update({
                'name': component,
                'version': version,
                'release': release,
                'source': "{0}#{1}".format(source.uri, source.commit_id),
            })

        return build