Esempio n. 1
0
    def _consume_real_build(self, msg):
        builds = list()  # These will be the Koji task IDs to upload, if any.

        msg = msg['body']['msg']
        if msg['owner'] != 'releng':
            log.debug("Dropping message.  Owned by %r" % msg['owner'])
            return

        if msg['instance'] != 'primary':
            log.info("Dropping message.  From %r instance." % msg['instance'])
            return

        # Don't upload *any* images if one of them fails.
        if msg['new'] != 1:
            log.info("Dropping message.  State is %r" % msg['new'])
            return

        koji_session = koji.ClientSession(autocloud.KOJI_SERVER_URL)
        children = koji_session.getTaskChildren(msg['task_id'])
        for child in children:
            if child["method"] == "createImage":
                builds.append(child["id"])

        if len(builds) > 0:
            produce_jobs(self._get_tasks(builds))
Esempio n. 2
0
    def _consume_scratch_task(self, msg):
        builds = list()  # These will be the Koji build IDs to upload, if any.

        msg_info = msg["body"]["msg"]["info"]

        log.info('Received %r %r' % (msg['topic'], msg['body']['msg_id']))

        # If the build method is "image", we check to see if the child
        # task's method is "createImage".
        if msg_info["method"] == "image":
            if isinstance(msg_info["children"], list):
                for child in msg_info["children"]:
                    if child["method"] == "createImage":
                        # We only care about the image if the build
                        # completed successfully (with state code 2).
                        if child["state"] == 2:
                            builds.append(child["id"])

        if len(builds) > 0:
            produce_jobs(self._get_tasks(builds))
Esempio n. 3
0
    def consume(self, msg):
        """ This is called when we receive a message matching the topic. """

        log.info('Received %r %r' % (msg['topic'], msg['body']['msg_id']))

        STATUS_F = ('FINISHED_INCOMPLETE', 'FINISHED',)

        images = []
        compose_db_update = False
        msg_body = msg['body']
        status = msg_body['msg']['status']
        compose_images_json = None

        # Till F27, both cloud-base and atomic images were available
        # under variant CloudImages. With F28 and onward releases,
        # cloud-base image compose moved to cloud variant and atomic images
        # moved under atomic variant.
        prev_rel = ['26', '27']
        if msg_body['msg']['release_version'] in prev_rel:
            VARIANTS_F = ('CloudImages',)
        else:
            VARIANTS_F = ('AtomicHost', 'Cloud')

        if status in STATUS_F:
            location = msg_body['msg']['location']
            json_metadata = '{}/metadata/images.json'.format(location)
            resp = requests.get(json_metadata)
            compose_images_json = getattr(resp, 'json', False)

        if compose_images_json is not None:
            compose_images_json = compose_images_json()
            compose_images = compose_images_json['payload']['images']
            compose_details = compose_images_json['payload']['compose']
            compose_images = dict((variant, compose_images[variant])
                                  for variant in VARIANTS_F
                                  if variant in compose_images)
            compose_id = compose_details['id']
            rel = fedfind.release.get_release(cid=compose_id)
            release = rel.release
            compose_details.update({'release': release})

            compose_images_variants = [variant for variant in VARIANTS_F
                                       if variant in compose_images]

            for variant in compose_images_variants:
                compose_image = compose_images[variant]
                for arch, payload in compose_image.iteritems():

                    if arch not in self.supported_archs:
                        continue

                    for item in payload:
                        relative_path = item['path']
                        if not is_valid_image(relative_path):
                            continue
                        absolute_path = '{}/{}'.format(location, relative_path)
                        item.update({
                            'compose': compose_details,
                            'absolute_path': absolute_path,
                        })
                        images.append(item)
                        compose_db_update = True

            if compose_db_update:
                session = init_model()
                compose_date = datetime.strptime(compose_details['date'], '%Y%m%d')
                try:
                    cd = ComposeDetails(
                        date=compose_date,
                        compose_id=compose_details['id'],
                        respin=compose_details['respin'],
                        type=compose_details['type'],
                        status=u'q',
                        location=location,
                    )

                    session.add(cd)
                    session.commit()

                    compose_details.update({
                        'status': 'queued',
                        'compose_job_id': cd.id,
                    })
                    publish_to_fedmsg(topic='compose.queued',
                                      **compose_details)
                except exc.IntegrityError:
                    session.rollback()
                    cd = session.query(ComposeDetails).filter_by(
                        compose_id=compose_details['id']).first()
                    log.info('Compose already exists %s: %s' % (
                        compose_details['id'],
                        cd.id
                    ))
                session.close()

            num_images = len(images)
            for pos, image in enumerate(images):
                image.update({'pos': (pos+1, num_images)})

            produce_jobs(images)
    def consume(self, msg):
        """ This is called when we receive a message matching the topic. """

        log.info('Received %r %r' % (msg['topic'], msg['body']['msg_id']))

        STATUS_F = ('FINISHED_INCOMPLETE', 'FINISHED',)
        VARIANTS_F = ('CloudImages',)

        images = []
        compose_db_update = False
        msg_body = msg['body']

        if msg_body['msg']['status'] in STATUS_F:
            location = msg_body['msg']['location']
            json_metadata = '{}/metadata/images.json'.format(location)

            resp = requests.get(json_metadata)
            compose_images_json = getattr(resp, 'json', False)

            if compose_images_json:
                compose_images_json = compose_images_json()

                compose_images = compose_images_json['payload']['images']
                compose_details = compose_images_json['payload']['compose']

                compose_images = dict(
                    (variant, compose_images[variant])
                    for variant in VARIANTS_F
                    if variant in compose_images
                )

                compose_id = compose_details['id']
                (release, _, _, _) = fedfind.helpers.parse_cid(compose_id)

                compose_details.update({'release': release})

                for variant in VARIANTS_F:

                    if variant not in compose_images:
                        continue

                    for arch, payload in compose_images[variant].iteritems():
                        for item in payload:
                            relative_path = item['path']

                            if not is_valid_image(relative_path):
                                continue

                            absolute_path = '{}/{}'.format(location,
                                                           relative_path)

                            item.update({
                                'compose': compose_details,
                                'absolute_path': absolute_path,
                            })
                            images.append(item)
                            compose_db_update = True

            if compose_db_update:
                session = init_model()
                compose_date = datetime.strptime(compose_details['date'],
                                                 '%Y%m%d')
                try:
                    cd = ComposeDetails(
                        date=compose_date,
                        compose_id=compose_details['id'],
                        respin=compose_details['respin'],
                        type=compose_details['type'],
                        status=u'q',
                        location=location,
                    )

                    session.add(cd)
                    session.commit()

                    compose_details.update({
                        'status': 'queued',
                        'compose_job_id': cd.id,
                    })
                    publish_to_fedmsg(topic='compose.queued',
                                      **compose_details)

                except exc.IntegrityError:
                    session.rollback()
                    cd = session.query(ComposeDetails).filter_by(
                        compose_id=compose_details['id']).first()
                    log.info('Compose already exists %s: %s' % (
                        compose_details['id'],
                        cd.id
                    ))

            num_images = len(images)
            for pos, image in enumerate(images):
                image.update({'pos': (pos+1, num_images)})

            produce_jobs(images)
Esempio n. 5
0
    def consume(self, msg):
        """ This is called when we receive a message matching the topic. """

        log.info('Received %r %r' % (msg['topic'], msg['body']['msg_id']))

        STATUS_F = (
            'FINISHED_INCOMPLETE',
            'FINISHED',
        )
        VARIANTS_F = ('CloudImages', )

        images = []
        compose_db_update = False
        msg_body = msg['body']

        if msg_body['msg']['status'] in STATUS_F:
            location = msg_body['msg']['location']
            json_metadata = '{}/metadata/images.json'.format(location)

            resp = requests.get(json_metadata)
            compose_images_json = getattr(resp, 'json', False)

            if compose_images_json:
                compose_images_json = compose_images_json()

                compose_images = compose_images_json['payload']['images']
                compose_details = compose_images_json['payload']['compose']

                compose_images = dict((variant, compose_images[variant])
                                      for variant in VARIANTS_F
                                      if variant in compose_images)

                compose_id = compose_details['id']
                rel = fedfind.release.get_release(cid=compose_id)
                release = rel.release

                compose_details.update({'release': release})

                for variant in VARIANTS_F:

                    if variant not in compose_images:
                        continue

                    for arch, payload in compose_images[variant].iteritems():
                        for item in payload:
                            relative_path = item['path']

                            if not is_valid_image(relative_path):
                                continue

                            absolute_path = '{}/{}'.format(
                                location, relative_path)

                            item.update({
                                'compose': compose_details,
                                'absolute_path': absolute_path,
                            })
                            images.append(item)
                            compose_db_update = True

            if compose_db_update:
                session = init_model()
                compose_date = datetime.strptime(compose_details['date'],
                                                 '%Y%m%d')
                try:
                    cd = ComposeDetails(
                        date=compose_date,
                        compose_id=compose_details['id'],
                        respin=compose_details['respin'],
                        type=compose_details['type'],
                        status=u'q',
                        location=location,
                    )

                    session.add(cd)
                    session.commit()

                    compose_details.update({
                        'status': 'queued',
                        'compose_job_id': cd.id,
                    })
                    publish_to_fedmsg(topic='compose.queued',
                                      **compose_details)

                except exc.IntegrityError:
                    session.rollback()
                    cd = session.query(ComposeDetails).filter_by(
                        compose_id=compose_details['id']).first()

                    log.info('Compose already exists %s: %s' %
                             (compose_details['id'], cd.id))

            num_images = len(images)
            for pos, image in enumerate(images):
                image.update({'pos': (pos + 1, num_images)})

            produce_jobs(images)