From af816fe68da116e325d3b024f8fb402c49e60199 Mon Sep 17 00:00:00 2001 From: geargyri Date: Mar 03 2022 10:39:32 +0000 Subject: Feature: Build non-scratch from locally stored kickstart. cli and hub code modified to support non-scratch builds from locally stored kickstart files. tests: Testing this feature is added. --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 354cd1a..a94de4c 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -6421,9 +6421,6 @@ def _build_image_oz(options, task_opts, session, args): # Upload the KS file to the staging area. # If it's a URL, it's kojid's job to go get it when it does the checkout. if not task_opts.ksurl: - if not task_opts.scratch: - # only scratch builds can omit ksurl - raise koji.GenericError("Non-scratch builds must provide ksurl") ksfile = task_opts.kickstart serverdir = unique_path('cli-image') session.uploadWrapper(ksfile, serverdir, callback=callback) diff --git a/hub/kojihub.py b/hub/kojihub.py index 81cdbc6..9dbbead 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -10713,8 +10713,6 @@ class RootExports(object): 'only admins may create high-priority tasks') taskOpts['priority'] = koji.PRIO_DEFAULT + priority - if 'scratch' not in opts and 'ksurl' not in opts: - raise koji.ActionNotAllowed('Non-scratch builds must provide ksurl') return make_task('image', [name, version, arches, target, inst_tree, opts], **taskOpts) diff --git a/tests/test_cli/test_image_build.py b/tests/test_cli/test_image_build.py index 313e679..554e73f 100644 --- a/tests/test_cli/test_image_build.py +++ b/tests/test_cli/test_image_build.py @@ -187,6 +187,36 @@ class TestBuildImageOz(utils.CliTestCase): '/path/to/cli-image', callback=None) + def test_build_image_oz_local_ks(self): + task_id = 107 + # self.task_options.kickstart will be + # changed in _build_image_oz() + ksfile = self.task_options.kickstart + self.task_options.ksurl = None + self.task_options.scratch = False + + self.session.getBuildTarget.return_value = self.target_info + self.session.getTag.return_value = self.tag_info + self.session.buildImageOz.return_value = task_id + + self.task_options.background = True + self.running_in_bg.return_value = True + with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout: + _build_image_oz( + self.options, self.task_options, self.session, self.args) + expected = '' + '\n' + expected += "Created task: %d" % task_id + "\n" + expected += "Task info: %s/taskinfo?taskID=%s" % \ + (self.options.weburl, task_id) + "\n" + self.assert_console_message(stdout, expected) + self.watch_tasks.assert_not_called() + self.session.buildImageOz.assert_called_once() + self.unique_path.assert_called_with('cli-image') + self.session.uploadWrapper.assert_called_with( + ksfile, + '/path/to/cli-image', + callback=None) + def test_build_image_oz_exception(self): self.session.getBuildTarget.return_value = {} with self.assertRaises(koji.GenericError) as cm: @@ -204,16 +234,6 @@ class TestBuildImageOz(utils.CliTestCase): str(cm.exception), 'No such destination tag: %s' % self.target_info['dest_tag_name']) - self.session.getTag.return_value = self.tag_info - with self.assertRaises(koji.GenericError) as cm: - self.task_options.ksurl = None - self.task_options.scratch = False - _build_image_oz( - self.options, self.task_options, self.session, self.args) - self.assertEqual( - str(cm.exception), - 'Non-scratch builds must provide ksurl') - class TestImageBuild(utils.CliTestCase):