From 64f2467fd0abb9ad2a07d03bdb612614c99d7029 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Fri, 16 Jun 2017 14:38:19 +0200 Subject: [PATCH] kojifile component type --- docs/source/content_generator_metadata.rst | 8 +++++++ hub/kojihub.py | 25 ++++++++++++++++++++ tests/test_hub/cg_importer_json/default.json | 10 +++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/docs/source/content_generator_metadata.rst b/docs/source/content_generator_metadata.rst index e878ef6d..bf573244 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 63f929ee..8394bcbe 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -5360,6 +5360,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 @@ -5411,6 +5415,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 e8a20943..03eb4026 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}} }],