From a5a0f3d69fcc7230fb688dfc6d1f77b1575639a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Thu, 28 Jan 2016 14:56:22 +0100 Subject: [PATCH] [koji-wrapper] Add support for spin-livemedia MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds support for live media creator in Koji. The intended workflow is to create a command , run it and finally collect built artifacts. get_live_media_cmd() run_blocking_cmd() get_image_paths() Signed-off-by: Lubomír Sedlář --- pungi/wrappers/kojiwrapper.py | 32 ++++++++++++++++++++++++++-- tests/test_koji_wrapper.py | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/pungi/wrappers/kojiwrapper.py b/pungi/wrappers/kojiwrapper.py index 5b5076b8..b5b7afba 100644 --- a/pungi/wrappers/kojiwrapper.py +++ b/pungi/wrappers/kojiwrapper.py @@ -127,6 +127,33 @@ class KojiWrapper(object): return cmd + def get_live_media_cmd(self, options, wait=True): + # Usage: koji spin-livemedia [options] + cmd = ['koji', 'spin-livemedia'] + + for key in ('name', 'version', 'target', 'arch', 'ksfile'): + if key not in options: + raise ValueError('Expected options to have key "%s"' % key) + cmd.append(pipes.quote(options[key])) + + if 'install_tree' not in options: + raise ValueError('Expected options to have key "install_tree"') + cmd.append('--install-tree=%s' % pipes.quote(options['install_tree'])) + + for repo in options.get('repo', []): + cmd.append('--repo=%s' % pipes.quote(repo)) + + if options.get('scratch'): + cmd.append('--scratch') + + if options.get('skip_tag'): + cmd.append('--skip-tag') + + if wait: + cmd.append('--wait') + + return cmd + def get_create_image_cmd(self, name, version, target, arch, ks_file, repos, image_type="live", image_format=None, release=None, wait=True, archive=False, specfile=None): # Usage: koji spin-livecd [options] # Usage: koji spin-appliance [options] @@ -204,7 +231,8 @@ class KojiWrapper(object): match = re.search(r"Created task: (\d+)", output) if not match: - raise RuntimeError("Could not find task ID in output. Command '%s' returned '%s'." % (" ".join(command), output)) + raise RuntimeError("Could not find task ID in output. Command '%s' returned '%s'." + % (" ".join(command), output)) result = { "retcode": retcode, @@ -224,7 +252,7 @@ class KojiWrapper(object): children_tasks = self.koji_proxy.getTaskChildren(task_id, request=True) for child_task in children_tasks: - if child_task['method'] != 'createImage': + if child_task['method'] not in ['createImage', 'createLiveMedia']: continue is_scratch = child_task['request'][-1].get('scratch', False) diff --git a/tests/test_koji_wrapper.py b/tests/test_koji_wrapper.py index f90dcc7d..a75a5eda 100755 --- a/tests/test_koji_wrapper.py +++ b/tests/test_koji_wrapper.py @@ -254,5 +254,45 @@ class KojiWrapperTest(unittest.TestCase): '/koji/task/12387277/Fedora-Cloud-Base-23-20160103.x86_64.raw.xz']) +class LiveMediaTestCase(unittest.TestCase): + def setUp(self): + self.koji_profile = mock.Mock() + with mock.patch('pungi.wrappers.kojiwrapper.koji') as koji: + koji.get_profile_module = mock.Mock( + return_value=mock.Mock( + pathinfo=mock.Mock( + work=mock.Mock(return_value='/koji'), + taskrelpath=mock.Mock(side_effect=lambda id: 'task/' + str(id)), + imagebuild=mock.Mock(side_effect=lambda id: '/koji/imagebuild/' + str(id)), + ) + ) + ) + self.koji_profile = koji.get_profile_module.return_value + self.koji = KojiWrapper('koji') + + def test_get_live_media_cmd_minimal(self): + opts = { + 'name': 'name', 'version': '1', 'target': 'tgt', 'arch': 'x,y,z', + 'ksfile': 'kickstart', 'install_tree': '/mnt/os' + } + cmd = self.koji.get_live_media_cmd(opts) + self.assertEqual(cmd, + ['koji', 'spin-livemedia', 'name', '1', 'tgt', 'x,y,z', 'kickstart', + '--install-tree=/mnt/os', '--wait']) + + def test_get_live_media_cmd_full(self): + opts = { + 'name': 'name', 'version': '1', 'target': 'tgt', 'arch': 'x,y,z', + 'ksfile': 'kickstart', 'install_tree': '/mnt/os', 'scratch': True, + 'repo': ['repo-1', 'repo-2'], 'skip_tag': True, + } + cmd = self.koji.get_live_media_cmd(opts) + self.assertEqual(cmd[:8], + ['koji', 'spin-livemedia', 'name', '1', 'tgt', 'x,y,z', 'kickstart', + '--install-tree=/mnt/os']) + self.assertItemsEqual(cmd[8:], + ['--repo=repo-1', '--repo=repo-2', '--skip-tag', '--scratch', '--wait']) + + if __name__ == "__main__": unittest.main()