Merge #84 Allow specifying --installpkgs for lorax
This commit is contained in:
commit
bdb1bcb35c
6 changed files with 233 additions and 6 deletions
136
tests/test_buildinstall.py
Executable file
136
tests/test_buildinstall.py
Executable file
|
|
@ -0,0 +1,136 @@
|
|||
#!/usr/bin/env python2
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
import unittest
|
||||
import mock
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
||||
|
||||
from pungi.phases.buildinstall import BuildinstallPhase
|
||||
|
||||
|
||||
class _DummyCompose(object):
|
||||
def __init__(self, config):
|
||||
self.conf = config
|
||||
self.paths = mock.Mock(
|
||||
compose=mock.Mock(
|
||||
topdir=mock.Mock(return_value='/a/b')
|
||||
),
|
||||
work=mock.Mock(
|
||||
arch_repo=mock.Mock(return_value='file:///a/b/'),
|
||||
buildinstall_dir=mock.Mock(side_effect=lambda x: '/buildinstall_dir/' + x),
|
||||
)
|
||||
)
|
||||
self._logger = mock.Mock()
|
||||
self.log_debug = mock.Mock()
|
||||
self.supported = True
|
||||
|
||||
def get_arches(self):
|
||||
return ['x86_64', 'amd64']
|
||||
|
||||
def get_variants(self, arch, types):
|
||||
variants = {
|
||||
'x86_64': [mock.Mock(uid='Server', buildinstallpackages=['bash', 'vim'])],
|
||||
'amd64': [mock.Mock(uid='Client', buildinstallpackages=[]),
|
||||
mock.Mock(uid='Server', buildinstallpackages=['bash', 'vim'])],
|
||||
}
|
||||
return variants.get(arch, [])
|
||||
|
||||
|
||||
class TestImageChecksumPhase(unittest.TestCase):
|
||||
|
||||
def test_config_skip_unless_bootable(self):
|
||||
compose = _DummyCompose({})
|
||||
compose.just_phases = None
|
||||
compose.skip_phases = []
|
||||
|
||||
phase = BuildinstallPhase(compose)
|
||||
|
||||
self.assertTrue(phase.skip())
|
||||
|
||||
def test_does_not_skip_on_bootable(self):
|
||||
compose = _DummyCompose({'bootable': True})
|
||||
compose.just_phases = None
|
||||
compose.skip_phases = []
|
||||
|
||||
phase = BuildinstallPhase(compose)
|
||||
|
||||
self.assertFalse(phase.skip())
|
||||
|
||||
@mock.patch('pungi.phases.buildinstall.ThreadPool')
|
||||
@mock.patch('pungi.phases.buildinstall.LoraxWrapper')
|
||||
@mock.patch('pungi.phases.buildinstall.get_volid')
|
||||
def test_starts_threads_for_each_cmd_with_lorax(self, get_volid, loraxCls, poolCls):
|
||||
compose = _DummyCompose({
|
||||
'bootable': True,
|
||||
'release_name': 'Test',
|
||||
'release_short': 't',
|
||||
'release_version': '1',
|
||||
'release_is_layered': False,
|
||||
'buildinstall_method': 'lorax'
|
||||
})
|
||||
|
||||
get_volid.return_value = 'vol_id'
|
||||
|
||||
phase = BuildinstallPhase(compose)
|
||||
|
||||
phase.run()
|
||||
|
||||
# Three items added for processing in total.
|
||||
# Server.x86_64, Client.amd64, Server.x86_64
|
||||
pool = poolCls.return_value
|
||||
self.assertEqual(3, len(pool.queue_put.mock_calls))
|
||||
|
||||
# Obtained correct lorax commands.
|
||||
lorax = loraxCls.return_value
|
||||
lorax.get_lorax_cmd.assert_has_calls(
|
||||
[mock.call('Test', '1', '1', 'file:///a/b/', '/buildinstall_dir/x86_64',
|
||||
buildarch='x86_64', is_final=True, nomacboot=True, noupgrade=True,
|
||||
volid='vol_id', variant='Server', buildinstallpackages=['bash', 'vim']),
|
||||
mock.call('Test', '1', '1', 'file:///a/b/', '/buildinstall_dir/amd64',
|
||||
buildarch='amd64', is_final=True, nomacboot=True, noupgrade=True,
|
||||
volid='vol_id', variant='Server', buildinstallpackages=['bash', 'vim']),
|
||||
mock.call('Test', '1', '1', 'file:///a/b/', '/buildinstall_dir/amd64',
|
||||
buildarch='amd64', is_final=True, nomacboot=True, noupgrade=True,
|
||||
volid='vol_id', variant='Client', buildinstallpackages=[])],
|
||||
any_order=True)
|
||||
|
||||
@mock.patch('pungi.phases.buildinstall.ThreadPool')
|
||||
@mock.patch('pungi.phases.buildinstall.LoraxWrapper')
|
||||
@mock.patch('pungi.phases.buildinstall.get_volid')
|
||||
def test_starts_threads_for_each_cmd_with_buildinstall(self, get_volid, loraxCls, poolCls):
|
||||
compose = _DummyCompose({
|
||||
'bootable': True,
|
||||
'release_name': 'Test',
|
||||
'release_short': 't',
|
||||
'release_version': '1',
|
||||
'release_is_layered': False,
|
||||
'buildinstall_method': 'buildinstall'
|
||||
})
|
||||
|
||||
get_volid.return_value = 'vol_id'
|
||||
|
||||
phase = BuildinstallPhase(compose)
|
||||
|
||||
phase.run()
|
||||
|
||||
# Two items added for processing in total.
|
||||
pool = poolCls.return_value
|
||||
self.assertEqual(2, len(pool.queue_put.mock_calls))
|
||||
|
||||
# Obtained correct lorax commands.
|
||||
lorax = loraxCls.return_value
|
||||
lorax.get_buildinstall_cmd.assert_has_calls(
|
||||
[mock.call('Test', '1', '1', 'file:///a/b/', '/buildinstall_dir/x86_64',
|
||||
buildarch='x86_64', is_final=True, volid='vol_id'),
|
||||
mock.call('Test', '1', '1', 'file:///a/b/', '/buildinstall_dir/amd64',
|
||||
buildarch='amd64', is_final=True, volid='vol_id')],
|
||||
any_order=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
52
tests/test_lorax_wrapper.py
Executable file
52
tests/test_lorax_wrapper.py
Executable file
|
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env python2
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import unittest
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
||||
|
||||
from pungi.wrappers.lorax import LoraxWrapper
|
||||
|
||||
|
||||
class LoraxWrapperTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.lorax = LoraxWrapper()
|
||||
|
||||
def test_get_command_with_minimal_arguments(self):
|
||||
cmd = self.lorax.get_lorax_cmd("product", "version", "release",
|
||||
"/mnt/repo_baseurl", "/mnt/output_dir")
|
||||
|
||||
self.assertEqual(cmd[0], 'lorax')
|
||||
self.assertItemsEqual(cmd[1:],
|
||||
['--product=product',
|
||||
'--version=version',
|
||||
'--release=release',
|
||||
'--source=file:///mnt/repo_baseurl',
|
||||
'/mnt/output_dir'])
|
||||
|
||||
def test_get_command_with_all_arguments(self):
|
||||
cmd = self.lorax.get_lorax_cmd("product", "version", "release",
|
||||
"/mnt/repo_baseurl", "/mnt/output_dir",
|
||||
variant="Server", bugurl="http://example.com/",
|
||||
nomacboot=True, noupgrade=True, is_final=True,
|
||||
buildarch='x86_64', volid='VOLUME_ID',
|
||||
buildinstallpackages=['bash', 'vim'])
|
||||
|
||||
self.assertEqual(cmd[0], 'lorax')
|
||||
self.assertItemsEqual(cmd[1:],
|
||||
['--product=product', '--version=version',
|
||||
'--release=release', '--variant=Server',
|
||||
'--source=file:///mnt/repo_baseurl',
|
||||
'--bugurl=http://example.com/',
|
||||
'--buildarch=x86_64', '--volid=VOLUME_ID',
|
||||
'--nomacboot', '--noupgrade', '--isfinal',
|
||||
'--installpkgs=bash', '--installpkgs=vim',
|
||||
'/mnt/output_dir'])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue