From eaa9b3754b7752e3530f4b9c81a43185e863f196 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Jul 02 2020 13:29:59 +0000 Subject: [PATCH 1/2] hub: importImage doesn't honor volume We're not sending updated build_info to the method and it is requesting data from db. There is not volume saved yet. Change is reusing modified buildinfo. Fixes: https://pagure.io/koji/issue/2355 --- diff --git a/hub/kojihub.py b/hub/kojihub.py index d756a78..826b531 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -9874,7 +9874,7 @@ def rpmdiff(basepath, rpmlist, hashes): 'rpmdiff output was:\n%s' % (os.path.basename(first_rpm), d.textdiff())) -def importImageInternal(task_id, build_id, imgdata): +def importImageInternal(task_id, build_info, imgdata): """ Import image info and the listing into the database, and move an image to the final resting place. The filesize may be reported as a string if it @@ -9897,7 +9897,6 @@ def importImageInternal(task_id, build_id, imgdata): koji.plugin.run_callbacks('preImport', type='image', image=imgdata) # import the build output - build_info = get_build(build_id, strict=True) workpath = koji.pathinfo.task(imgdata['task_id']) imgdata['relpath'] = koji.pathinfo.taskrelpath(imgdata['task_id']) archives = [] @@ -13775,7 +13774,7 @@ class HostExports(object): build_info['volume_name'] = vol['name'] vol_update = True - self.importImage(task_id, build_id, results) + self.importImage(task_id, build_info, results) ensure_volume_symlink(build_info) st_old = build_info['state'] @@ -14160,7 +14159,7 @@ class HostExports(object): _untag_build(fromtag, build, user_id=user_id, force=force, strict=True) _tag_build(tag, build, user_id=user_id, force=force) - def importImage(self, task_id, build_id, results): + def importImage(self, task_id, build_info, results): """ Import a built image, populating the database with metadata and moving the image to its final location. @@ -14169,11 +14168,11 @@ class HostExports(object): if 'task_id' not in sub_results: logger.warning('Task %s failed, no image available' % task_id) continue - importImageInternal(task_id, build_id, sub_results) + importImageInternal(task_id, build_info, sub_results) if 'rpmresults' in sub_results: rpm_results = sub_results['rpmresults'] _import_wrapper(rpm_results['task_id'], - get_build(build_id, strict=True), rpm_results) + get_build(build_info['id'], strict=True), rpm_results) def tagNotification(self, is_successful, tag_id, from_id, build_id, user_id, ignore_success=False, failure_msg=''): From f0eb97b8f3a46b86a9f0bbf2aea27314530370fc Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Jul 02 2020 13:40:44 +0000 Subject: [PATCH 2/2] fix tests --- diff --git a/tests/test_hub/test_import_image_internal.py b/tests/test_hub/test_import_image_internal.py index 34895b6..16ca13f 100644 --- a/tests/test_hub/test_import_image_internal.py +++ b/tests/test_hub/test_import_image_internal.py @@ -38,11 +38,14 @@ class TestImportImageInternal(unittest.TestCase): context.session.host_id = 42 get_build.return_value = { 'id': 2, + 'name': 'name', + 'version': 'version', + 'release': 'release', } get_archive_type.return_value = 4 work.return_value = self.tempdir os.makedirs(self.tempdir + "/tasks/1/1") - kojihub.importImageInternal(task_id=1, build_id=2, imgdata=imgdata) + kojihub.importImageInternal(task_id=1, build_info=get_build.return_value, imgdata=imgdata) @mock.patch('kojihub.get_rpm') @mock.patch('koji.pathinfo.build') @@ -76,10 +79,16 @@ class TestImportImageInternal(unittest.TestCase): ], 'rpmlist': [rpm], } + build_info = { + 'name': 'name', + 'version': 'version', + 'release': 'release', + 'id': 2 + } cursor = mock.MagicMock() context.cnx.cursor.return_value = cursor context.session.host_id = 42 - get_build.return_value = {'id': 2} + get_build.return_value = build_info get_rpm.return_value = rpm get_archive_type.return_value = 4 work.return_value = self.tempdir @@ -94,7 +103,7 @@ class TestImportImageInternal(unittest.TestCase): with open(workdir + '/foo.log', 'w'): pass - kojihub.importImageInternal(task_id=1, build_id=2, imgdata=imgdata) + kojihub.importImageInternal(task_id=1, build_info=build_info, imgdata=imgdata) # Check that the log symlink made it to where it was supposed to. dest = os.readlink(workdir + '/foo.log')