From bd18ade2787243a044d238d577c7d163885be95a Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Jun 16 2017 12:38:19 +0000 Subject: [PATCH 1/2] kojifile component type --- diff --git a/docs/source/content_generator_metadata.rst b/docs/source/content_generator_metadata.rst index e878ef6..bf57324 100644 --- a/docs/source/content_generator_metadata.rst +++ b/docs/source/content_generator_metadata.rst @@ -108,6 +108,14 @@ Each map in the buildroots list contains the following entries: - checksum: The checksum of the file. - checksum\_type: The checksum type used. +- For maps where **type = kojifile**, the following fields will be present: + - filename: The name of the file. + - filesize: The size of the file. + - checksum: The checksum of the file. + - checksum\_type: The checksum type used. + - nvr: Build nvr from which this file origins. + - archive\_id: ID of archive from specified build. + - The format may be extended with other types in the future. - extra: A map containing information specific to the Content Generator that produced the files to import. For OSBS, the extra map should diff --git a/hub/kojihub.py b/hub/kojihub.py index d300038..9cb17b9 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -5331,6 +5331,10 @@ class CG_Importer(object): match = self.match_file(comp) if match: files.append(match) + elif comp['type'] == 'kojifile': + match = self.match_kojifile(comp) + if match: + files.append(match) else: raise koji.GenericError("Unknown component type: %(type)s" % comp) return rpms, files @@ -5382,6 +5386,27 @@ class CG_Importer(object): return None #raise koji.GenericError("No match: %(filename)s (size %(filesize)s, sum %(checksum)s" % comp) + def match_kojifile(self, comp): + # kojifile is identified by nvr + archive_id + filename + # additional checks by checksum + assert(comp['type'] == 'kojifile') + build = get_build(comp['nvr']) + if build is None: + logger.error("No match: NVR: %(nvr)" % comp) + return None + try: + archive = list_archives(buildID = build['id'], archiveID = comp['archive_id'])[0] + except IndexError: + logger.error("No match: NVR: %(nvr), Archive: %(archive_id)s" % comp) + return None + if archive['checksum_type'] != koji.CHECKSUM_TYPES[comp['checksum_type']]: + logger.error("Failed to match archive %(filename)s, unsupported checksum type: %(checksum_type)s" % archive) + elif archive['checksum'] != comp['checksum']: + logger.error("Failed to match archive %(filename)s (size %(filesize)s, sum %(checksum)s", comp) + else: + return archive + return None + def prep_outputs(self): metadata = self.metadata diff --git a/tests/test_hub/cg_importer_json/default.json b/tests/test_hub/cg_importer_json/default.json index e8a2094..03eb402 100644 --- a/tests/test_hub/cg_importer_json/default.json +++ b/tests/test_hub/cg_importer_json/default.json @@ -52,7 +52,15 @@ "filename": "jboss-eap-6.3.3-full-build.zip", "filesize": 12345678, "checksum": "5ec2f29c4e1c2e2aa6552836e236a158", - "checksum_type": "md5"}], + "checksum_type": "md5"}, + {"type": "kojifile", + "filename": "jboss-eap-6.4.10-1.win6.src.zip", + "filesize": 21670719, + "checksum": "215cf04db6bdbefb9644f001995bd550", + "checksum_type": "md5", + "archive_id": 1, + "nvr": "jboss-eap-6.4.10-1.win6"} + ], "extra": {"osbs": {"build_id": 12345, "builder_image_id": 67890}} }], From 76f8c4a2506eba9606983905ef11f8bd1664a1c0 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Jun 20 2017 12:38:39 +0000 Subject: [PATCH 2/2] check also filename/size --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 9cb17b9..b4ae4ff 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -5395,7 +5395,10 @@ class CG_Importer(object): logger.error("No match: NVR: %(nvr)" % comp) return None try: - archive = list_archives(buildID = build['id'], archiveID = comp['archive_id'])[0] + archive = list_archives(buildID = build['id'], + archiveID = comp['archive_id'], + filename=comp['filename'], + size=comp['filesize'])[0] except IndexError: logger.error("No match: NVR: %(nvr), Archive: %(archive_id)s" % comp) return None