From 6dcd819b183adc88177b9c030fb663c7c500d6f4 Mon Sep 17 00:00:00 2001 From: Mike Bonnet Date: Nov 26 2019 16:50:15 +0000 Subject: [PATCH 1/3] fix argument type in format string Argument is a string, not a float. --- diff --git a/vm/kojikamid.py b/vm/kojikamid.py index b3df301..b2f0643 100755 --- a/vm/kojikamid.py +++ b/vm/kojikamid.py @@ -323,7 +323,7 @@ class WindowsBuild(object): elif fileinfo['checksum_type'] == 'md5': checksum = hashlib.md5() else: - raise BuildError('Unknown checksum type %s for %f' % ( + raise BuildError('Unknown checksum type %s for %s' % ( fileinfo['checksum_type'], os.path.basename(fileinfo['localpath']))) with open(destpath, 'w') as destfile: From 61d660612eb637bca549fb7d56f6c9600c9f8013 Mon Sep 17 00:00:00 2001 From: Mike Bonnet Date: Nov 26 2019 18:20:53 +0000 Subject: [PATCH 2/3] kojikamid.py: use urllib from six.moves kojikamid has the SCM class from daemon.py inserted into it at build time. This class has been converted to use urllib from six.moves (for Python 3 compatibility), rather than using urlparse. Update the import in kojikamid.py to be compatible with this change. --- diff --git a/vm/kojikamid.py b/vm/kojikamid.py index b2f0643..4f63ab9 100755 --- a/vm/kojikamid.py +++ b/vm/kojikamid.py @@ -34,9 +34,9 @@ import subprocess import sys import tempfile import time -# urlparse is required by the SCM class which is substituted into this file +# urllib is required by the SCM class which is substituted into this file # do not remove the import below -import urlparse +from six.moves import urllib import six.moves.xmlrpc_client import base64 import hashlib From 9146b011f33eef5405485f9a707f0e28d614f7ad Mon Sep 17 00:00:00 2001 From: Mike Bonnet Date: Nov 26 2019 19:06:55 +0000 Subject: [PATCH 3/3] include CHECKSUM_TYPES in kojikamid.py, and use it when validating checksums of downloaded files The Koji data model has been updated to support multiple checksum types. These are listed in the CHECKSUM_TYPES enum in koji/__init__.py, but are not available in kojikamid.py. This change copies the Enum class and the CHECKSUM_TYPES enum into kojikamid at build time, and uses it when validating the checksums of downloaded files. --- diff --git a/koji/__init__.py b/koji/__init__.py index a7925d3..6acd1bb 100644 --- a/koji/__init__.py +++ b/koji/__init__.py @@ -127,6 +127,7 @@ for h in ( 'RECOMMENDNAME', 'RECOMMENDVERSION', 'RECOMMENDFLAGS'): SUPPORTED_OPT_DEP_HDRS[h] = hasattr(rpm, 'RPMTAG_%s' % h) +## BEGIN kojikamid dup class Enum(dict): """A simple class to track our enumerated constants @@ -174,6 +175,8 @@ class Enum(dict): update = _notImplemented setdefault = _notImplemented +## END kojikamid dup + API_VERSION = 1 TASK_STATES = Enum(( @@ -262,12 +265,16 @@ TAG_UPDATE_TYPES = Enum(( 'MANUAL', )) +## BEGIN kojikamid dup + CHECKSUM_TYPES = Enum(( 'md5', 'sha1', 'sha256', )) +## END kojikamid dup + #PARAMETERS BASEDIR = '/mnt/koji' # default task priority diff --git a/vm/kojikamid.py b/vm/kojikamid.py index 4f63ab9..ed10101 100755 --- a/vm/kojikamid.py +++ b/vm/kojikamid.py @@ -316,15 +316,16 @@ class WindowsBuild(object): destpath = os.path.join(basedir, fileinfo['localpath']) ensuredir(os.path.dirname(destpath)) if 'checksum_type' in fileinfo: - if fileinfo['checksum_type'] == 'sha1': + checksum_type = CHECKSUM_TYPES[fileinfo['checksum_type']] + if checksum_type == 'sha1': checksum = hashlib.sha1() - elif fileinfo['checksum_type'] == 'sha256': + elif checksum_type == 'sha256': checksum = hashlib.sha256() - elif fileinfo['checksum_type'] == 'md5': + elif checksum_type == 'md5': checksum = hashlib.md5() else: raise BuildError('Unknown checksum type %s for %s' % ( - fileinfo['checksum_type'], + checksum_type, os.path.basename(fileinfo['localpath']))) with open(destpath, 'w') as destfile: offset = 0 @@ -338,12 +339,15 @@ class WindowsBuild(object): offset += len(data) if 'checksum_type' in fileinfo: checksum.update(data) - # rpms don't have a md5sum in the fileinfo, but check it for everything else - digest = checksum.hexdigest() - if 'checksum' in fileinfo and fileinfo['checksum'] != digest: - raise BuildError('checksum validation failed for %s, %s (computed) != %s (provided)' % \ - (destpath, digest, fileinfo['checksum'])) - self.logger.info('Retrieved %s (%s bytes, md5: %s)', destpath, offset, digest) + # rpms don't have a checksum in the fileinfo, but check it for everything else + if 'checksum_type' in fileinfo: + digest = checksum.hexdigest() + if fileinfo['checksum'] != digest: + raise BuildError('checksum validation failed for %s, %s (computed) != %s (provided)' % \ + (destpath, digest, fileinfo['checksum'])) + self.logger.info('Retrieved %s (%s bytes, %s: %s)', destpath, offset, checksum_type, digest) + else: + self.logger.info('Retrieved %s (%s bytes)', destpath, offset) def fetchBuildReqs(self): """Retrieve buildrequires listed in the spec file"""