2021-01-08 13:41:50 +01:00
|
|
|
From c9543da431aab06c39911c2217e9cb449b63f8e3 Mon Sep 17 00:00:00 2001
|
2020-05-26 10:05:14 +02:00
|
|
|
From: Alberto Planas <aplanas@suse.com>
|
|
|
|
Date: Thu, 21 May 2020 10:19:15 +0200
|
|
|
|
Subject: [PATCH] zypperpkg: filter patterns that start with dot (#244)
|
|
|
|
|
|
|
|
For versions <=SLE12SP4 some patterns can contain alias, and can appear
|
|
|
|
duplicated. The alias start with ".", so they can be filtered.
|
|
|
|
|
|
|
|
If the module try to search by the alias name (pattern:.basename, for
|
|
|
|
example), zypper will not be able to find it and the operation will
|
|
|
|
fail.
|
|
|
|
|
|
|
|
This patch detect and filter the alias, and remove duplicates.
|
|
|
|
|
|
|
|
Fix bsc#1171906
|
|
|
|
|
|
|
|
(cherry picked from commit d043db63000df2892b2e7259f580ede81e33724d)
|
|
|
|
---
|
2021-01-08 13:41:50 +01:00
|
|
|
salt/modules/zypperpkg.py | 9 ++++++---
|
2020-05-26 10:05:14 +02:00
|
|
|
tests/unit/modules/test_zypperpkg.py | 22 ++++++++++++++++++++++
|
2021-01-08 13:41:50 +01:00
|
|
|
2 files changed, 28 insertions(+), 3 deletions(-)
|
2020-05-26 10:05:14 +02:00
|
|
|
|
|
|
|
diff --git a/salt/modules/zypperpkg.py b/salt/modules/zypperpkg.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index b75572f4ff..ffcd1dfa4f 100644
|
2020-05-26 10:05:14 +02:00
|
|
|
--- a/salt/modules/zypperpkg.py
|
|
|
|
+++ b/salt/modules/zypperpkg.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -2422,11 +2422,14 @@ def _get_installed_patterns(root=None):
|
2020-05-26 10:05:14 +02:00
|
|
|
# a real error.
|
2021-01-08 13:41:50 +01:00
|
|
|
output = __salt__["cmd.run"](cmd, ignore_retcode=True)
|
2020-05-26 10:05:14 +02:00
|
|
|
|
2021-01-08 13:41:50 +01:00
|
|
|
- installed_patterns = [
|
2020-05-26 10:05:14 +02:00
|
|
|
+ # On <= SLE12SP4 we have patterns that have multiple names (alias)
|
|
|
|
+ # and that are duplicated. The alias start with ".", so we filter
|
|
|
|
+ # them.
|
|
|
|
+ installed_patterns = {
|
2021-01-08 13:41:50 +01:00
|
|
|
_pattern_name(line)
|
|
|
|
for line in output.splitlines()
|
|
|
|
- if line.startswith("pattern() = ")
|
|
|
|
- ]
|
2020-05-26 10:05:14 +02:00
|
|
|
+ if line.startswith("pattern() = ") and not _pattern_name(line).startswith(".")
|
|
|
|
+ }
|
|
|
|
|
2021-01-08 13:41:50 +01:00
|
|
|
patterns = {
|
|
|
|
k: v for k, v in _get_visible_patterns(root=root).items() if v["installed"]
|
2020-05-26 10:05:14 +02:00
|
|
|
diff --git a/tests/unit/modules/test_zypperpkg.py b/tests/unit/modules/test_zypperpkg.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index 1b62122e0e..b346ef9ebd 100644
|
2020-05-26 10:05:14 +02:00
|
|
|
--- a/tests/unit/modules/test_zypperpkg.py
|
|
|
|
+++ b/tests/unit/modules/test_zypperpkg.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -1978,6 +1978,28 @@ pattern() = package-c"""
|
|
|
|
"package-c": {"installed": True, "summary": "Non-visible pattern",},
|
2020-05-26 10:05:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+ @patch("salt.modules.zypperpkg._get_visible_patterns")
|
|
|
|
+ def test__get_installed_patterns_with_alias(self, get_visible_patterns):
|
|
|
|
+ """Test installed patterns in the system if they have alias"""
|
|
|
|
+ get_visible_patterns.return_value = {
|
|
|
|
+ "package-a": {"installed": True, "summary": "description a"},
|
|
|
|
+ "package-b": {"installed": False, "summary": "description b"},
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ salt_mock = {
|
|
|
|
+ "cmd.run": MagicMock(
|
|
|
|
+ return_value="""pattern() = .package-a-alias
|
|
|
|
+pattern() = package-a
|
|
|
|
+pattern-visible()
|
|
|
|
+pattern() = package-c"""
|
|
|
|
+ ),
|
|
|
|
+ }
|
|
|
|
+ with patch.dict("salt.modules.zypperpkg.__salt__", salt_mock):
|
|
|
|
+ assert zypper._get_installed_patterns() == {
|
|
|
|
+ "package-a": {"installed": True, "summary": "description a"},
|
|
|
|
+ "package-c": {"installed": True, "summary": "Non-visible pattern"},
|
|
|
|
+ }
|
|
|
|
+
|
2021-01-08 13:41:50 +01:00
|
|
|
@patch("salt.modules.zypperpkg._get_visible_patterns")
|
2020-05-26 10:05:14 +02:00
|
|
|
def test_list_patterns(self, get_visible_patterns):
|
2021-01-08 13:41:50 +01:00
|
|
|
"""Test available patterns in the repo"""
|
2020-05-26 10:05:14 +02:00
|
|
|
--
|
2021-01-08 13:41:50 +01:00
|
|
|
2.29.2
|
2020-05-26 10:05:14 +02:00
|
|
|
|
|
|
|
|