allow comma-separated pkgs lists, quote args, test deb behaviour

This commit is contained in:
Alessandro -oggei- Ogier 2017-08-24 12:00:36 +02:00
parent d8612ae006
commit 216ced69e5
2 changed files with 69 additions and 9 deletions

View file

@ -180,13 +180,9 @@ def bootstrap(
if pkgs is None:
pkgs = []
elif isinstance(pkgs, six.string_types):
pkgs = pkgs.split(',')
if exclude_pkgs is None:
exclude_pkgs = []
elif isinstance(exclude_pkgs, six.string_types):
exclude_pkgs = exclude_pkgs.split(',')
if platform in ('rpm', 'yum'):
_bootstrap_yum(
@ -331,6 +327,8 @@ def _bootstrap_yum(
'''
if pkgs is None:
pkgs = []
elif isinstance(pkgs, six.string_types):
pkgs = pkgs.split(',')
default_pkgs = ('yum', 'centos-release', 'iputils')
for pkg in default_pkgs:
@ -339,6 +337,8 @@ def _bootstrap_yum(
if exclude_pkgs is None:
exclude_pkgs = []
elif isinstance(exclude_pkgs, six.string_types):
exclude_pkgs = exclude_pkgs.split(',')
for pkg in exclude_pkgs:
pkgs.remove(pkg)
@ -403,6 +403,11 @@ def _bootstrap_deb(
log.error('Required tool debootstrap is not installed.')
return False
if isinstance(pkgs, (list, tuple)):
pkgs = ','.join(pkgs)
if isinstance(exclude_pkgs, (list, tuple)):
exclude_pkgs = ','.join(exclude_pkgs)
deb_args = [
'debootstrap',
'--foreign',
@ -410,9 +415,9 @@ def _bootstrap_deb(
_cmd_quote(arch)]
if pkgs:
deb_args += ['--include'] + pkgs
deb_args += ['--include', _cmd_quote(pkgs)]
if exclude_pkgs:
deb_args += ['--exclude'] + exclude_pkgs
deb_args += ['--exclude', _cmd_quote(exclude_pkgs)]
deb_args += [
_cmd_quote(flavor),
@ -482,6 +487,8 @@ def _bootstrap_pacman(
if pkgs is None:
pkgs = []
elif isinstance(pkgs, six.string_types):
pkgs = pkgs.split(',')
default_pkgs = ('pacman', 'linux', 'systemd-sysvcompat', 'grub')
for pkg in default_pkgs:
@ -490,6 +497,8 @@ def _bootstrap_pacman(
if exclude_pkgs is None:
exclude_pkgs = []
elif isinstance(exclude_pkgs, six.string_types):
exclude_pkgs = exclude_pkgs.split(',')
for pkg in exclude_pkgs:
pkgs.remove(pkg)

View file

@ -49,12 +49,63 @@ class GenesisTestCase(TestCase):
with patch.dict(genesis.__salt__, {'disk.blkid': MagicMock(return_value={})}):
self.assertEqual(genesis.bootstrap('rpm', 'root', 'dir'), None)
with patch.object(genesis, '_bootstrap_deb', return_value='A'):
common_parms = {'platform': 'deb',
'root': 'root',
'img_format': 'dir',
'arch': 'amd64',
'flavor': 'stable',
'static_qemu': 'qemu'}
param_sets = [
{'params': {},
'commandlines': [
['debootstrap', '--foreign', '--arch', 'amd64',
'stable', 'root', 'http://ftp.debian.org/debian/'],
]},
{'params': {'pkgs': 'vim'},
'commandlines': [
['debootstrap', '--foreign', '--arch', 'amd64',
'--include', 'vim',
'stable', 'root', 'http://ftp.debian.org/debian/'],
]},
{'params': {'pkgs': 'vim,emacs'},
'commandlines': [
['debootstrap', '--foreign', '--arch', 'amd64',
'--include', 'vim,emacs',
'stable', 'root', 'http://ftp.debian.org/debian/'],
]},
{'params': {'pkgs': ['vim', 'emacs']},
'commandlines': [
['debootstrap', '--foreign', '--arch', 'amd64',
'--include', 'vim,emacs',
'stable', 'root', 'http://ftp.debian.org/debian/'],
]},
{'params': {'pkgs': ['vim', 'emacs'], 'exclude_pkgs': ['vim', 'foo']},
'commandlines': [
['debootstrap', '--foreign', '--arch', 'amd64',
'--include', 'vim,emacs', '--exclude', 'vim,foo',
'stable', 'root', 'http://ftp.debian.org/debian/'],
]},
]
for param_set in param_sets:
with patch.dict(genesis.__salt__, {'mount.umount': MagicMock(),
'file.rmdir': MagicMock(),
'file.directory_exists': MagicMock()}):
'file.directory_exists': MagicMock(),
'cmd.run': MagicMock()}):
with patch.dict(genesis.__salt__, {'disk.blkid': MagicMock(return_value={})}):
self.assertEqual(genesis.bootstrap('deb', 'root', 'dir'), None)
param_set['params'].update(common_parms)
self.assertEqual(genesis.bootstrap(**param_set['params']),
None)
for commandline in param_set['commandlines']:
genesis.__salt__['cmd.run'].assert_any_call(commandline, python_shell=False)
with patch.object(genesis, '_bootstrap_pacman', return_value='A') as pacman_patch:
with patch.dict(genesis.__salt__, {'mount.umount': MagicMock(),