From 0321eb619f477ee2d8358411fb7d12991902be66 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Mar 01 2023 13:46:29 +0000 Subject: [PATCH 1/2] update koji-check-builds for py3 --- diff --git a/src/bin/koji-check-builds b/src/bin/koji-check-builds index 9dea373..80b81a7 100755 --- a/src/bin/koji-check-builds +++ b/src/bin/koji-check-builds @@ -1,6 +1,7 @@ #!/usr/bin/python -import Queue # for exceptions +from __future__ import absolute_import +import six.moves.queue # for exceptions import cProfile from functools import partial import hashlib @@ -15,12 +16,15 @@ import time import dateutil import koji as _koji # koji declared using profile module in main() import rpm +from six.moves import range +from six.moves import zip logger = logging.getLogger('koji.checkbuilds') # an event to indicate that the feeder is done feeder_done = multiprocessing.Event() +workers_done = multiprocessing.Event() # queue to hold actions in the pipeline queue = multiprocessing.Queue() @@ -128,13 +132,12 @@ def main(): # wait for the queue to be empty queue.close() - queue.join_thread() # XXX is this right? - - assert queue.empty() + queue.join_thread() logger.info('Finished. Waiting for workers to stop.') for worker in workers: worker.join() + workers_done.set() logger.info('Workers finished') s_thread.join() @@ -181,8 +184,8 @@ def stats_thread(tracker): while True: try: method, args, kw = stats_queue.get(block=True, timeout=5) - except Queue.Empty: - if feeder_done.is_set() and queue.empty(): + except six.moves.queue.Empty: + if workers_done.is_set(): # is this enough? break continue @@ -378,7 +381,7 @@ def worker_main(opts): while True: try: build, opts = queue.get(block=True, timeout=5) - except Queue.Empty: + except six.moves.queue.Empty: if feeder_done.is_set(): # is this enough? break @@ -535,7 +538,7 @@ class BuildChecker(object): def verify_rpm(self, fn, ts, n_bytes): logger.debug('Verifying rpm %s', fn) start = time.time() - with open(fn, 'r') as fp: + with open(fn, 'rb') as fp: try: ts.hdrFromFdno(fp.fileno()) except rpm.error as ex: @@ -560,7 +563,7 @@ class BuildChecker(object): for rpminfo, [sigs] in zip(self.rpms, session.multiCall(strict=True)): for sig in sigs: sig_idx.setdefault(sig['sigkey'], []).append([rpminfo, sig]) - logger.debug('Keys for %s: %s', build['nvr'], sig_idx.keys()) + logger.debug('Keys for %s: %s', build['nvr'], list(sig_idx.keys())) for sigkey in sig_idx: cachedir = os.path.join(self.build_dir, 'data/sigcache/%s' % sigkey) if not os.path.isdir(cachedir): @@ -575,7 +578,7 @@ class BuildChecker(object): logger.warn("Cached signature missing: %s", cachefile) self.fail('sigcache.missing') continue - sighash = hashlib.md5(file(cachefile).read()).hexdigest() + sighash = hashlib.md5(open(cachefile, 'rb').read()).hexdigest() if sighash != sig['sighash']: logger.warn('Cached signature mismatch for %s\n' ' db: %s, file:%s', @@ -677,18 +680,22 @@ class BuildChecker(object): sumtype = koji.CHECKSUM_TYPES[sumtype] except KeyError: logger.error('Unknown sum type %s for %s', sumtype, fn) + stats.increment('checksum.unsupported') return if sumtype == 'md5': chk = hashlib.md5() elif sumtype == 'sha1': chk = hashlib.sha1() + elif sumtype == 'sha256': + chk = hashlib.sha256() else: logger.error('Unsupported sum type %s for %s', sumtype, fn) + stats.increment('checksum.unsupported') return logger.debug('Checking %s for %s', sumtype, fn) stats.increment('checksum.checked') start = time.time() - with file(fn, 'r') as fp: + with open(fn, 'rb') as fp: chunks = iter(partial(fp.read, 819200), b'') [chk.update(b) for b in chunks] n_bytes = fp.tell() From d8bcd48cb26219bc2c9c6b01c0983390031d1731 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Mar 01 2023 13:46:29 +0000 Subject: [PATCH 2/2] update koji-fix-build-symlink for py3 --- diff --git a/src/bin/koji-fix-build-symlink b/src/bin/koji-fix-build-symlink index d6dd334..84e0f35 100755 --- a/src/bin/koji-fix-build-symlink +++ b/src/bin/koji-fix-build-symlink @@ -1,6 +1,7 @@ #!/usr/bin/python -import Queue # for exceptions +from __future__ import absolute_import +import six.moves.queue # for exceptions import cProfile import grp import logging @@ -14,6 +15,7 @@ import time import dateutil import koji as _koji # koji declared using profile module in main() +from six.moves import range koji = _koji # until main() replaces @@ -198,7 +200,7 @@ def stats_thread(tracker): while True: try: method, args, kw = stats_queue.get(block=True, timeout=5) - except Queue.Empty: + except six.moves.queue.Empty: if workers_done.is_set(): # is this enough? break @@ -398,7 +400,7 @@ def worker_main(opts): while True: try: build, opts = build_queue.get(block=True, timeout=5) - except Queue.Empty: + except six.moves.queue.Empty: if feeder_done.is_set(): # is this enough? break