SHA256
1
0
forked from pool/salt
salt/0016-write-a-zypper-command-builder-function.patch
Dominique Leuenberger 1592ccc37e Accepting request 361294 from systemsmanagement:saltstack
- fix argument handling of pkg.download
  Add: 0022-fix-argument-handling-for-pkg.download.patch

- unify behavior of zypper refresh in salt
  Add: 0018-unify-behavior-of-refresh.patch
       0019-add-refresh-option-to-more-functions.patch
       0020-simplify-checking-the-refresh-paramater.patch
       0021-do-not-change-kwargs-in-refresh-while-checking-a-val.patch

- Fix crash with scheduler and runners
  Add: 0017-Fix-crash-with-scheduler-and-runners-31106.patch

- Call zypper always with --non-interactive
  Add:
  * 0015-call-zypper-with-option-non-interactive-everywhere.patch
  * 0016-write-a-zypper-command-builder-function.patch

- require rpm-python on SUSE for zypper support

- fix state return code
  Add: 0009-The-functions-in-the-state-module-that-return-a-retc.patch
- add handling of OEM products to pkg.list_products
  Add: 0010-add-handling-for-OEM-products.patch
- improve doc for list_pkgs
  Add: 0011-improve-doc-for-list_pkgs.patch
- implement pkg.version_cmp in zypper.py
  Add:
  * 0012-implement-version_cmp-for-zypper.patch
  * 0013-pylint-changes.patch
  * 0014-Check-if-rpm-python-can-be-imported.patch

- Update to 2015.8.7
  this is a small update to fix some regressions
  see https://docs.saltstack.com/en/latest/topics/releases/2015.8.7.html

- Booleans should not be strings from XML, add Unix ticks time and
  format result in a list of maps.
  Add:
  * 0008-Fix-types-in-the-output-data-and-return-just-a-list-.patch

- Stop salt-api daemon faster (bsc#963322)
  Add:
  * 0007-Force-kill-websocket-s-child-processes-faster-than-d.patch

- Do not crash on salt-key reject/delete consecutive calls.
  Add:
  * 0006-add_key-reject_key-do-not-crash-w-Permission-denied-.patch

- Update to 2015.8.5
  See https://docs.saltstack.com/en/latest/topics/releases/2015.8.5.html
  Dropped patches (all upstream):
  * 0003-List-products-consistently-across-all-SLES-systems.patch
  * 0004-Add-missing-return-data-to-scheduled-jobs.patch
  * 0005-Fix-RPM-issues-with-the-date-time-and-add-package-at.patch
  * 0006-Bugfix-info_available-does-not-work-correctly-on-SLE.patch
  Renamed patches:
  * 0007-Check-if-byte-strings-are-properly-encoded-in-UTF-8.patch
    -> 0003-Check-if-byte-strings-are-properly-encoded-in-UTF-8.patch
  * 0008-Fix-pkg.latest-prevent-crash-on-multiple-package-ins.patch
    -> 0004-Fix-pkg.latest-prevent-crash-on-multiple-package-ins.patch
  * 0009-Fix-package-status-filtering-on-latest-version-and-i.patch
    -> 0005-Fix-package-status-filtering-on-latest-version-and-i.patch
- Update to 2015.8.4
  See https://docs.saltstack.com/en/latest/topics/releases/2015.8.4.html

- Fix latest version available comparison and implement epoch
  support in Zypper module.
  Add:
  * 0009-Fix-package-status-filtering-on-latest-version-and-i.patch

- Update patch from opensuse to upstream version.
  Update:
  * 0008-Fix-pkg.latest-prevent-crash-on-multiple-package-ins.patch

- Fix dependencies to Salt subpackages requiring release along the
  version.

- Fix pkg.latest crash.
- Fix pkg.latest SLS ID bug, when pkgs empty list is passed,
  but SLS ID still treated as a package name.
  Add:
  * 0008-Fix-pkg.latest-prevent-crash-on-multiple-package-ins.patch

- Drop:
  * -0004-zypper-check-package-header-content-for-valid-utf-8.patch
- Rename:
  * -0004-zypper-check-package-header-content-for-valid-utf-8.patch
    +0004-Add-missing-return-data-to-scheduled-jobs.patch
  * -0005-Add-missing-return-data-to-scheduled-jobs.patch
    +0004-Add-missing-return-data-to-scheduled-jobs.patch
  * -0006-Fix-RPM-issues-with-the-date-time-and-add-package-at.patch
    +0005-Fix-RPM-issues-with-the-date-time-and-add-package-at.patch
  * -0007-Bugfix-info_available-does-not-work-correctly-on-SLE.patch
    +0006-Bugfix-info_available-does-not-work-correctly-on-SLE.patch
- Add:
  * 0007-Check-if-byte-strings-are-properly-encoded-in-UTF-8.patch

- Rename use-forking-daemon.patch to
  0001-tserong-suse.com-We-don-t-have-python-systemd-so-not.patch
- Rename use-salt-user-for-master.patch to
  0002-Run-salt-master-as-dedicated-salt-user.patch
- Rename 1efe484309a5c776974e723f3da0f5181f4bdb86.patch to
  0003-List-products-consistently-across-all-SLES-systems.patch
- Rename zypper-utf-8.patch to
  0004-zypper-check-package-header-content-for-valid-utf-8.patch
- Rename salt-2015.8-schedule-ret.patch to
  0005-Add-missing-return-data-to-scheduled-jobs.patch
- Rename salt-2015.8-pkg-zypper-attr-filtering.patch to
  0006-Fix-RPM-issues-with-the-date-time-and-add-package-at.patch
- Rename salt-2015.8-zypper-info.patch to
  0007-Bugfix-info_available-does-not-work-correctly-on-SLE.patch

OBS-URL: https://build.opensuse.org/request/show/361294
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/salt?expand=0&rev=55
2016-02-24 17:43:06 +00:00

202 lines
8.1 KiB
Diff

From 8d25c4c8906581fa44380f72f0f754b56f5e30c3 Mon Sep 17 00:00:00 2001
From: Michael Calmer <mc@suse.de>
Date: Fri, 19 Feb 2016 11:50:31 +0100
Subject: [PATCH 16/22] write a zypper command builder function
---
salt/modules/zypper.py | 62 +++++++++++++++++++++++---------------------------
1 file changed, 29 insertions(+), 33 deletions(-)
diff --git a/salt/modules/zypper.py b/salt/modules/zypper.py
index cb26b51..f878c95 100644
--- a/salt/modules/zypper.py
+++ b/salt/modules/zypper.py
@@ -56,19 +56,18 @@ def __virtual__():
return __virtualname__
-def _zypper(as_list=False):
+def _zypper(*opts):
'''
- Return zypper command with default options as a string.
+ Return zypper command with default options as a list.
- CMD: zypper --non-interactive
+ opts
+ additional options for zypper command
- as_list:
- if set to True, the command and the default options
- are returned as a list
'''
- if as_list:
- return ['zypper', '--non-interactive']
- return "zypper --non-interactive "
+ cmd = ['zypper', '--non-interactive']
+ cmd.extend(opts)
+
+ return cmd
def list_upgrades(refresh=True):
@@ -85,7 +84,7 @@ def list_upgrades(refresh=True):
refresh_db()
ret = {}
call = __salt__['cmd.run_all'](
- _zypper() + 'list-updates', output_loglevel='trace'
+ _zypper('list-updates'), output_loglevel='trace'
)
if call['retcode'] != 0:
comment = ''
@@ -200,7 +199,7 @@ def info_available(*names, **kwargs):
# Run in batches
while batch:
- cmd = '{0} info -t package {1}'.format(_zypper(), ' '.join(batch[:batch_size]))
+ cmd = _zypper('info', '-t', 'package', *batch[:batch_size])
pkg_info.extend(re.split(r"Information for package*", __salt__['cmd.run_stdout'](cmd, output_loglevel='trace')))
batch = batch[batch_size:]
@@ -509,7 +508,7 @@ def del_repo(repo):
repos_cfg = _get_configured_repos()
for alias in repos_cfg.sections():
if alias == repo:
- cmd = ('{0} -x rr --loose-auth --loose-query {1}'.format(_zypper(), alias))
+ cmd = _zypper('-x', 'rr', '--loose-auth', '--loose-query', alias)
doc = dom.parseString(__salt__['cmd.run'](cmd, output_loglevel='trace'))
msg = doc.getElementsByTagName('message')
if doc.getElementsByTagName('progress') and msg:
@@ -598,8 +597,8 @@ def mod_repo(repo, **kwargs):
try:
# Try to parse the output and find the error,
# but this not always working (depends on Zypper version)
- doc = dom.parseString(__salt__['cmd.run'](('{0} -x ar {1} \'{2}\''.format(_zypper(), url, repo)),
- output_loglevel='trace'))
+ doc = dom.parseString(__salt__['cmd.run'](
+ _zypper('-x', 'ar', url, repo), output_loglevel='trace'))
except Exception:
# No XML out available, but it is still unknown the state of the result.
pass
@@ -644,7 +643,8 @@ def mod_repo(repo, **kwargs):
cmd_opt.append("--name='{0}'".format(kwargs.get('humanname')))
if cmd_opt:
- __salt__['cmd.run'](('{0} -x mr {1} \'{2}\''.format(_zypper(), ' '.join(cmd_opt), repo)),
+ cmd_opt.append(repo)
+ __salt__['cmd.run'](_zypper('-x', 'mr', *cmd_opt),
output_loglevel='trace')
# If repo nor added neither modified, error should be thrown
@@ -667,7 +667,7 @@ def refresh_db():
salt '*' pkg.refresh_db
'''
- cmd = _zypper() + 'refresh'
+ cmd = _zypper('refresh')
ret = {}
call = __salt__['cmd.run_all'](cmd, output_loglevel='trace')
if call['retcode'] != 0:
@@ -814,7 +814,7 @@ def install(name=None,
log.info('Targeting repo {0!r}'.format(fromrepo))
else:
fromrepoopt = ''
- cmd_install = _zypper(as_list=True)
+ cmd_install = _zypper()
if not refresh:
cmd_install.append('--no-refresh')
cmd_install += ['install', '--name', '--auto-agree-with-licenses']
@@ -870,7 +870,7 @@ def upgrade(refresh=True):
if salt.utils.is_true(refresh):
refresh_db()
old = list_pkgs()
- cmd = _zypper() + 'update --auto-agree-with-licenses'
+ cmd = _zypper('update', '--auto-agree-with-licenses')
call = __salt__['cmd.run_all'](cmd, output_loglevel='trace')
if call['retcode'] != 0:
ret['result'] = False
@@ -901,10 +901,7 @@ def _uninstall(action='remove', name=None, pkgs=None):
if not targets:
return {}
while targets:
- cmd = (
- '{0} remove {1} {2}'
- .format(_zypper(), purge_arg, ' '.join(targets[:500]))
- )
+ cmd = _zypper('remove', purge_arg, *targets[:500])
__salt__['cmd.run'](cmd, output_loglevel='trace')
targets = targets[500:]
__context__.pop('pkg.list_pkgs', None)
@@ -1018,7 +1015,7 @@ def clean_locks():
if not os.path.exists("/etc/zypp/locks"):
return out
- doc = dom.parseString(__salt__['cmd.run'](_zypper() + '-x cl', output_loglevel='trace'))
+ doc = dom.parseString(__salt__['cmd.run'](_zypper('-x', 'cl'), output_loglevel='trace'))
for node in doc.getElementsByTagName("message"):
text = node.childNodes[0].nodeValue.lower()
if text.startswith(LCK):
@@ -1056,8 +1053,7 @@ def remove_lock(packages, **kwargs): # pylint: disable=unused-argument
missing.append(pkg)
if removed:
- __salt__['cmd.run'](('{0} rl {1}'.format(_zypper(), ' '.join(removed))),
- output_loglevel='trace')
+ __salt__['cmd.run'](_zypper('rl', *removed), output_loglevel='trace')
return {'removed': len(removed), 'not_found': missing}
@@ -1086,8 +1082,7 @@ def add_lock(packages, **kwargs): # pylint: disable=unused-argument
added.append(pkg)
if added:
- __salt__['cmd.run'](('{0} al {1}'.format(_zypper(), ' '.join(added))),
- output_loglevel='trace')
+ __salt__['cmd.run'](_zypper('al', *added), output_loglevel='trace')
return {'added': len(added), 'packages': added}
@@ -1219,7 +1214,7 @@ def _get_patterns(installed_only=None):
List all known patterns in repos.
'''
patterns = {}
- doc = dom.parseString(__salt__['cmd.run']((_zypper() + '--xmlout se -t pattern'),
+ doc = dom.parseString(__salt__['cmd.run'](_zypper('--xmlout', 'se', '-t', 'pattern'),
output_loglevel='trace'))
for element in doc.getElementsByTagName('solvable'):
installed = element.getAttribute('status') == 'installed'
@@ -1268,7 +1263,7 @@ def search(criteria):
salt '*' pkg.search <criteria>
'''
- doc = dom.parseString(__salt__['cmd.run'](('{0} --xmlout se {1}'.format(_zypper(), criteria)),
+ doc = dom.parseString(__salt__['cmd.run'](_zypper('--xmlout', 'se', criteria),
output_loglevel='trace'))
solvables = doc.getElementsByTagName('solvable')
if not solvables:
@@ -1317,8 +1312,10 @@ def list_products(all=False):
'''
ret = list()
OEM_PATH = "/var/lib/suseRegister/OEM"
- doc = dom.parseString(__salt__['cmd.run'](("{0} -x products{1}".format(_zypper(), not all and ' -i' or '')),
- output_loglevel='trace'))
+ cmd = _zypper('-x', 'products')
+ if not all:
+ cmd.append('-i')
+ doc = dom.parseString(__salt__['cmd.run'](cmd, output_loglevel='trace'))
for prd in doc.getElementsByTagName('product-list')[0].getElementsByTagName('product'):
p_nfo = dict()
for k_p_nfo, v_p_nfo in prd.attributes.items():
@@ -1357,8 +1354,7 @@ def download(*packages):
raise CommandExecutionError("No packages has been specified.")
doc = dom.parseString(__salt__['cmd.run'](
- ('{0} -x download {1}'.format(_zypper(), ' '.join(packages))),
- output_loglevel='trace'))
+ _zypper('-x', 'download', *packages), output_loglevel='trace'))
pkg_ret = {}
for dld_result in doc.getElementsByTagName("download-result"):
repo = dld_result.getElementsByTagName("repository")[0]
--
2.1.4