lxc: chroot fallback toggle

This commit is contained in:
Mathieu Le Marec - Pasquet 2015-05-18 14:51:52 +02:00
parent e2887a0d44
commit e8d674fed4

View file

@ -1412,6 +1412,7 @@ def init(name,
'/.lxc.{0}.initial_pass'.format(name)]
if not any(retcode(name,
'test -e "{0}"'.format(x),
chroot_fallback=True,
ignore_retcode=True) == 0
for x in gids):
# think to touch the default user generated by default templates
@ -1419,11 +1420,12 @@ def init(name,
# root is defined as a member earlier in the code
for default_user in ['ubuntu']:
if (
default_user not in users
and retcode(name,
'id {0}'.format(default_user),
python_shell=False,
ignore_retcode=True) == 0
default_user not in users and
retcode(name,
'id {0}'.format(default_user),
python_shell=False,
chroot_fallback=True,
ignore_retcode=True) == 0
):
users.append(default_user)
for user in users:
@ -1447,6 +1449,7 @@ def init(name,
if retcode(name,
('sh -c \'touch "{0}"; test -e "{0}"\''
.format(gid)),
chroot_fallback=True,
ignore_retcode=True) != 0:
ret['comment'] = 'Failed to set password marker'
changes[-1]['password'] += '. ' + ret['comment'] + '.'
@ -1461,6 +1464,7 @@ def init(name,
'/lxc.{0}.initial_dns'.format(name)]
if not any(retcode(name,
'test -e "{0}"'.format(x),
chroot_fallback=True,
ignore_retcode=True) == 0
for x in gids):
try:
@ -1475,6 +1479,7 @@ def init(name,
if retcode(name,
('sh -c \'touch "{0}"; test -e "{0}"\''
.format(gid)),
chroot_fallback=True,
ignore_retcode=True) != 0:
ret['comment'] = 'Failed to set DNS marker'
changes[-1]['dns'] += '. ' + ret['comment'] + '.'
@ -1486,9 +1491,9 @@ def init(name,
if (
any(retcode(name,
'test -e {0}'.format(x),
chroot_fallback=True,
ignore_retcode=True) == 0
for x in gids)
or not ret.get('result', True)
for x in gids) or not ret.get('result', True)
):
pass
elif seed or seed_cmd:
@ -2578,6 +2583,7 @@ def set_password(name, users, password, encrypted=True):
'chpasswd{0}'.format(' -e' if encrypted else ''),
stdin=':'.join((user, password)),
python_shell=False,
chroot_fallback=True,
output_loglevel='quiet')
if result != 0:
failed_users.append(user)
@ -2893,6 +2899,7 @@ def bootstrap(name,
needs_install = True
seeded = retcode(name,
'test -e \'{0}\''.format(SEED_MARKER),
chroot_fallback=True,
ignore_retcode=True) == 0
tmp = tempfile.mkdtemp()
if seeded and not unconditional_install:
@ -3003,6 +3010,7 @@ def _run(name,
output_loglevel='debug',
use_vt=False,
ignore_retcode=False,
chroot_fallback=None,
keep_env='http_proxy,https_proxy,no_proxy'):
'''
Common logic for lxc.run functions
@ -3038,6 +3046,9 @@ def _run(name,
ignore_retcode=ignore_retcode,
use_vt=use_vt)
else:
if not chroot_fallback:
raise CommandExecutionError(
'{0} is not attachable.'.format(name))
rootfs = info(name).get('rootfs')
# Set context var to make cmd.run_chroot run cmd.run instead of
# cmd.run_all.
@ -3076,6 +3087,7 @@ def run_cmd(name,
output_loglevel='debug',
use_vt=False,
ignore_retcode=False,
chroot_fallback=False,
keep_env='http_proxy,https_proxy,no_proxy'):
'''
.. deprecated:: 2015.5.0
@ -3117,6 +3129,7 @@ def run(name,
output_loglevel='debug',
use_vt=False,
ignore_retcode=False,
chroot_fallback=False,
keep_env='http_proxy,https_proxy,no_proxy'):
'''
.. versionadded:: 2015.5.0
@ -3160,6 +3173,10 @@ def run(name,
Use SaltStack's utils.vt to stream output to console. Assumes
``output=all``.
chroot_fallback
if the container is not running, try to run the command using chroot
default: false
keep_env : http_proxy,https_proxy,no_proxy
A list of env vars to preserve. May be passed as commma-delimited list.
@ -3180,6 +3197,7 @@ def run(name,
output_loglevel=output_loglevel,
use_vt=use_vt,
ignore_retcode=ignore_retcode,
chroot_fallback=chroot_fallback,
keep_env=keep_env)
@ -3192,6 +3210,7 @@ def run_stdout(name,
output_loglevel='debug',
use_vt=False,
ignore_retcode=False,
chroot_fallback=False,
keep_env='http_proxy,https_proxy,no_proxy'):
'''
.. versionadded:: 2015.5.0
@ -3238,6 +3257,10 @@ def run_stdout(name,
keep_env : http_proxy,https_proxy,no_proxy
A list of env vars to preserve. May be passed as commma-delimited list.
chroot_fallback
if the container is not running, try to run the command using chroot
default: false
CLI Example:
@ -3255,6 +3278,7 @@ def run_stdout(name,
output_loglevel=output_loglevel,
use_vt=use_vt,
ignore_retcode=ignore_retcode,
chroot_fallback=chroot_fallback,
keep_env=keep_env)
@ -3267,6 +3291,7 @@ def run_stderr(name,
output_loglevel='debug',
use_vt=False,
ignore_retcode=False,
chroot_fallback=False,
keep_env='http_proxy,https_proxy,no_proxy'):
'''
.. versionadded:: 2015.5.0
@ -3311,6 +3336,10 @@ def run_stderr(name,
keep_env : http_proxy,https_proxy,no_proxy
A list of env vars to preserve. May be passed as commma-delimited list.
chroot_fallback
if the container is not running, try to run the command using chroot
default: false
CLI Example:
@ -3328,6 +3357,7 @@ def run_stderr(name,
output_loglevel=output_loglevel,
use_vt=use_vt,
ignore_retcode=ignore_retcode,
chroot_fallback=chroot_fallback,
keep_env=keep_env)
@ -3340,6 +3370,7 @@ def retcode(name,
output_loglevel='debug',
use_vt=False,
ignore_retcode=False,
chroot_fallback=False,
keep_env='http_proxy,https_proxy,no_proxy'):
'''
.. versionadded:: 2015.5.0
@ -3386,6 +3417,10 @@ def retcode(name,
keep_env : http_proxy,https_proxy,no_proxy
A list of env vars to preserve. May be passed as commma-delimited list.
chroot_fallback
if the container is not running, try to run the command using chroot
default: false
CLI Example:
@ -3403,6 +3438,7 @@ def retcode(name,
output_loglevel=output_loglevel,
use_vt=use_vt,
ignore_retcode=ignore_retcode,
chroot_fallback=chroot_fallback,
keep_env=keep_env)
@ -3415,6 +3451,7 @@ def run_all(name,
output_loglevel='debug',
use_vt=False,
ignore_retcode=False,
chroot_fallback=False,
keep_env='http_proxy,https_proxy,no_proxy'):
'''
.. versionadded:: 2015.5.0
@ -3459,6 +3496,10 @@ def run_all(name,
keep_env : http_proxy,https_proxy,no_proxy
A list of env vars to preserve. May be passed as commma-delimited list.
chroot_fallback
if the container is not running, try to run the command using chroot
default: false
CLI Example:
@ -3476,6 +3517,7 @@ def run_all(name,
output_loglevel=output_loglevel,
use_vt=use_vt,
ignore_retcode=ignore_retcode,
chroot_fallback=chroot_fallback,
keep_env=keep_env)
@ -3483,7 +3525,9 @@ def _get_md5(name, path):
'''
Get the MD5 checksum of a file from a container
'''
output = run_stdout(name, 'md5sum "{0}"'.format(path), ignore_retcode=True)
output = run_stdout(name, 'md5sum "{0}"'.format(path),
chroot_fallback=True,
ignore_retcode=True)
try:
return output.split()[0]
except IndexError: