From 37136f957a6988f71f3ac1f359842acc760bf452 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: May 11 2017 17:43:32 +0000 Subject: Check target only for the original build to which the package has been tagged, use build-tags inheritance for others. Signed-off-by: Jan Kaluza --- diff --git a/robosignatory/tagconsumer.py b/robosignatory/tagconsumer.py index 6a693fb..a77b02c 100644 --- a/robosignatory/tagconsumer.py +++ b/robosignatory/tagconsumer.py @@ -8,6 +8,8 @@ from pdc_client import PDCClient import logging log = logging.getLogger("robosignatory.tagconsumer") +class MultipleStreamsError(ValueError): + pass class TagSignerConsumer(fedmsg.consumers.FedmsgConsumer): config_key = 'robosignatory.enabled.tagsigner' @@ -127,7 +129,10 @@ class TagSignerConsumer(fedmsg.consumers.FedmsgConsumer): and tag['verified']. """ query = {} - query["koji_tag"] = tag["name"] + tag_name = tag["name"] + if tag_name.endswith("-build"): + tag_name = tag_name[:-len("-build")] + query["koji_tag"] = tag_name if active is not None: query["active"] = active retval = self.pdc_client.unreleasedvariants(page_size=-1, **query) @@ -142,6 +147,7 @@ class TagSignerConsumer(fedmsg.consumers.FedmsgConsumer): tag["verified"] = True tag["stream"] = retval[0]["variant_version"] + tag["name"] = tag_name return tag def get_base_module_tag(self, session, info, parent_tags=None): @@ -154,40 +160,16 @@ class TagSignerConsumer(fedmsg.consumers.FedmsgConsumer): if not info['name'].startswith(self.module_prefixes): return None - # Find all targets pointing to our current tag, there should be just - # single target for our tag. - targets = session.getBuildTargets(destTagID=info['id']) - if not targets: - return None - - # TODO: For now skip the -repo target. We are creating these targets - # for modules only to force kojira to create repo for the modules. - # We can remove these targets and this code once the composes will be - # be running, but for that, we need robosignatory to sign packages - # (chicken and egg)... - targets = [target for target in targets - if target['name'] != info['name'] + "-repo"] - - if len(targets) != 1: - log.info("Expected exactly 1 target for tag %s, skipping." - % info["name"]) - return None - - target = targets[0] - - # Get the build tag of this target. - build_tag_id = target["build_tag"] - build_tag_info = session.getTag(build_tag_id) # Store the dest_tag as a possible base tag (we don't know yet). - base_module_tag = {"id": target["dest_tag"], - "name": target["dest_tag_name"], + base_module_tag = {"id": info['id'], + "name": info['name'], "verified": False, "stream": None} # Get the inheritance data and filter out tags from parent_tags set. # Following those tags would bring us back to the already seen target. - inheritance_data = session.getInheritanceData(build_tag_info['name']) + inheritance_data = session.getInheritanceData(info['name']) inheritance_data = [data for data in inheritance_data if data['parent_id'] not in parent_tags] @@ -201,7 +183,11 @@ class TagSignerConsumer(fedmsg.consumers.FedmsgConsumer): # Get tag info for the parent_tag. info = session.getTag(parent_tag_id) if info is None: - return base_module_tag + continue + if not info['name'].endswith("-build"): + info = session.getTag(info['name'] + "-build") + if info is None: + continue # Check if parent_tag is valid base module tag. maybe_tag = self.verify_base_module_tag(info) @@ -220,9 +206,9 @@ class TagSignerConsumer(fedmsg.consumers.FedmsgConsumer): # are matching. if (base_module_tag['verified'] and maybe_tag['stream'] != base_module_tag['stream']): - log.warn("Multiple base module streams found in " - "inheritance tree.") - return None + err = "Multiple base module streams found in inheritance tree." + log.warn(err) + raise MultipleStreamsError(err) else: base_module_tag = maybe_tag @@ -238,9 +224,9 @@ class TagSignerConsumer(fedmsg.consumers.FedmsgConsumer): session = instance["client"] # Get the tag to find out its id. - info = session.getTag(tag) + info = session.getTag(tag + "-build") if info is None: - log.info("Koji tag %s not known, skipping" % tag) + log.info("Build tag for Koji tag %s not known, skipping" % tag) return # Try to find out if the current tag is a base module before traversing @@ -264,8 +250,12 @@ class TagSignerConsumer(fedmsg.consumers.FedmsgConsumer): parent_tags = set([info['id']]) # Resulting base module tag according to which we will use the right key. - base_module_tag = self.get_base_module_tag( - session, info, parent_tags=parent_tags) + try: + base_module_tag = self.get_base_module_tag( + session, info, parent_tags=parent_tags) + except MultipleStreamsError: + # Set to unverified tag + base_module_tag = maybe_tag # Set the cache to None, so in case this module build does not have # valid base module stream, we do not query PDC on every RPM, but just