From db6931b73561281b6fd9a69ab79e40a4bcdcef3a Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Feb 07 2022 09:10:31 +0000 Subject: PR#3228: api: checksum_type filter for listArchives Merges #3228 https://pagure.io/koji/pull-request/3228 Fixes: #3227 https://pagure.io/koji/issue/3227 listArchives should allow also checksum_type specification. --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 26837c4..81cdbc6 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -4850,8 +4850,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. @@ -4860,8 +4860,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: @@ -4877,6 +4877,16 @@ def list_archives(buildID=None, buildrootID=None, componentBuildrootID=None, hos checksum: checksum of the archive (string) checksum_type: the checksum type (integer) + 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 build environment setup (boolean) @@ -4968,6 +4978,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'],