Skip to content

Commit c20de1e

Browse files
committed
Merge pull request saltstack#16361 from rallytime/bp-15584
Backport saltstack#15584 to 2014.7
2 parents 8836651 + 167a75e commit c20de1e

File tree

2 files changed

+40
-16
lines changed

2 files changed

+40
-16
lines changed

salt/modules/aptpkg.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import yaml
2121

2222
# Import salt libs
23+
from salt.modules.cmdmod import _parse_env
2324
import salt.utils
2425
from salt._compat import string_types
2526
from salt.exceptions import (
@@ -51,6 +52,12 @@
5152

5253
_MODIFY_OK = frozenset(['uri', 'comps', 'architectures', 'disabled',
5354
'file', 'dist'])
55+
DPKG_ENV_VARS = {
56+
'APT_LISTBUGS_FRONTEND': 'none',
57+
'APT_LISTCHANGES_FRONTEND': 'none',
58+
'DEBIAN_FRONTEND': 'noninteractive',
59+
'UCF_FORCE_CONFFOLD': '1',
60+
}
5461

5562
# Define the module's virtual name
5663
__virtualname__ = 'pkg'
@@ -72,14 +79,8 @@ def __init__():
7279
non-interactive.
7380
'''
7481
if __virtual__():
75-
env_vars = {
76-
'APT_LISTBUGS_FRONTEND': 'none',
77-
'APT_LISTCHANGES_FRONTEND': 'none',
78-
'DEBIAN_FRONTEND': 'noninteractive',
79-
'UCF_FORCE_CONFFOLD': '1',
80-
}
8182
# Export these puppies so they persist
82-
os.environ.update(env_vars)
83+
os.environ.update(DPKG_ENV_VARS)
8384

8485

8586
def _get_ppa_info_from_launchpad(owner_name, ppa_name):
@@ -484,7 +485,9 @@ def install(name=None,
484485
if refreshdb:
485486
refresh_db()
486487

487-
__salt__['cmd.run'](cmd, env=kwargs.get('env'), python_shell=False)
488+
env = _parse_env(kwargs.get('env'))
489+
env.update(DPKG_ENV_VARS.copy())
490+
__salt__['cmd.run'](cmd, python_shell=False, env=env)
488491
__context__.pop('pkg.list_pkgs', None)
489492
new = list_pkgs()
490493
return salt.utils.compare_dicts(old, new)
@@ -608,6 +611,11 @@ def upgrade(refresh=True, dist_upgrade=True):
608611
609612
salt '*' pkg.upgrade
610613
'''
614+
ret = {'changes': {},
615+
'result': True,
616+
'comment': '',
617+
}
618+
611619
if salt.utils.is_true(refresh):
612620
refresh_db()
613621

@@ -618,10 +626,19 @@ def upgrade(refresh=True, dist_upgrade=True):
618626
else:
619627
cmd = ['apt-get', '-q', '-y', '-o', 'DPkg::Options::=--force-confold',
620628
'-o', 'DPkg::Options::=--force-confdef', 'upgrade']
621-
__salt__['cmd.run'](cmd, python_shell=False, output_loglevel='trace', env={'DEBIAN_FRONTEND': 'noninteractive'})
622-
__context__.pop('pkg.list_pkgs', None)
623-
new = list_pkgs()
624-
return salt.utils.compare_dicts(old, new)
629+
call = __salt__['cmd.run_all'](cmd, python_shell=False, output_loglevel='trace',
630+
env=DPKG_ENV_VARS.copy())
631+
if call['retcode'] != 0:
632+
ret['result'] = False
633+
if 'stderr' in call:
634+
ret['comment'] += call['stderr']
635+
if 'stdout' in call:
636+
ret['comment'] += call['stdout']
637+
else:
638+
__context__.pop('pkg.list_pkgs', None)
639+
new = list_pkgs()
640+
ret['changes'] = salt.utils.compare_dicts(old, new)
641+
return ret
625642

626643

627644
def hold(name=None, pkgs=None, sources=None, **kwargs): # pylint: disable=W0613

salt/modules/cmdmod.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ def _bad_level(level):
141141
return LOG_LEVELS[level]
142142

143143

144+
def _parse_env(env):
145+
if not env:
146+
env = {}
147+
if isinstance(env, list):
148+
env = salt.utils.repack_dictlist(env)
149+
if not isinstance(env, dict):
150+
env = {}
151+
return env
152+
153+
144154
def _run(cmd,
145155
cwd=None,
146156
stdin=None,
@@ -221,10 +231,7 @@ def _run(cmd,
221231

222232
ret = {}
223233

224-
if not env:
225-
env = {}
226-
if isinstance(env, list):
227-
env = salt.utils.repack_dictlist(env)
234+
env = _parse_env(env)
228235

229236
for bad_env_key in (x for x, y in env.iteritems() if y is None):
230237
log.error('Environment variable {0!r} passed without a value. '

0 commit comments

Comments
 (0)