[koji-wrapper] Add tests for runroot wrapper
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
f57665f963
commit
8e5e893e5c
@ -53,14 +53,12 @@ class KojiWrapper(object):
|
|||||||
if weight:
|
if weight:
|
||||||
cmd.append("--weight=%s" % int(weight))
|
cmd.append("--weight=%s" % int(weight))
|
||||||
|
|
||||||
if packages:
|
for package in packages or []:
|
||||||
for package in packages:
|
cmd.append("--package=%s" % package)
|
||||||
cmd.append("--package=%s" % package)
|
|
||||||
|
|
||||||
if mounts:
|
for mount in mounts or []:
|
||||||
for mount in mounts:
|
# directories are *not* created here
|
||||||
# directories are *not* created here
|
cmd.append("--mount=%s" % mount)
|
||||||
cmd.append("--mount=%s" % mount)
|
|
||||||
|
|
||||||
# IMPORTANT: all --opts have to be provided *before* args
|
# IMPORTANT: all --opts have to be provided *before* args
|
||||||
|
|
||||||
@ -91,12 +89,11 @@ class KojiWrapper(object):
|
|||||||
if output_ends_with_eol:
|
if output_ends_with_eol:
|
||||||
output += "\n"
|
output += "\n"
|
||||||
|
|
||||||
result = {
|
return {
|
||||||
"retcode": retcode,
|
"retcode": retcode,
|
||||||
"output": output,
|
"output": output,
|
||||||
"task_id": task_id,
|
"task_id": task_id,
|
||||||
}
|
}
|
||||||
return result
|
|
||||||
|
|
||||||
def get_image_build_cmd(self, config_options, conf_file_dest, wait=True, scratch=False):
|
def get_image_build_cmd(self, config_options, conf_file_dest, wait=True, scratch=False):
|
||||||
"""
|
"""
|
||||||
|
@ -294,5 +294,70 @@ class LiveMediaTestCase(unittest.TestCase):
|
|||||||
['--repo=repo-1', '--repo=repo-2', '--skip-tag', '--scratch', '--wait'])
|
['--repo=repo-1', '--repo=repo-2', '--skip-tag', '--scratch', '--wait'])
|
||||||
|
|
||||||
|
|
||||||
|
class RunrootKojiWrapperTest(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_cmd_minimal(self):
|
||||||
|
cmd = self.koji.get_runroot_cmd('tgt', 's390x', 'date', use_shell=False, task_id=False)
|
||||||
|
self.assertEqual(len(cmd), 6)
|
||||||
|
self.assertEqual(cmd[0], 'koji')
|
||||||
|
self.assertEqual(cmd[1], 'runroot')
|
||||||
|
self.assertEqual(cmd[-3], 'tgt')
|
||||||
|
self.assertEqual(cmd[-2], 's390x')
|
||||||
|
self.assertEqual(cmd[-1], 'rm -f /var/lib/rpm/__db*; rm -rf /var/cache/yum/*; set -x; date')
|
||||||
|
self.assertItemsEqual(cmd[2:-3],
|
||||||
|
['--channel-override=runroot-local'])
|
||||||
|
|
||||||
|
def test_get_cmd_full(self):
|
||||||
|
cmd = self.koji.get_runroot_cmd('tgt', 's390x', ['/bin/echo', '&'],
|
||||||
|
quiet=True, channel='chan',
|
||||||
|
packages=['strace', 'lorax'],
|
||||||
|
mounts=['/tmp'], weight=1000)
|
||||||
|
self.assertEqual(len(cmd), 13)
|
||||||
|
self.assertEqual(cmd[0], 'koji')
|
||||||
|
self.assertEqual(cmd[1], 'runroot')
|
||||||
|
self.assertEqual(cmd[-3], 'tgt')
|
||||||
|
self.assertEqual(cmd[-2], 's390x')
|
||||||
|
self.assertEqual(cmd[-1], 'rm -f /var/lib/rpm/__db*; rm -rf /var/cache/yum/*; set -x; /bin/echo \'&\'')
|
||||||
|
self.assertItemsEqual(cmd[2:-3],
|
||||||
|
['--channel-override=chan', '--quiet', '--use-shell',
|
||||||
|
'--task-id', '--weight=1000', '--package=strace',
|
||||||
|
'--package=lorax', '--mount=/tmp'])
|
||||||
|
|
||||||
|
@mock.patch('pungi.wrappers.kojiwrapper.run')
|
||||||
|
def test_run_runroot_cmd_no_task_id(self, run):
|
||||||
|
cmd = ['koji', 'runroot']
|
||||||
|
output = 'Output ...'
|
||||||
|
run.return_value = (0, output)
|
||||||
|
|
||||||
|
result = self.koji.run_runroot_cmd(cmd)
|
||||||
|
self.assertDictEqual(result,
|
||||||
|
{'retcode': 0, 'output': output, 'task_id': None})
|
||||||
|
|
||||||
|
@mock.patch('pungi.wrappers.kojiwrapper.run')
|
||||||
|
def test_run_runroot_cmd_with_task_id(self, run):
|
||||||
|
cmd = ['koji', 'runroot', '--task-id']
|
||||||
|
output = 'Output ...\n'
|
||||||
|
run.return_value = (0, '1234\n' + output)
|
||||||
|
|
||||||
|
result = self.koji.run_runroot_cmd(cmd)
|
||||||
|
self.assertDictEqual(result,
|
||||||
|
{'retcode': 0, 'output': output, 'task_id': 1234})
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user