2686359b2c
- Update to Salt release version 3006.0 (jsc#PED-3139) * See release notes: https://docs.saltproject.io/en/latest/topics/releases/3006.0.html - Add python3-looseversion as new dependency for salt - Add python3-packaging as new dependency for salt - Drop conflictive patch dicarded from upstream - Fix SLS rendering error when Jinja macros are used - Fix version detection and avoid building and testing failures - Added: * fix-version-detection-and-avoid-building-and-testing.patch * make-sure-the-file-client-is-destroyed-upon-used.patch - Modified: * 3005.1-implement-zypper-removeptf-573.patch * activate-all-beacons-sources-config-pillar-grains.patch * add-custom-suse-capabilities-as-grains.patch * add-environment-variable-to-know-if-yum-is-invoked-f.patch * add-migrated-state-and-gpg-key-management-functions-.patch * add-publish_batch-to-clearfuncs-exposed-methods.patch * add-salt-ssh-support-with-venv-salt-minion-3004-493.patch * add-sleep-on-exception-handling-on-minion-connection.patch * add-standalone-configuration-file-for-enabling-packa.patch * add-support-for-gpgautoimport-539.patch * allow-vendor-change-option-with-zypper.patch * async-batch-implementation.patch * avoid-excessive-syslogging-by-watchdog-cronjob-58.patch * bsc-1176024-fix-file-directory-user-and-group-owners.patch * change-the-delimeters-to-prevent-possible-tracebacks.patch * control-the-collection-of-lvm-grains-via-config.patch * debian-info_installed-compatibility-50453.patch * dnfnotify-pkgset-plugin-implementation-3002.2-450.patch * do-not-load-pip-state-if-there-is-no-3rd-party-depen.patch * don-t-use-shell-sbin-nologin-in-requisites.patch * drop-serial-from-event.unpack-in-cli.batch_async.patch * early-feature-support-config.patch * enable-passing-a-unix_socket-for-mysql-returners-bsc.patch * enhance-openscap-module-add-xccdf_eval-call-386.patch * fix-bsc-1065792.patch * fix-for-suse-expanded-support-detection.patch * fix-issue-2068-test.patch * fix-missing-minion-returns-in-batch-mode-360.patch * fix-ownership-of-salt-thin-directory-when-using-the-.patch * fix-regression-with-depending-client.ssh-on-psutil-b.patch * fix-salt-ssh-opts-poisoning-bsc-1197637-3004-501.patch * fix-salt.utils.stringutils.to_str-calls-to-make-it-w.patch * fix-the-regression-for-yumnotify-plugin-456.patch * fix-traceback.print_exc-calls-for-test_pip_state-432.patch * fixes-for-python-3.10-502.patch * include-aliases-in-the-fqdns-grains.patch * info_installed-works-without-status-attr-now.patch * let-salt-ssh-use-platform-python-binary-in-rhel8-191.patch * make-aptpkg.list_repos-compatible-on-enabled-disable.patch * make-setup.py-script-to-not-require-setuptools-9.1.patch * pass-the-context-to-pillar-ext-modules.patch * prevent-affection-of-ssh.opts-with-lazyloader-bsc-11.patch * prevent-pkg-plugins-errors-on-missing-cookie-path-bs.patch * prevent-shell-injection-via-pre_flight_script_args-4.patch * read-repo-info-without-using-interpolation-bsc-11356.patch * restore-default-behaviour-of-pkg-list-return.patch * return-the-expected-powerpc-os-arch-bsc-1117995.patch * revert-fixing-a-use-case-when-multiple-inotify-beaco.patch * run-salt-api-as-user-salt-bsc-1064520.patch * run-salt-master-as-dedicated-salt-user.patch * save-log-to-logfile-with-docker.build.patch * skip-package-names-without-colon-bsc-1208691-578.patch * switch-firewalld-state-to-use-change_interface.patch * temporary-fix-extend-the-whitelist-of-allowed-comman.patch * update-target-fix-for-salt-ssh-to-process-targets-li.patch * use-adler32-algorithm-to-compute-string-checksums.patch * use-rlock-to-avoid-deadlocks-in-salt-ssh.patch * use-salt-bundle-in-dockermod.patch * x509-fixes-111.patch * zypperpkg-ignore-retcode-104-for-search-bsc-1176697-.patch - Removed: * add-amazon-ec2-detection-for-virtual-grains-bsc-1195.patch * add-support-for-name-pkgs-and-diff_attr-parameters-t.patch * align-amazon-ec2-nitro-grains-with-upstream-pr-bsc-1.patch * allow-entrypoint-compatibility-for-importlib-metadat.patch * clarify-pkg.installed-pkg_verify-documentation.patch * detect-module.run-syntax.patch * fix-salt.states.file.managed-for-follow_symlinks-tru.patch * fix-state.apply-in-test-mode-with-file-state-module-.patch * fix-test_ipc-unit-tests.patch * fixes-pkg.version_cmp-on-openeuler-systems-and-a-few.patch * fopen-workaround-bad-buffering-for-binary-mode-563.patch * ignore-erros-on-reading-license-files-with-dpkg_lowp.patch * ignore-extend-declarations-from-excluded-sls-files.patch * ignore-non-utf8-characters-while-reading-files-with-.patch * include-stdout-in-error-message-for-zypperpkg-559.patch * make-pass-renderer-configurable-other-fixes-532.patch * make-sure-saltcacheloader-use-correct-fileclient-519.patch * normalize-package-names-once-with-pkg.installed-remo.patch * retry-if-rpm-lock-is-temporarily-unavailable-547.patch * set-default-target-for-pip-from-venv_pip_target-envi.patch * state.apply-don-t-check-for-cached-pillar-errors.patch * state.orchestrate_single-does-not-pass-pillar-none-4.patch OBS-URL: https://build.opensuse.org/request/show/1084999 OBS-URL: https://build.opensuse.org/package/show/systemsmanagement:saltstack/salt?expand=0&rev=210
276 lines
12 KiB
Diff
276 lines
12 KiB
Diff
From deaee93b2f83f1524ec136afc1a5198b33d293d2 Mon Sep 17 00:00:00 2001
|
|
From: Alberto Planas <aplanas@suse.com>
|
|
Date: Mon, 5 Oct 2020 16:24:16 +0200
|
|
Subject: [PATCH] zypperpkg: ignore retcode 104 for search()
|
|
(bsc#1176697) (#270)
|
|
|
|
---
|
|
salt/modules/zypperpkg.py | 28 ++++++---
|
|
tests/unit/modules/test_zypperpkg.py | 87 ++++++++++++++++++++++------
|
|
2 files changed, 89 insertions(+), 26 deletions(-)
|
|
|
|
diff --git a/salt/modules/zypperpkg.py b/salt/modules/zypperpkg.py
|
|
index d8220a1fdd..4bb10f445a 100644
|
|
--- a/salt/modules/zypperpkg.py
|
|
+++ b/salt/modules/zypperpkg.py
|
|
@@ -103,6 +103,8 @@ class _Zypper:
|
|
}
|
|
|
|
LOCK_EXIT_CODE = 7
|
|
+ NOT_FOUND_EXIT_CODE = 104
|
|
+
|
|
XML_DIRECTIVES = ["-x", "--xmlout"]
|
|
# ZYPPER_LOCK is not affected by --root
|
|
ZYPPER_LOCK = "/var/run/zypp.pid"
|
|
@@ -134,6 +136,7 @@ class _Zypper:
|
|
self.__no_raise = False
|
|
self.__refresh = False
|
|
self.__ignore_repo_failure = False
|
|
+ self.__ignore_not_found = False
|
|
self.__systemd_scope = False
|
|
self.__root = None
|
|
|
|
@@ -153,6 +156,9 @@ class _Zypper:
|
|
# Ignore exit code for 106 (repo is not available)
|
|
if "no_repo_failure" in kwargs:
|
|
self.__ignore_repo_failure = kwargs["no_repo_failure"]
|
|
+ # Ignore exit code for 104 (package not found)
|
|
+ if "ignore_not_found" in kwargs:
|
|
+ self.__ignore_not_found = kwargs["ignore_not_found"]
|
|
if "systemd_scope" in kwargs:
|
|
self.__systemd_scope = kwargs["systemd_scope"]
|
|
if "root" in kwargs:
|
|
@@ -333,6 +339,10 @@ class _Zypper:
|
|
if self.__root:
|
|
self.__cmd.extend(["--root", self.__root])
|
|
|
|
+ # Do not consider 104 as a retcode error
|
|
+ if self.__ignore_not_found:
|
|
+ kwargs["success_retcodes"] = [_Zypper.NOT_FOUND_EXIT_CODE]
|
|
+
|
|
self.__cmd.extend(args)
|
|
kwargs["output_loglevel"] = "trace"
|
|
kwargs["python_shell"] = False
|
|
@@ -479,9 +489,11 @@ class Wildcard:
|
|
Get available versions of the package.
|
|
:return:
|
|
"""
|
|
- solvables = self.zypper.nolock.xml.call(
|
|
- "se", "-xv", self.name
|
|
- ).getElementsByTagName("solvable")
|
|
+ solvables = (
|
|
+ self.zypper(ignore_not_found=True)
|
|
+ .nolock.xml.call("se", "-v", self.name)
|
|
+ .getElementsByTagName("solvable")
|
|
+ )
|
|
if not solvables:
|
|
raise CommandExecutionError(
|
|
"No packages found matching '{}'".format(self.name)
|
|
@@ -1086,7 +1098,7 @@ def list_repo_pkgs(*args, **kwargs):
|
|
|
|
root = kwargs.get("root") or None
|
|
for node in (
|
|
- __zypper__(root=root)
|
|
+ __zypper__(root=root, ignore_not_found=True)
|
|
.xml.call("se", "-s", *targets)
|
|
.getElementsByTagName("solvable")
|
|
):
|
|
@@ -2556,7 +2568,9 @@ def owner(*paths, **kwargs):
|
|
def _get_visible_patterns(root=None):
|
|
"""Get all available patterns in the repo that are visible."""
|
|
patterns = {}
|
|
- search_patterns = __zypper__(root=root).nolock.xml.call("se", "-t", "pattern")
|
|
+ search_patterns = __zypper__(root=root, ignore_not_found=True).nolock.xml.call(
|
|
+ "se", "-t", "pattern"
|
|
+ )
|
|
for element in search_patterns.getElementsByTagName("solvable"):
|
|
installed = element.getAttribute("status") == "installed"
|
|
patterns[element.getAttribute("name")] = {
|
|
@@ -2753,7 +2767,7 @@ def search(criteria, refresh=False, **kwargs):
|
|
|
|
cmd.append(criteria)
|
|
solvables = (
|
|
- __zypper__(root=root)
|
|
+ __zypper__(root=root, ignore_not_found=True)
|
|
.nolock.noraise.xml.call(*cmd)
|
|
.getElementsByTagName("solvable")
|
|
)
|
|
@@ -3005,7 +3019,7 @@ def _get_patches(installed_only=False, root=None):
|
|
"""
|
|
patches = {}
|
|
for element in (
|
|
- __zypper__(root=root)
|
|
+ __zypper__(root=root, ignore_not_found=True)
|
|
.nolock.xml.call("se", "-t", "patch")
|
|
.getElementsByTagName("solvable")
|
|
):
|
|
diff --git a/tests/unit/modules/test_zypperpkg.py b/tests/unit/modules/test_zypperpkg.py
|
|
index 22137a2544..5e4c967520 100644
|
|
--- a/tests/unit/modules/test_zypperpkg.py
|
|
+++ b/tests/unit/modules/test_zypperpkg.py
|
|
@@ -28,7 +28,10 @@ class ZyppCallMock:
|
|
|
|
def __call__(self, *args, **kwargs):
|
|
# If the call is for a configuration modifier, we return self
|
|
- if any(i in kwargs for i in ("no_repo_failure", "systemd_scope", "root")):
|
|
+ if any(
|
|
+ i in kwargs
|
|
+ for i in ("no_repo_failure", "ignore_not_found", "systemd_scope", "root")
|
|
+ ):
|
|
return self
|
|
return MagicMock(return_value=self.__return_value)()
|
|
|
|
@@ -1662,8 +1665,9 @@ class ZypperTestCase(TestCase, LoaderModuleMockMixin):
|
|
<solvable status="installed" name="libzypp" kind="package" edition="16.2.4-19.5" arch="x86_64" repository="(System Packages)"/>
|
|
</solvable-list></search-result></stream>
|
|
"""
|
|
- _zpr = MagicMock()
|
|
- _zpr.nolock.xml.call = MagicMock(return_value=minidom.parseString(xmldoc))
|
|
+ __zpr = MagicMock()
|
|
+ __zpr.nolock.xml.call.return_value = minidom.parseString(xmldoc)
|
|
+ _zpr = MagicMock(return_value=__zpr)
|
|
wcard = zypper.Wildcard(_zpr)
|
|
wcard.name, wcard.version = "libzypp", "*"
|
|
assert wcard._get_scope_versions(wcard._get_available_versions()) == [
|
|
@@ -1685,8 +1689,9 @@ class ZypperTestCase(TestCase, LoaderModuleMockMixin):
|
|
</solvable-list></search-result></stream>
|
|
"""
|
|
|
|
- _zpr = MagicMock()
|
|
- _zpr.nolock.xml.call = MagicMock(return_value=minidom.parseString(xmldoc))
|
|
+ __zpr = MagicMock()
|
|
+ __zpr.nolock.xml.call.return_value = minidom.parseString(xmldoc)
|
|
+ _zpr = MagicMock(return_value=__zpr)
|
|
wcard = zypper.Wildcard(_zpr)
|
|
wcard.name, wcard.version = "libzypp", "16.2.*-2*"
|
|
assert wcard._get_scope_versions(wcard._get_available_versions()) == [
|
|
@@ -1707,8 +1712,9 @@ class ZypperTestCase(TestCase, LoaderModuleMockMixin):
|
|
</solvable-list></search-result></stream>
|
|
"""
|
|
|
|
- _zpr = MagicMock()
|
|
- _zpr.nolock.xml.call = MagicMock(return_value=minidom.parseString(xmldoc))
|
|
+ __zpr = MagicMock()
|
|
+ __zpr.nolock.xml.call.return_value = minidom.parseString(xmldoc)
|
|
+ _zpr = MagicMock(return_value=__zpr)
|
|
wcard = zypper.Wildcard(_zpr)
|
|
wcard.name, wcard.version = "libzypp", "16.2.5*"
|
|
assert wcard._get_scope_versions(wcard._get_available_versions()) == [
|
|
@@ -1728,8 +1734,9 @@ class ZypperTestCase(TestCase, LoaderModuleMockMixin):
|
|
</solvable-list></search-result></stream>
|
|
"""
|
|
|
|
- _zpr = MagicMock()
|
|
- _zpr.nolock.xml.call = MagicMock(return_value=minidom.parseString(xmldoc))
|
|
+ __zpr = MagicMock()
|
|
+ __zpr.nolock.xml.call.return_value = minidom.parseString(xmldoc)
|
|
+ _zpr = MagicMock(return_value=__zpr)
|
|
wcard = zypper.Wildcard(_zpr)
|
|
wcard.name, wcard.version = "libzypp", "*.1"
|
|
assert wcard._get_scope_versions(wcard._get_available_versions()) == [
|
|
@@ -1750,8 +1757,9 @@ class ZypperTestCase(TestCase, LoaderModuleMockMixin):
|
|
<solvable status="other-version" name="libzypp" kind="package" edition="17.2.6-27.9.1" arch="x86_64" repository="foo"/>
|
|
</solvable-list></search-result></stream>
|
|
"""
|
|
- _zpr = MagicMock()
|
|
- _zpr.nolock.xml.call = MagicMock(return_value=minidom.parseString(xmldoc))
|
|
+ __zpr = MagicMock()
|
|
+ __zpr.nolock.xml.call.return_value = minidom.parseString(xmldoc)
|
|
+ _zpr = MagicMock(return_value=__zpr)
|
|
assert zypper.Wildcard(_zpr)("libzypp", "16.2.4*") == "16.2.4-19.5"
|
|
assert zypper.Wildcard(_zpr)("libzypp", "16.2*") == "16.2.5-25.1"
|
|
assert zypper.Wildcard(_zpr)("libzypp", "*6-*") == "17.2.6-27.9.1"
|
|
@@ -1770,8 +1778,10 @@ class ZypperTestCase(TestCase, LoaderModuleMockMixin):
|
|
<solvable status="other-version" name="libzypp" kind="package" edition="17.2.6-27.9.1" arch="x86_64" repository="foo"/>
|
|
</solvable-list></search-result></stream>
|
|
"""
|
|
- _zpr = MagicMock()
|
|
- _zpr.nolock.xml.call = MagicMock(return_value=minidom.parseString(xmldoc))
|
|
+ __zpr = MagicMock()
|
|
+ __zpr.nolock.xml.call.return_value = minidom.parseString(xmldoc)
|
|
+ _zpr = MagicMock(return_value=__zpr)
|
|
+
|
|
assert zypper.Wildcard(_zpr)("libzypp", None) is None
|
|
|
|
def test_wildcard_to_query_typecheck(self):
|
|
@@ -1787,8 +1797,9 @@ class ZypperTestCase(TestCase, LoaderModuleMockMixin):
|
|
<solvable status="other-version" name="libzypp" kind="package" edition="17.2.6-27.9.1" arch="x86_64" repository="foo"/>
|
|
</solvable-list></search-result></stream>
|
|
"""
|
|
- _zpr = MagicMock()
|
|
- _zpr.nolock.xml.call = MagicMock(return_value=minidom.parseString(xmldoc))
|
|
+ __zpr = MagicMock()
|
|
+ __zpr.nolock.xml.call.return_value = minidom.parseString(xmldoc)
|
|
+ _zpr = MagicMock(return_value=__zpr)
|
|
assert isinstance(zypper.Wildcard(_zpr)("libzypp", "*.1"), str)
|
|
|
|
def test_wildcard_to_query_condition_preservation(self):
|
|
@@ -1804,8 +1815,9 @@ class ZypperTestCase(TestCase, LoaderModuleMockMixin):
|
|
<solvable status="other-version" name="libzypp" kind="package" edition="17.2.6-27.9.1" arch="x86_64" repository="foo"/>
|
|
</solvable-list></search-result></stream>
|
|
"""
|
|
- _zpr = MagicMock()
|
|
- _zpr.nolock.xml.call = MagicMock(return_value=minidom.parseString(xmldoc))
|
|
+ __zpr = MagicMock()
|
|
+ __zpr.nolock.xml.call.return_value = minidom.parseString(xmldoc)
|
|
+ _zpr = MagicMock(return_value=__zpr)
|
|
|
|
for op in zypper.Wildcard.Z_OP:
|
|
assert zypper.Wildcard(_zpr)(
|
|
@@ -1831,8 +1843,10 @@ class ZypperTestCase(TestCase, LoaderModuleMockMixin):
|
|
<solvable status="other-version" name="libzypp" kind="package" edition="17.2.6-27.9.1" arch="x86_64" repository="foo"/>
|
|
</solvable-list></search-result></stream>
|
|
"""
|
|
- _zpr = MagicMock()
|
|
- _zpr.nolock.xml.call = MagicMock(return_value=minidom.parseString(xmldoc))
|
|
+ __zpr = MagicMock()
|
|
+ __zpr.nolock.xml.call.return_value = minidom.parseString(xmldoc)
|
|
+ _zpr = MagicMock(return_value=__zpr)
|
|
+
|
|
with self.assertRaises(CommandExecutionError):
|
|
for op in [">>", "==", "<<", "+"]:
|
|
zypper.Wildcard(_zpr)("libzypp", "{}*.1".format(op))
|
|
@@ -1958,3 +1972,38 @@ pattern() = package-c"""
|
|
self.assertFalse(zypper.__zypper__._is_rpm_lock())
|
|
self.assertEqual(lockf_mock.call_count, 2)
|
|
zypper.__zypper__._reset()
|
|
+
|
|
+ def test_search(self):
|
|
+ """Test zypperpkg.search()"""
|
|
+ xml_mock = MagicMock(return_value=[])
|
|
+ zypp_mock = MagicMock(return_value=xml_mock)
|
|
+ ZyppCallMock(return_value=xml_mock)
|
|
+ with patch("salt.modules.zypperpkg.__zypper__", zypp_mock):
|
|
+ zypper.search("emacs")
|
|
+ zypp_mock.assert_called_with(root=None, ignore_not_found=True)
|
|
+ xml_mock.nolock.noraise.xml.call.assert_called_with("search", "emacs")
|
|
+
|
|
+ def test_search_not_found(self):
|
|
+ """Test zypperpkg.search()"""
|
|
+ ret = {
|
|
+ "stdout": "<?xml version='1.0'?><stream></stream>",
|
|
+ "stderr": None,
|
|
+ "retcode": 104,
|
|
+ }
|
|
+ run_all_mock = MagicMock(return_value=ret)
|
|
+ with patch.dict(zypper.__salt__, {"cmd.run_all": run_all_mock}):
|
|
+ self.assertRaises(CommandExecutionError, zypper.search, "vim")
|
|
+ run_all_mock.assert_called_with(
|
|
+ [
|
|
+ "zypper",
|
|
+ "--non-interactive",
|
|
+ "--xmlout",
|
|
+ "--no-refresh",
|
|
+ "search",
|
|
+ "vim",
|
|
+ ],
|
|
+ success_retcodes=[104],
|
|
+ output_loglevel="trace",
|
|
+ python_shell=False,
|
|
+ env={"ZYPP_READONLY_HACK": "1"},
|
|
+ )
|
|
--
|
|
2.39.2
|
|
|
|
|