mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #33880 from terminalmage/zh744
pkg.uptodate: Pass kwargs to pkg.list_upgrades
This commit is contained in:
commit
6b98e8a9ea
10 changed files with 86 additions and 67 deletions
|
@ -1044,7 +1044,7 @@ def list_pkgs(versions_as_list=False,
|
|||
return ret
|
||||
|
||||
|
||||
def _get_upgradable():
|
||||
def _get_upgradable(**kwargs):
|
||||
'''
|
||||
Utility function to get upgradable packages
|
||||
|
||||
|
@ -1052,18 +1052,22 @@ def _get_upgradable():
|
|||
{ 'pkgname': '1.2.3-45', ... }
|
||||
'''
|
||||
|
||||
cmd = 'apt-get --just-print dist-upgrade'
|
||||
call = __salt__['cmd.run_all'](cmd, output_loglevel='trace')
|
||||
cmd = ['apt-get', '--just-print', 'dist-upgrade']
|
||||
fromrepo = _get_repo(**kwargs)
|
||||
if fromrepo:
|
||||
cmd.extend(['-o', 'APT::Default-Release={0}'.format(fromrepo)])
|
||||
|
||||
call = __salt__['cmd.run_all'](cmd,
|
||||
python_shell=False,
|
||||
output_loglevel='trace')
|
||||
|
||||
if call['retcode'] != 0:
|
||||
comment = ''
|
||||
if 'stderr' in call:
|
||||
comment += call['stderr']
|
||||
if 'stdout' in call:
|
||||
comment += call['stdout']
|
||||
raise CommandExecutionError(
|
||||
'{0}'.format(comment)
|
||||
)
|
||||
msg = 'Failed to get upgrades'
|
||||
for key in ('stderr', 'stdout'):
|
||||
if call[key]:
|
||||
msg += ': ' + call[key]
|
||||
break
|
||||
raise CommandExecutionError(msg)
|
||||
else:
|
||||
out = call['stdout']
|
||||
|
||||
|
@ -1086,7 +1090,7 @@ def _get_upgradable():
|
|||
return ret
|
||||
|
||||
|
||||
def list_upgrades(refresh=True):
|
||||
def list_upgrades(refresh=True, **kwargs):
|
||||
'''
|
||||
List all available package upgrades.
|
||||
|
||||
|
@ -1098,7 +1102,7 @@ def list_upgrades(refresh=True):
|
|||
'''
|
||||
if salt.utils.is_true(refresh):
|
||||
refresh_db()
|
||||
return _get_upgradable()
|
||||
return _get_upgradable(**kwargs)
|
||||
|
||||
|
||||
def upgrade_available(name):
|
||||
|
|
|
@ -332,7 +332,7 @@ def install(name=None, pkgs=None, taps=None, options=None, **kwargs):
|
|||
return salt.utils.compare_dicts(old, new)
|
||||
|
||||
|
||||
def list_upgrades(refresh=True):
|
||||
def list_upgrades(refresh=True, **kwargs): # pylint: disable=W0613
|
||||
'''
|
||||
Check whether or not an upgrade is available for all packages
|
||||
|
||||
|
@ -348,14 +348,12 @@ def list_upgrades(refresh=True):
|
|||
cmd = 'brew outdated'
|
||||
call = _call_brew(cmd)
|
||||
if call['retcode'] != 0:
|
||||
comment = ''
|
||||
if 'stderr' in call:
|
||||
comment += call['stderr']
|
||||
if 'stdout' in call:
|
||||
comment += call['stdout']
|
||||
raise CommandExecutionError(
|
||||
'{0}'.format(comment)
|
||||
)
|
||||
msg = 'Failed to get upgrades'
|
||||
for key in ('stderr', 'stdout'):
|
||||
if call[key]:
|
||||
msg += ': ' + call[key]
|
||||
break
|
||||
raise CommandExecutionError(msg)
|
||||
else:
|
||||
out = call['stdout']
|
||||
return out.splitlines()
|
||||
|
|
|
@ -266,14 +266,12 @@ def _get_upgradable():
|
|||
call = __salt__['cmd.run_all'](cmd, output_loglevel='trace')
|
||||
|
||||
if call['retcode'] != 0:
|
||||
comment = ''
|
||||
if 'stderr' in call:
|
||||
comment += call['stderr']
|
||||
if 'stdout' in call:
|
||||
comment += call['stdout']
|
||||
raise CommandExecutionError(
|
||||
'{0}'.format(comment)
|
||||
)
|
||||
msg = 'Failed to get upgrades'
|
||||
for key in ('stderr', 'stdout'):
|
||||
if call[key]:
|
||||
msg += ': ' + call[key]
|
||||
break
|
||||
raise CommandExecutionError(msg)
|
||||
else:
|
||||
out = call['stdout']
|
||||
|
||||
|
@ -296,7 +294,7 @@ def _get_upgradable():
|
|||
return ret
|
||||
|
||||
|
||||
def list_upgrades(refresh=True):
|
||||
def list_upgrades(refresh=True, **kwargs): # pylint: disable=W0613
|
||||
'''
|
||||
List all available package upgrades.
|
||||
|
||||
|
|
|
@ -329,7 +329,7 @@ def install(name=None, refresh=False, pkgs=None, **kwargs):
|
|||
return salt.utils.compare_dicts(old, new)
|
||||
|
||||
|
||||
def list_upgrades(refresh=True):
|
||||
def list_upgrades(refresh=True, **kwargs): # pylint: disable=W0613
|
||||
'''
|
||||
Check whether or not an upgrade is available for all packages
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ def upgrade_available(name):
|
|||
return latest_version(name) != ''
|
||||
|
||||
|
||||
def list_upgrades(refresh=False):
|
||||
def list_upgrades(refresh=False, **kwargs): # pylint: disable=W0613
|
||||
'''
|
||||
List all available package upgrades on this system
|
||||
|
||||
|
@ -127,14 +127,14 @@ def list_upgrades(refresh=False):
|
|||
salt '*' pkg.list_upgrades
|
||||
'''
|
||||
upgrades = {}
|
||||
options = ['-S', '-p', '-u', '--print-format "%n %v"']
|
||||
cmd = ['pacman', '-S', '-p', '-u', '--print-format', '%n %v']
|
||||
|
||||
if refresh:
|
||||
options.append('-y')
|
||||
cmd.append('-y')
|
||||
|
||||
cmd = ('pacman {0}').format(' '.join(options))
|
||||
|
||||
call = __salt__['cmd.run_all'](cmd, output_loglevel='trace')
|
||||
call = __salt__['cmd.run_all'](cmd,
|
||||
python_shell=False,
|
||||
output_loglevel='trace')
|
||||
|
||||
if call['retcode'] != 0:
|
||||
comment = ''
|
||||
|
@ -148,7 +148,7 @@ def list_upgrades(refresh=False):
|
|||
else:
|
||||
out = call['stdout']
|
||||
|
||||
for line in iter(out.splitlines()):
|
||||
for line in out.splitlines():
|
||||
comps = line.split(' ')
|
||||
if len(comps) != 2:
|
||||
continue
|
||||
|
|
|
@ -65,7 +65,7 @@ def upgrade_available(name):
|
|||
return ''
|
||||
|
||||
|
||||
def list_upgrades(refresh=True):
|
||||
def list_upgrades(refresh=True, **kwargs): # pylint: disable=W0613
|
||||
'''
|
||||
List all available package upgrades on this system
|
||||
|
||||
|
|
|
@ -122,12 +122,19 @@ def upgrade_available(name):
|
|||
return ret
|
||||
|
||||
|
||||
def list_upgrades(refresh=False):
|
||||
def list_upgrades(refresh=False, **kwargs): # pylint: disable=W0613
|
||||
'''
|
||||
Lists all packages available for update.
|
||||
When run in global zone, it reports only upgradable packages for the global zone.
|
||||
When run in non-global zone, it can report more upgradable packages than "pkg update -vn" because "pkg update" hides packages that require newer version of pkg://solaris/entire (which means that they can be upgraded only from global zone). Simply said: if you see pkg://solaris/entire in the list of upgrades, you should upgrade the global zone to get all possible updates.
|
||||
You can force full pkg DB refresh before listing.
|
||||
|
||||
When run in global zone, it reports only upgradable packages for the global
|
||||
zone.
|
||||
|
||||
When run in non-global zone, it can report more upgradable packages than
|
||||
``pkg update -vn``, because ``pkg update`` hides packages that require
|
||||
newer version of ``pkg://solaris/entire`` (which means that they can be
|
||||
upgraded only from the global zone). If ``pkg://solaris/entire`` is found
|
||||
in the list of upgrades, then the global zone should be updated to get all
|
||||
possible updates. Use ``refresh=True`` to refresh the package database.
|
||||
|
||||
CLI Example::
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ def upgrade_available(name):
|
|||
return latest_version(name) != ''
|
||||
|
||||
|
||||
def list_upgrades(refresh=True):
|
||||
def list_upgrades(refresh=True, **kwargs): # pylint: disable=W0613
|
||||
'''
|
||||
List all available package upgrades on this system
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ def __virtual__():
|
|||
return __virtualname__
|
||||
|
||||
|
||||
def list_upgrades(refresh=True):
|
||||
def list_upgrades(refresh=True, **kwargs):
|
||||
'''
|
||||
List all available package upgrades on this system
|
||||
|
||||
|
@ -68,33 +68,40 @@ def list_upgrades(refresh=True):
|
|||
if salt.utils.is_true(refresh):
|
||||
refresh_db()
|
||||
ret = {}
|
||||
call = __salt__['cmd.run_all'](
|
||||
'zypper list-updates', output_loglevel='trace'
|
||||
)
|
||||
cmd = ['zypper', 'list-updates']
|
||||
|
||||
repo = None
|
||||
if 'fromrepo' in kwargs:
|
||||
repo = kwargs['fromrepo'] \
|
||||
if isinstance(kwargs['fromrepo'], six.string_types) \
|
||||
else str(kwargs['fromrepo'])
|
||||
cmd.extend(['--repo', repo])
|
||||
|
||||
call = __salt__['cmd.run_all'](cmd,
|
||||
python_shell=False,
|
||||
output_loglevel='trace')
|
||||
if call['retcode'] != 0:
|
||||
comment = ''
|
||||
if 'stderr' in call:
|
||||
comment += call['stderr']
|
||||
if 'stdout' in call:
|
||||
comment += call['stdout']
|
||||
raise CommandExecutionError(
|
||||
'{0}'.format(comment)
|
||||
)
|
||||
msg = 'Failed to get upgrades'
|
||||
for key in ('stderr', 'stdout'):
|
||||
if call[key]:
|
||||
msg += ': ' + call[key]
|
||||
break
|
||||
raise CommandExecutionError(msg)
|
||||
else:
|
||||
out = call['stdout']
|
||||
|
||||
# Repo name is not part of output when a repo is specified in the zypper
|
||||
# command, so the information will be in a different column
|
||||
name_idx, avail_idx = (2, 4) if repo is None else (1, 3)
|
||||
|
||||
for line in out.splitlines():
|
||||
if not line:
|
||||
continue
|
||||
if '|' not in line:
|
||||
comps = [x.strip() for x in line.split('|')]
|
||||
if comps[0] != 'v':
|
||||
continue
|
||||
try:
|
||||
status, repo, name, cur, avail, arch = \
|
||||
[x.strip() for x in line.split('|')]
|
||||
except (ValueError, IndexError):
|
||||
ret[comps[name_idx]] = comps[avail_idx]
|
||||
except IndexError:
|
||||
continue
|
||||
if status == 'v':
|
||||
ret[name] = avail
|
||||
return ret
|
||||
|
||||
# Provide a list_updates function for those used to using zypper list-updates
|
||||
|
|
|
@ -1637,14 +1637,19 @@ def uptodate(name, refresh=False, **kwargs):
|
|||
ret['comment'] = 'State pkg.uptodate is not available'
|
||||
return ret
|
||||
|
||||
# emerge --update doesn't appear to support repo notation
|
||||
if 'fromrepo' in kwargs and __grains__['os'] == 'Gentoo':
|
||||
ret['comment'] = '\'fromrepo\' argument not supported on this platform'
|
||||
return ret
|
||||
|
||||
if isinstance(refresh, bool):
|
||||
try:
|
||||
packages = __salt__['pkg.list_upgrades'](refresh=refresh)
|
||||
packages = __salt__['pkg.list_upgrades'](refresh=refresh, **kwargs)
|
||||
except Exception as e:
|
||||
ret['comment'] = str(e)
|
||||
return ret
|
||||
else:
|
||||
ret['comment'] = 'refresh must be a boolean.'
|
||||
ret['comment'] = 'refresh must be either True or False'
|
||||
return ret
|
||||
|
||||
if not packages:
|
||||
|
|
Loading…
Add table
Reference in a new issue