def create_or_update_build(self, build, event_id): """ Use the Koji Task Result to create or update a ContainerKojiBuild. :param dict build: the build represented in Freshmaker being created or updated :param int event_id: the id of the Freshmaker event :return: the created/updated ContainerKojiBuild or None if it cannot be created :rtype: ContainerKojiBuild or None """ # Builds in Koji only exist when the Koji task this Freshmaker build represents completes if build['state_name'] != 'DONE': log.debug( 'Skipping build update for event {0} because the build is not complete yet' .format(event_id)) return None try: koji_task_result = self.koji_session.getTaskResult( build['build_id']) except Exception: log.error('Failed to get the Koji task result with ID {0}'.format( build['build_id'])) raise if not koji_task_result.get('koji_builds'): log.warn( 'The task result of {0} does not contain the koji_builds key'. format(build['build_id'])) return None # The ID is returned as a string so it must be cast to an int koji_build_id = int(koji_task_result['koji_builds'][0]) # It's always going to be a container build when the build comes from Freshmaker, so we can # just set force_container_label to avoid unncessary heuristic checks return self.get_or_create_build(koji_build_id, build['original_nvr'], force_container_label=True)
def __init__(self, config): """ Initialize the handler. :param dict config: the fedmsg configuration """ self._koji_session = None self.config = config if config.get('estuary_updater.neo4j_url'): neomodel.config.DATABASE_URL = config['estuary_updater.neo4j_url'] else: log.warn('The configuration "estuary_updater.neo4j_url" was not set, so the default ' 'will be used') neomodel.config.DATABASE_URL = 'bolt://*****:*****@localhost:7687'
def build_state_handler(self, msg): """ Handle a Freshmaker build state changed message and update Neo4j if necessary. :param dict msg: a message to be processed """ build_info = msg['body']['msg'] event_id = msg['body']['msg']['event_id'] build = self.create_or_update_build(build_info, event_id) if build: event = FreshmakerEvent.nodes.get_or_none(id_=str(event_id)) if event: event.triggered_container_builds.connect(build) else: log.warn( 'The Freshmaker event {0} does not exist in Neo4j'.format( event_id))
def event_state_handler(self, msg): """ Handle a Freshmaker event state changed message and update Neo4j if necessary. :param dict msg: a message to be processed """ msg_id = msg['body']['msg']['message_id'] if msg['body']['msg'].get('dry_run'): return event_params = { 'id_': str(msg['body']['msg']['id']), 'state_name': msg['body']['msg']['state_name'], 'state_reason': msg['body']['msg']['state_reason'] } if 'time_created' in msg['body']['msg']: event_params['time_created'] = timestamp_to_datetime( msg['body']['msg']['time_created']) if 'time_done' in msg['body']['msg'] and msg['body']['msg'][ 'time_done'] is not None: event_params['time_done'] = timestamp_to_datetime( msg['body']['msg']['time_done']) event = FreshmakerEvent.create_or_update(event_params)[0] advisory_name = msg_id.rsplit('.', 1)[-1] if advisory_name[0:4] not in ('RHSA', 'RHBA', 'RHEA'): log.warn( 'Unable to parse the advisory name from the Freshmaker message_id: {0}' .format(msg_id)) advisory_name = None advisory = Advisory.get_or_create({ 'id_': msg['body']['msg']['search_key'], 'advisory_name': advisory_name })[0] event.conditional_connect(event.triggered_by_advisory, advisory)
def event_state_handler(self, msg): """ Handle a Freshmaker event state changed message and update Neo4j if necessary. :param dict msg: a message to be processed """ msg_id = msg['body']['msg']['message_id'] event = FreshmakerEvent.create_or_update({ 'id_': str(msg['body']['msg']['id']), 'event_type_id': msg['body']['msg']['event_type_id'], 'message_id': msg_id, 'state': msg['body']['msg']['state'], 'state_name': msg['body']['msg']['state_name'], 'state_reason': msg['body']['msg']['state_reason'] })[0] advisory_name = msg_id.rsplit('.', 1)[-1] if advisory_name[0:4] not in ('RHSA', 'RHBA', 'RHEA'): log.warn( 'Unable to parse the advisory name from the Freshmaker message_id: {0}' .format(msg_id)) advisory_name = None advisory = Advisory.get_or_create({ 'id_': msg['body']['msg']['search_key'], 'advisory_name': advisory_name })[0] event.conditional_connect(event.triggered_by_advisory, advisory)