api: checksum_type filter for listArchives

Related: https://pagure.io/koji/issue/3227
This commit is contained in:
Tomas Kopecek 2022-01-26 10:38:15 +01:00
parent 7fe0d10d60
commit 66a94f045e
2 changed files with 23 additions and 4 deletions

View file

@ -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,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)
@ -4968,6 +4975,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

View file

@ -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'],