Merge pull request #31378 from mcalmer/zypper-refresh-handling

Zypper refresh handling
This commit is contained in:
Mike Place 2016-02-22 09:50:28 -07:00
commit 83294e4f3a

View file

@ -74,13 +74,18 @@ def list_upgrades(refresh=True):
'''
List all available package upgrades on this system
refresh
force a refresh if set to True (default).
If set to False it depends on zypper if a refresh is
executed.
CLI Example:
.. code-block:: bash
salt '*' pkg.list_upgrades
'''
if salt.utils.is_true(refresh):
if refresh:
refresh_db()
ret = {}
call = __salt__['cmd.run_all'](
@ -174,6 +179,11 @@ def info_available(*names, **kwargs):
'''
Return the information of the named package available for the system.
refresh
force a refresh if set to True (default).
If set to False it depends on zypper if a refresh is
executed or not.
CLI example:
.. code-block:: bash
@ -189,7 +199,7 @@ def info_available(*names, **kwargs):
names = sorted(list(set(names)))
# Refresh db before extracting the latest package
if salt.utils.is_true(kwargs.pop('refresh', True)):
if kwargs.get('refresh', True):
refresh_db()
pkg_info = []
@ -656,7 +666,7 @@ def mod_repo(repo, **kwargs):
def refresh_db():
'''
Just run a ``zypper refresh``, return a dict::
Force a repository refresh by calling ``zypper refresh --force``, return a dict::
{'<database name>': Bool}
@ -666,7 +676,7 @@ def refresh_db():
salt '*' pkg.refresh_db
'''
cmd = _zypper('refresh')
cmd = _zypper('refresh', '--force')
ret = {}
call = __salt__['cmd.run_all'](cmd, output_loglevel='trace')
if call['retcode'] != 0:
@ -703,7 +713,7 @@ def install(name=None,
version=None,
**kwargs):
'''
Install the passed package(s), add refresh=True to run 'zypper refresh'
Install the passed package(s), add refresh=True to force a 'zypper refresh'
before package is installed.
name
@ -720,7 +730,9 @@ def install(name=None,
salt '*' pkg.install <package name>
refresh
Whether or not to refresh the package database before installing.
force a refresh if set to True.
If set to False (default) it depends on zypper if a refresh is
executed.
fromrepo
Specify a package repository to install from.
@ -768,6 +780,9 @@ def install(name=None,
{'<package>': {'old': '<old-version>',
'new': '<new-version>'}}
'''
if refresh:
refresh_db()
try:
pkg_params, pkg_type = __salt__['pkg_resource.parse_targets'](name, pkgs, sources, **kwargs)
except MinionError as exc:
@ -814,8 +829,6 @@ def install(name=None,
else:
fromrepoopt = ''
cmd_install = _zypper()
if not refresh:
cmd_install.append('--no-refresh')
cmd_install += ['install', '--name', '--auto-agree-with-licenses']
if downloadonly:
cmd_install.append('--download-only')
@ -850,6 +863,11 @@ def upgrade(refresh=True):
'''
Run a full system upgrade, a zypper upgrade
refresh
force a refresh if set to True (default).
If set to False it depends on zypper if a refresh is
executed.
Return a dict containing the new package names and versions::
{'<package>': {'old': '<old-version>',
@ -866,7 +884,7 @@ def upgrade(refresh=True):
'comment': '',
}
if salt.utils.is_true(refresh):
if refresh:
refresh_db()
old = list_pkgs()
cmd = _zypper('update', '--auto-agree-with-licenses')
@ -1226,16 +1244,24 @@ def _get_patterns(installed_only=None):
return patterns
def list_patterns():
def list_patterns(refresh=False):
'''
List all known patterns from available repos.
refresh
force a refresh if set to True.
If set to False (default) it depends on zypper if a refresh is
executed.
CLI Examples:
.. code-block:: bash
salt '*' pkg.list_patterns
'''
if refresh:
refresh_db()
return _get_patterns()
@ -1252,16 +1278,24 @@ def list_installed_patterns():
return _get_patterns(installed_only=True)
def search(criteria):
def search(criteria, refresh=False):
'''
List known packags, available to the system.
refresh
force a refresh if set to True.
If set to False (default) it depends on zypper if a refresh is
executed.
CLI Examples:
.. code-block:: bash
salt '*' pkg.search <criteria>
'''
if refresh:
refresh_db()
doc = dom.parseString(__salt__['cmd.run'](_zypper('--xmlout', 'se', criteria),
output_loglevel='trace'))
solvables = doc.getElementsByTagName('solvable')
@ -1292,13 +1326,18 @@ def _get_first_aggregate_text(node_list):
return '\n'.join(out)
def list_products(all=False):
def list_products(all=False, refresh=False):
'''
List all available or installed SUSE products.
all
List all products available or only installed. Default is False.
refresh
force a refresh if set to True.
If set to False (default) it depends on zypper if a refresh is
executed.
Includes handling for OEM products, which read the OEM productline file
and overwrite the release value.
@ -1309,6 +1348,9 @@ def list_products(all=False):
salt '*' pkg.list_products
salt '*' pkg.list_products all=True
'''
if refresh:
refresh_db()
ret = list()
OEM_PATH = "/var/lib/suseRegister/OEM"
cmd = _zypper('-x', 'products')
@ -1338,10 +1380,15 @@ def list_products(all=False):
return ret
def download(*packages):
def download(refresh=False, *packages):
"""
Download packages to the local disk.
refresh
force a refresh if set to True.
If set to False (default) it depends on zypper if a refresh is
executed.
CLI example:
.. code-block:: bash
@ -1352,6 +1399,9 @@ def download(*packages):
if not packages:
raise CommandExecutionError("No packages has been specified.")
if refresh:
refresh_db()
doc = dom.parseString(__salt__['cmd.run'](
_zypper('-x', 'download', *packages), output_loglevel='trace'))
pkg_ret = {}