SHA256
1
0
forked from pool/salt
salt/0014-Add-ignore_repo_failure-option-to-suppress-zypper-s-.patch

83 lines
3.2 KiB
Diff
Raw Normal View History

From f860f7ccb3dba6b8f0cef61e2d9658a3116e3c3c Mon Sep 17 00:00:00 2001
From: Bo Maryniuk <bo@suse.de>
Date: Mon, 15 Aug 2016 15:03:53 +0200
Subject: [PATCH 14/15] Add ignore_repo_failure option to suppress zypper's
exit code 106 on unavailable repos
---
salt/modules/zypper.py | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/salt/modules/zypper.py b/salt/modules/zypper.py
index 547d72b..1c60f0f 100644
--- a/salt/modules/zypper.py
+++ b/salt/modules/zypper.py
@@ -100,6 +100,18 @@ class _Zypper(object):
self.__no_lock = False
self.__no_raise = False
self.__refresh = False
+ self.__ignore_repo_failure = False
+
+ def __call__(self, *args, **kwargs):
+ '''
+ :param args:
+ :param kwargs:
+ :return:
+ '''
+ # Ignore exit code for 106 (repo is not available)
+ if 'no_repo_failure' in kwargs:
+ self.__ignore_repo_failure = kwargs['no_repo_failure']
+ return self
def __getattr__(self, item):
'''
@@ -275,7 +287,7 @@ class _Zypper(object):
__salt__['event.fire_master']({'success': not len(self.error_msg),
'info': self.error_msg or 'Zypper has been released'},
self.TAG_RELEASED)
- if self.error_msg and not self.__no_raise:
+ if self.error_msg and not self.__no_raise and not self.__ignore_repo_failure:
raise CommandExecutionError('Zypper command failure: {0}'.format(self.error_msg))
return self._is_xml_mode() and dom.parseString(self.__call_result['stdout']) or self.__call_result['stdout']
@@ -863,6 +875,7 @@ def install(name=None,
downloadonly=None,
skip_verify=False,
version=None,
+ ignore_repo_failure=False,
**kwargs):
'''
Install the passed package(s), add refresh=True to force a 'zypper refresh'
@@ -929,6 +942,10 @@ def install(name=None,
salt '*' pkg.install sources='[{"foo": "salt://foo.rpm"},{"bar": "salt://bar.rpm"}]'
+ ignore_repo_failure
+ Zypper returns error code 106 if one of the repositories are not available for various reasons.
+ In case to set strict check, this parameter needs to be set to True. Default: False.
+
Returns a dict containing the new package names and versions::
@@ -1000,7 +1017,7 @@ def install(name=None,
while targets:
cmd = cmd_install + targets[:500]
targets = targets[500:]
- for line in __zypper__.call(*cmd).splitlines():
+ for line in __zypper__(no_repo_failure=ignore_repo_failure).call(*cmd).splitlines():
match = re.match(r"^The selected package '([^']+)'.+has lower version", line)
if match:
downgrades.append(match.group(1))
@@ -1008,7 +1025,7 @@ def install(name=None,
while downgrades:
cmd = cmd_install + ['--force'] + downgrades[:500]
downgrades = downgrades[500:]
- __zypper__.call(*cmd)
+ __zypper__(no_repo_failure=ignore_repo_failure).call(*cmd)
__context__.pop('pkg.list_pkgs', None)
new = list_pkgs()
--
2.9.3