[koji-wrapper] Add support for spin-livemedia

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ář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2016-01-28 14:56:22 +01:00
parent ae30c07553
commit a5a0f3d69f
2 changed files with 70 additions and 2 deletions

View File

@ -127,6 +127,33 @@ class KojiWrapper(object):
return cmd
def get_live_media_cmd(self, options, wait=True):
# Usage: koji spin-livemedia [options] <name> <version> <target> <arch> <kickstart-file>
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] <name> <version> <target> <arch> <kickstart-file>
# Usage: koji spin-appliance [options] <name> <version> <target> <arch> <kickstart-file>
@ -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)

View File

@ -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()