From 2d1cf41e544e12d9850525e03d91e2c53776beb3 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Jan 31 2022 13:53:05 +0000 Subject: [PATCH 1/2] api: checksum_type filter for listArchives Related: https://pagure.io/koji/issue/3227 --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 40dfe8b..52ba919 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -4848,8 +4848,8 @@ def add_btype(name): def list_archives(buildID=None, buildrootID=None, componentBuildrootID=None, hostID=None, - type=None, filename=None, size=None, checksum=None, typeInfo=None, - queryOpts=None, imageID=None, archiveID=None, strict=False): + type=None, filename=None, size=None, checksum=None, checksum_type=None, + typeInfo=None, queryOpts=None, imageID=None, archiveID=None, strict=False): """ Retrieve information about archives. If buildID is not null it will restrict the list to archives built by the build with that ID. @@ -4858,8 +4858,8 @@ def list_archives(buildID=None, buildrootID=None, componentBuildrootID=None, hos If componentBuildrootID is not null it will restrict the list to archives that were present in the buildroot with that ID. If hostID is not null it will restrict the list to archives built on the host with that ID. - If filename, size, and/or checksum are not null it will filter the results to entries matching - the provided values. + If filename, size, checksum and/or checksum_type are not null it will filter + the results to entries matching the provided values. Returns a list of maps containing the following keys: @@ -4875,6 +4875,13 @@ def list_archives(buildID=None, buildrootID=None, componentBuildrootID=None, hos checksum: checksum of the archive (string) checksum_type: the checksum type (integer) + For checksum/checksum_type you need to have in mind that earch archive + currently has only one checksum attached. So, it you don't find some + checksum for given type it doesn't mean that it doesn't really exist. + Different checksum_type could have been computed e.g. via content generator + import and koji doesn't need to have an opportunity to compute the other + ones. + If componentBuildrootID is specified, then the map will also contain the following key: project: whether the archive was pulled in as a project dependency, or as part of the build environment setup (boolean) @@ -4966,6 +4973,9 @@ def list_archives(buildID=None, buildrootID=None, componentBuildrootID=None, hos if checksum is not None: clauses.append('checksum = %(checksum)s') values['checksum'] = checksum + if checksum_type is not None: + clauses.append('checksum_type = %(checksum_type)s') + values['checksum_type'] = checksum_type if archiveID is not None: clauses.append('archiveinfo.id = %(archive_id)s') values['archive_id'] = archiveID diff --git a/tests/test_hub/test_list_archives.py b/tests/test_hub/test_list_archives.py index 219d972..5a921b2 100644 --- a/tests/test_hub/test_list_archives.py +++ b/tests/test_hub/test_list_archives.py @@ -124,6 +124,15 @@ class TestListArchives(DBQueryTestCase): clauses=['checksum = %(checksum)s'], values={'checksum': '7873f0a6dbf3abc07724e000ac9b3941'}) + def test_list_archives_checksum_type(self): + kojihub.list_archives(checksum_type=koji.CHECKSUM_TYPES['sha256']) + self.assertLastQueryEqual(tables=['archiveinfo'], + joins=['archivetypes on archiveinfo.type_id = archivetypes.id', + 'btype ON archiveinfo.btype_id = btype.id'], + clauses=['checksum_type = %(checksum_type)s'], + values={'checksum_type': koji.CHECKSUM_TYPES['sha256']}) + + def test_list_archives_archiveid(self): kojihub.list_archives(archiveID=1) self.assertLastQueryEqual(tables=['archiveinfo'], From 40a7a9688ec3254a1e2b819a275deacc7b5b3ffb Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Feb 07 2022 09:09:45 +0000 Subject: [PATCH 2/2] update docstring --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 52ba919..1afbe19 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -4875,12 +4875,15 @@ def list_archives(buildID=None, buildrootID=None, componentBuildrootID=None, hos checksum: checksum of the archive (string) checksum_type: the checksum type (integer) - For checksum/checksum_type you need to have in mind that earch archive - currently has only one checksum attached. So, it you don't find some - checksum for given type it doesn't mean that it doesn't really exist. - Different checksum_type could have been computed e.g. via content generator - import and koji doesn't need to have an opportunity to compute the other - ones. + Koji only stores one checksum type per archive. Some content generators + store md5 checksums in Koji, and others store sha256 checksums, and this may + change for older and newer archives as different content generators upgrade + to sha256. + + If you search for an archive by its sha256 checksum, and Koji has only + stored an md5 checksum record for that archive, then Koji will not return a + result for that archive. You may need to call listArchives multiple times, + once for each checksum_type you want to search. If componentBuildrootID is specified, then the map will also contain the following key: project: whether the archive was pulled in as a project dependency, or as part of the