mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #43103 from aogier/43101-genesis-bootstrap
genesis.bootstrap deboostrap fix
This commit is contained in:
commit
f16b7246e4
2 changed files with 76 additions and 9 deletions
|
@ -24,6 +24,8 @@ import salt.utils.kickstart
|
|||
import salt.syspaths
|
||||
from salt.exceptions import SaltInvocationError
|
||||
|
||||
# Import 3rd-party libs
|
||||
from salt.ext import six
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -325,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:
|
||||
|
@ -333,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)
|
||||
|
@ -393,15 +399,27 @@ def _bootstrap_deb(
|
|||
if repo_url is None:
|
||||
repo_url = 'http://ftp.debian.org/debian/'
|
||||
|
||||
if not salt.utils.which('debootstrap'):
|
||||
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',
|
||||
'--arch',
|
||||
_cmd_quote(arch),
|
||||
'--include',
|
||||
] + pkgs + [
|
||||
'--exclude',
|
||||
] + exclude_pkgs + [
|
||||
_cmd_quote(arch)]
|
||||
|
||||
if pkgs:
|
||||
deb_args += ['--include', _cmd_quote(pkgs)]
|
||||
if exclude_pkgs:
|
||||
deb_args += ['--exclude', _cmd_quote(exclude_pkgs)]
|
||||
|
||||
deb_args += [
|
||||
_cmd_quote(flavor),
|
||||
_cmd_quote(root),
|
||||
_cmd_quote(repo_url),
|
||||
|
@ -469,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:
|
||||
|
@ -477,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)
|
||||
|
|
|
@ -49,12 +49,57 @@ 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': {},
|
||||
'cmd': ['debootstrap', '--foreign', '--arch', 'amd64',
|
||||
'stable', 'root', 'http://ftp.debian.org/debian/']
|
||||
},
|
||||
|
||||
{'params': {'pkgs': 'vim'},
|
||||
'cmd': ['debootstrap', '--foreign', '--arch', 'amd64',
|
||||
'--include', 'vim',
|
||||
'stable', 'root', 'http://ftp.debian.org/debian/']
|
||||
},
|
||||
|
||||
{'params': {'pkgs': 'vim,emacs'},
|
||||
'cmd': ['debootstrap', '--foreign', '--arch', 'amd64',
|
||||
'--include', 'vim,emacs',
|
||||
'stable', 'root', 'http://ftp.debian.org/debian/']
|
||||
},
|
||||
|
||||
{'params': {'pkgs': ['vim', 'emacs']},
|
||||
'cmd': ['debootstrap', '--foreign', '--arch', 'amd64',
|
||||
'--include', 'vim,emacs',
|
||||
'stable', 'root', 'http://ftp.debian.org/debian/']
|
||||
},
|
||||
|
||||
{'params': {'pkgs': ['vim', 'emacs'], 'exclude_pkgs': ['vim', 'foo']},
|
||||
'cmd': ['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()}):
|
||||
with patch.dict(genesis.__salt__, {'disk.blkid': MagicMock(return_value={})}):
|
||||
self.assertEqual(genesis.bootstrap('deb', 'root', 'dir'), None)
|
||||
'file.directory_exists': MagicMock(),
|
||||
'cmd.run': MagicMock(),
|
||||
'disk.blkid': MagicMock(return_value={})}):
|
||||
with patch('salt.modules.genesis.salt.utils.which', return_value=True):
|
||||
param_set['params'].update(common_parms)
|
||||
self.assertEqual(genesis.bootstrap(**param_set['params']), None)
|
||||
genesis.__salt__['cmd.run'].assert_any_call(param_set['cmd'], python_shell=False)
|
||||
|
||||
with patch.object(genesis, '_bootstrap_pacman', return_value='A') as pacman_patch:
|
||||
with patch.dict(genesis.__salt__, {'mount.umount': MagicMock(),
|
||||
|
|
Loading…
Add table
Reference in a new issue