From aeb8ba4b12eace0e3b6f5b824d9888452f55d4fb Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Oct 06 2017 21:16:03 +0000 Subject: apply volume_policy in import_build --- diff --git a/hub/kojihub.py b/hub/kojihub.py index adae789..a129970 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -5020,13 +5020,26 @@ def import_build(srpm, rpms, brmap=None, task_id=None, build_id=None, logs=None) #this will raise an exception if the buildroot id is invalid BuildRoot(br_id) - #read srpm info + # get build informaton fn = "%s/%s" % (uploadpath, srpm) build = koji.get_header_fields(fn, ('name', 'version', 'release', 'epoch', 'sourcepackage')) if build['sourcepackage'] != 1: raise koji.GenericError("not a source package: %s" % fn) build['task_id'] = task_id + + policy_data = { + 'prebuild': build, + 'package': build['name'], + 'buildroots': brmap.values(), + 'import': True, + 'import_type': 'rpm', + } + vol = check_volume_policy(policy_data, strict=False) + if vol: + build['volume_id'] = vol['id'] + build['volume_name'] = vol['name'] + if build_id is None: build_id = new_build(build) binfo = get_build(build_id, strict=True) @@ -5043,10 +5056,13 @@ def import_build(srpm, rpms, brmap=None, task_id=None, build_id=None, logs=None) raise koji.GenericError("Unable to complete build: state is %s" \ % koji.BUILD_STATES[binfo['state']]) #update build state - update = """UPDATE build SET state=%(st_complete)i,completion_time=NOW() - WHERE id=%(build_id)i""" - _dml(update, locals()) + update = UpdateProcessor('build', clauses=['id=%(id)s'], values=binfo) + update.set(state=st_complete) + update.rawset(completion_time='NOW()') + update.set(volume_id=build['volume_id']) + update.execute() koji.plugin.run_callbacks('postBuildStateChange', attribute='state', old=binfo['state'], new=st_complete, info=binfo) + # now to handle the individual rpms for relpath in [srpm] + rpms: fn = "%s/%s" % (uploadpath, relpath) diff --git a/tests/test_hub/test_import_build.py b/tests/test_hub/test_import_build.py index 108f911..a0d1e56 100644 --- a/tests/test_hub/test_import_build.py +++ b/tests/test_hub/test_import_build.py @@ -193,6 +193,7 @@ class TestImportBuild(unittest.TestCase): def tearDown(self): shutil.rmtree(self.tempdir) + @mock.patch('kojihub.check_volume_policy') @mock.patch('kojihub.new_typed_build') @mock.patch('kojihub._dml') @mock.patch('kojihub._singleValue') @@ -211,7 +212,7 @@ class TestImportBuild(unittest.TestCase): import_rpm, import_rpm_file, rip_rpm_sighdr, add_rpm_sig, get_build, _singleValue, _dml, - new_typed_build): + new_typed_build, check_volume_policy): rip_rpm_sighdr.return_value = (0, 0) @@ -223,6 +224,8 @@ class TestImportBuild(unittest.TestCase): work.return_value = '/' + check_volume_policy.return_value = {'id':0, 'name': 'DEFAULT'} + retval = copy.copy(self.rpm_header_retval) retval.update({ 'filename': 'name-version-release.arch.rpm',