mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Fix interactivity in aptpkg
This commit is contained in:
parent
f23c791a8e
commit
da6d692e4e
@ -20,6 +20,7 @@ import json
|
||||
import yaml
|
||||
|
||||
# Import salt libs
|
||||
from salt.modules.cmdmod import _parse_env
|
||||
import salt.utils
|
||||
from salt._compat import string_types
|
||||
from salt.exceptions import (
|
||||
@ -51,6 +52,12 @@ LP_PVT_SRC_FORMAT = 'deb https://{0}private-ppa.launchpad.net/{1}/{2}/ubuntu' \
|
||||
|
||||
_MODIFY_OK = frozenset(['uri', 'comps', 'architectures', 'disabled',
|
||||
'file', 'dist'])
|
||||
DPKG_ENV_VARS = {
|
||||
'APT_LISTBUGS_FRONTEND': 'none',
|
||||
'APT_LISTCHANGES_FRONTEND': 'none',
|
||||
'DEBIAN_FRONTEND': 'noninteractive',
|
||||
'UCF_FORCE_CONFFOLD': '1',
|
||||
}
|
||||
|
||||
# Define the module's virtual name
|
||||
__virtualname__ = 'pkg'
|
||||
@ -72,14 +79,8 @@ def __init__():
|
||||
non-interactive.
|
||||
'''
|
||||
if __virtual__():
|
||||
env_vars = {
|
||||
'APT_LISTBUGS_FRONTEND': 'none',
|
||||
'APT_LISTCHANGES_FRONTEND': 'none',
|
||||
'DEBIAN_FRONTEND': 'noninteractive',
|
||||
'UCF_FORCE_CONFFOLD': '1',
|
||||
}
|
||||
# Export these puppies so they persist
|
||||
os.environ.update(env_vars)
|
||||
os.environ.update(DPKG_ENV_VARS)
|
||||
|
||||
|
||||
def _get_ppa_info_from_launchpad(owner_name, ppa_name):
|
||||
@ -484,7 +485,9 @@ def install(name=None,
|
||||
if refreshdb:
|
||||
refresh_db()
|
||||
|
||||
__salt__['cmd.run'](cmd, env=kwargs.get('env'), python_shell=False)
|
||||
env = _parse_env(kwargs.get('env'))
|
||||
env.update(copy.deepcopy(DPKG_ENV_VARS))
|
||||
__salt__['cmd.run'](cmd, python_shell=False, env=env)
|
||||
__context__.pop('pkg.list_pkgs', None)
|
||||
new = list_pkgs()
|
||||
return salt.utils.compare_dicts(old, new)
|
||||
@ -618,10 +621,19 @@ def upgrade(refresh=True, dist_upgrade=True):
|
||||
else:
|
||||
cmd = ['apt-get', '-q', '-y', '-o', 'DPkg::Options::=--force-confold',
|
||||
'-o', 'DPkg::Options::=--force-confdef', 'upgrade']
|
||||
__salt__['cmd.run'](cmd, python_shell=False, output_loglevel='trace', env={'DEBIAN_FRONTEND': 'noninteractive'})
|
||||
__context__.pop('pkg.list_pkgs', None)
|
||||
new = list_pkgs()
|
||||
return salt.utils.compare_dicts(old, new)
|
||||
call = __salt__['cmd.run_all'](cmd, python_shell=False, output_loglevel='trace',
|
||||
env=copy.deepcopy(DPKG_ENV_VARS))
|
||||
if call['retcode'] != 0:
|
||||
ret['result'] = False
|
||||
if 'stderr' in call:
|
||||
ret['comment'] += call['stderr']
|
||||
if 'stdout' in call:
|
||||
ret['comment'] += call['stdout']
|
||||
else:
|
||||
__context__.pop('pkg.list_pkgs', None)
|
||||
new = list_pkgs()
|
||||
ret['changes'] = salt.utils.compare_dicts(old, new)
|
||||
return ret
|
||||
|
||||
|
||||
def hold(name=None, pkgs=None, sources=None, **kwargs): # pylint: disable=W0613
|
||||
|
@ -141,6 +141,16 @@ def _check_loglevel(level='info', quiet=False):
|
||||
return LOG_LEVELS[level]
|
||||
|
||||
|
||||
def _parse_env(env):
|
||||
if not env:
|
||||
env = {}
|
||||
if isinstance(env, list):
|
||||
env = salt.utils.repack_dictlist(env)
|
||||
if not isinstance(env, dict):
|
||||
env = {}
|
||||
return env
|
||||
|
||||
|
||||
def _run(cmd,
|
||||
cwd=None,
|
||||
stdin=None,
|
||||
@ -221,10 +231,7 @@ def _run(cmd,
|
||||
|
||||
ret = {}
|
||||
|
||||
if not env:
|
||||
env = {}
|
||||
if isinstance(env, list):
|
||||
env = salt.utils.repack_dictlist(env)
|
||||
env = _parse_env(env)
|
||||
|
||||
for bad_env_key in (x for x, y in env.iteritems() if y is None):
|
||||
log.error('Environment variable {0!r} passed without a value. '
|
||||
|
Loading…
Reference in New Issue
Block a user