2021-01-08 13:41:50 +01:00
|
|
|
From 828650500159fd7040d2fa76b2fc4d2b627f7065 Mon Sep 17 00:00:00 2001
|
2019-10-25 11:14:18 +02:00
|
|
|
From: Alberto Planas <aplanas@gmail.com>
|
|
|
|
Date: Tue, 22 Oct 2019 11:02:33 +0200
|
|
|
|
Subject: [PATCH] Accumulated changes from Yomi (#167)
|
|
|
|
|
|
|
|
* core.py: ignore wrong product_name files
|
|
|
|
|
|
|
|
Some firmwares (like some NUC machines), do not provide valid
|
|
|
|
/sys/class/dmi/id/product_name strings. In those cases an
|
|
|
|
UnicodeDecodeError exception happens.
|
|
|
|
|
|
|
|
This patch ignore this kind of issue during the grains creation.
|
|
|
|
|
|
|
|
(cherry picked from commit 2d57d2a6063488ad9329a083219e3826e945aa2d)
|
|
|
|
|
|
|
|
* zypperpkg: understand product type
|
|
|
|
|
|
|
|
(cherry picked from commit b865491b74679140f7a71c5ba50d482db47b600f)
|
|
|
|
---
|
2021-01-08 13:41:50 +01:00
|
|
|
salt/grains/core.py | 6 +--
|
|
|
|
salt/modules/zypperpkg.py | 22 ----------
|
|
|
|
tests/unit/grains/test_core.py | 64 +++++++++++++++++++++++++++-
|
|
|
|
tests/unit/modules/test_zypperpkg.py | 38 +++++++++++++++++
|
|
|
|
4 files changed, 103 insertions(+), 27 deletions(-)
|
2019-10-25 11:14:18 +02:00
|
|
|
|
|
|
|
diff --git a/salt/grains/core.py b/salt/grains/core.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index 0dc1d97f97..a2983e388b 100644
|
2019-10-25 11:14:18 +02:00
|
|
|
--- a/salt/grains/core.py
|
|
|
|
+++ b/salt/grains/core.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -1046,7 +1046,7 @@ def _virtual(osdata):
|
|
|
|
if os.path.isfile("/sys/devices/virtual/dmi/id/product_name"):
|
|
|
|
try:
|
|
|
|
with salt.utils.files.fopen(
|
|
|
|
- "/sys/devices/virtual/dmi/id/product_name", "rb"
|
|
|
|
+ "/sys/devices/virtual/dmi/id/product_name", "r"
|
|
|
|
) as fhr:
|
|
|
|
output = salt.utils.stringutils.to_unicode(
|
|
|
|
fhr.read(), errors="replace"
|
|
|
|
@@ -1066,9 +1066,7 @@ def _virtual(osdata):
|
|
|
|
except UnicodeDecodeError:
|
|
|
|
# Some firmwares provide non-valid 'product_name'
|
|
|
|
# files, ignore them
|
|
|
|
- log.debug(
|
|
|
|
- "The content in /sys/devices/virtual/dmi/id/product_name is not valid"
|
|
|
|
- )
|
2019-10-25 11:14:18 +02:00
|
|
|
+ pass
|
2021-01-08 13:41:50 +01:00
|
|
|
except OSError:
|
2019-10-25 11:14:18 +02:00
|
|
|
pass
|
2021-01-08 13:41:50 +01:00
|
|
|
elif osdata["kernel"] == "FreeBSD":
|
2019-10-25 11:14:18 +02:00
|
|
|
diff --git a/salt/modules/zypperpkg.py b/salt/modules/zypperpkg.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index 2daec0f380..b5621174a4 100644
|
2019-10-25 11:14:18 +02:00
|
|
|
--- a/salt/modules/zypperpkg.py
|
|
|
|
+++ b/salt/modules/zypperpkg.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -958,28 +958,6 @@ def list_pkgs(versions_as_list=False, root=None, includes=None, **kwargs):
|
|
|
|
}
|
|
|
|
]
|
2019-10-25 11:14:18 +02:00
|
|
|
|
2021-01-08 13:41:50 +01:00
|
|
|
- for include in includes:
|
|
|
|
- if include in ("pattern", "patch"):
|
|
|
|
- if include == "pattern":
|
2019-10-25 11:14:18 +02:00
|
|
|
- pkgs = list_installed_patterns(root=root)
|
2021-01-08 13:41:50 +01:00
|
|
|
- elif include == "patch":
|
2019-10-25 11:14:18 +02:00
|
|
|
- pkgs = list_installed_patches(root=root)
|
2021-01-08 13:41:50 +01:00
|
|
|
- else:
|
2019-10-25 11:14:18 +02:00
|
|
|
- pkgs = []
|
|
|
|
- for pkg in pkgs:
|
2021-01-08 13:41:50 +01:00
|
|
|
- pkg_extended_name = "{}:{}".format(include, pkg)
|
|
|
|
- info = info_available(pkg_extended_name, refresh=False, root=root)
|
|
|
|
- _ret[pkg_extended_name] = [
|
|
|
|
- {
|
|
|
|
- "epoch": None,
|
|
|
|
- "version": info[pkg]["version"],
|
|
|
|
- "release": None,
|
|
|
|
- "arch": info[pkg]["arch"],
|
|
|
|
- "install_date": None,
|
|
|
|
- "install_date_time_t": None,
|
|
|
|
- }
|
|
|
|
- ]
|
|
|
|
-
|
|
|
|
__context__[contextkey] = _ret
|
|
|
|
|
|
|
|
return __salt__["pkg_resource.format_pkg_list"](
|
2019-10-25 11:14:18 +02:00
|
|
|
diff --git a/tests/unit/grains/test_core.py b/tests/unit/grains/test_core.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index a5ceeb8317..0dc3423646 100644
|
2019-10-25 11:14:18 +02:00
|
|
|
--- a/tests/unit/grains/test_core.py
|
|
|
|
+++ b/tests/unit/grains/test_core.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -2047,13 +2047,74 @@ class CoreGrainsTestCase(TestCase, LoaderModuleMockMixin):
|
|
|
|
result = core.path()
|
|
|
|
assert result == {"path": path, "systempath": comps}, result
|
|
|
|
|
|
|
|
+ @skipIf(not salt.utils.platform.is_linux(), "System is not Linux")
|
|
|
|
+ @patch("os.path.exists")
|
|
|
|
+ @patch("salt.utils.platform.is_proxy")
|
2019-10-25 11:14:18 +02:00
|
|
|
+ def test_kernelparams_return(self):
|
|
|
|
+ expectations = [
|
2021-01-08 13:41:50 +01:00
|
|
|
+ (
|
|
|
|
+ "BOOT_IMAGE=/vmlinuz-3.10.0-693.2.2.el7.x86_64",
|
|
|
|
+ {
|
|
|
|
+ "kernelparams": [
|
|
|
|
+ ("BOOT_IMAGE", "/vmlinuz-3.10.0-693.2.2.el7.x86_64")
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ ),
|
|
|
|
+ (
|
|
|
|
+ "root=/dev/mapper/centos_daemon-root",
|
|
|
|
+ {"kernelparams": [("root", "/dev/mapper/centos_daemon-root")]},
|
|
|
|
+ ),
|
|
|
|
+ (
|
|
|
|
+ "rhgb quiet ro",
|
|
|
|
+ {"kernelparams": [("rhgb", None), ("quiet", None), ("ro", None)]},
|
|
|
|
+ ),
|
|
|
|
+ ('param="value1"', {"kernelparams": [("param", "value1")]}),
|
|
|
|
+ (
|
|
|
|
+ 'param="value1 value2 value3"',
|
|
|
|
+ {"kernelparams": [("param", "value1 value2 value3")]},
|
|
|
|
+ ),
|
|
|
|
+ (
|
|
|
|
+ 'param="value1 value2 value3" LANG="pl" ro',
|
|
|
|
+ {
|
|
|
|
+ "kernelparams": [
|
|
|
|
+ ("param", "value1 value2 value3"),
|
|
|
|
+ ("LANG", "pl"),
|
|
|
|
+ ("ro", None),
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ ),
|
|
|
|
+ ("ipv6.disable=1", {"kernelparams": [("ipv6.disable", "1")]}),
|
|
|
|
+ (
|
|
|
|
+ 'param="value1:value2:value3"',
|
|
|
|
+ {"kernelparams": [("param", "value1:value2:value3")]},
|
|
|
|
+ ),
|
|
|
|
+ (
|
|
|
|
+ 'param="value1,value2,value3"',
|
|
|
|
+ {"kernelparams": [("param", "value1,value2,value3")]},
|
|
|
|
+ ),
|
|
|
|
+ (
|
|
|
|
+ 'param="value1" param="value2" param="value3"',
|
|
|
|
+ {
|
|
|
|
+ "kernelparams": [
|
|
|
|
+ ("param", "value1"),
|
|
|
|
+ ("param", "value2"),
|
|
|
|
+ ("param", "value3"),
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ ),
|
2019-10-25 11:14:18 +02:00
|
|
|
+ ]
|
|
|
|
+
|
|
|
|
+ for cmdline, expectation in expectations:
|
2021-01-08 13:41:50 +01:00
|
|
|
+ with patch("salt.utils.files.fopen", mock_open(read_data=cmdline)):
|
2019-10-25 11:14:18 +02:00
|
|
|
+ self.assertEqual(core.kernelparams(), expectation)
|
|
|
|
+
|
2021-01-08 13:41:50 +01:00
|
|
|
@skipIf(not salt.utils.platform.is_linux(), "System is not Linux")
|
|
|
|
@patch("os.path.exists")
|
|
|
|
@patch("salt.utils.platform.is_proxy")
|
|
|
|
def test__hw_data_linux_empty(self, is_proxy, exists):
|
|
|
|
is_proxy.return_value = False
|
|
|
|
exists.return_value = True
|
|
|
|
- with patch("salt.utils.files.fopen", mock_open(read_data=b"")):
|
|
|
|
+ with patch("salt.utils.files.fopen", mock_open(read_data="")):
|
|
|
|
self.assertEqual(
|
|
|
|
core._hw_data({"kernel": "Linux"}),
|
|
|
|
{
|
|
|
|
@@ -2067,6 +2128,7 @@ class CoreGrainsTestCase(TestCase, LoaderModuleMockMixin):
|
|
|
|
)
|
|
|
|
|
|
|
|
@skipIf(not salt.utils.platform.is_linux(), "System is not Linux")
|
|
|
|
+ @skipIf(six.PY2, "UnicodeDecodeError is throw in Python 3")
|
|
|
|
@patch("os.path.exists")
|
|
|
|
@patch("salt.utils.platform.is_proxy")
|
|
|
|
def test__hw_data_linux_unicode_error(self, is_proxy, exists):
|
2019-10-25 11:14:18 +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 5d4e7766b6..1b62122e0e 100644
|
2019-10-25 11:14:18 +02:00
|
|
|
--- a/tests/unit/modules/test_zypperpkg.py
|
|
|
|
+++ b/tests/unit/modules/test_zypperpkg.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -1424,6 +1424,44 @@ Repository 'DUMMY' not found by its alias, number, or URI.
|
|
|
|
ret, {"product:openSUSE": {"old": "15.2", "new": "15.3"}}
|
|
|
|
)
|
2019-10-25 11:14:18 +02:00
|
|
|
|
2021-01-08 13:41:50 +01:00
|
|
|
+ @patch("salt.modules.zypperpkg._systemd_scope", MagicMock(return_value=False))
|
|
|
|
+ @patch(
|
|
|
|
+ "salt.modules.zypperpkg.list_products",
|
|
|
|
+ MagicMock(return_value={"openSUSE": {"installed": False, "summary": "test"}}),
|
|
|
|
+ )
|
|
|
|
+ @patch(
|
|
|
|
+ "salt.modules.zypperpkg.list_pkgs",
|
|
|
|
+ MagicMock(
|
|
|
|
+ side_effect=[{"product:openSUSE": "15.2"}, {"product:openSUSE": "15.3"}]
|
|
|
|
+ ),
|
|
|
|
+ )
|
2019-10-25 11:14:18 +02:00
|
|
|
+ def test_install_product_ok(self):
|
2021-01-08 13:41:50 +01:00
|
|
|
+ """
|
2019-10-25 11:14:18 +02:00
|
|
|
+ Test successfully product installation.
|
2021-01-08 13:41:50 +01:00
|
|
|
+ """
|
|
|
|
+ with patch.dict(
|
|
|
|
+ zypper.__salt__,
|
|
|
|
+ {
|
|
|
|
+ "pkg_resource.parse_targets": MagicMock(
|
|
|
|
+ return_value=(["product:openSUSE"], None)
|
|
|
|
+ )
|
|
|
|
+ },
|
|
|
|
+ ):
|
|
|
|
+ with patch(
|
|
|
|
+ "salt.modules.zypperpkg.__zypper__.noraise.call", MagicMock()
|
|
|
|
+ ) as zypper_mock:
|
|
|
|
+ ret = zypper.install("product:openSUSE", includes=["product"])
|
2019-10-25 11:14:18 +02:00
|
|
|
+ zypper_mock.assert_called_once_with(
|
2021-01-08 13:41:50 +01:00
|
|
|
+ "--no-refresh",
|
|
|
|
+ "install",
|
|
|
|
+ "--auto-agree-with-licenses",
|
|
|
|
+ "--name",
|
|
|
|
+ "product:openSUSE",
|
|
|
|
+ )
|
|
|
|
+ self.assertDictEqual(
|
|
|
|
+ ret, {"product:openSUSE": {"old": "15.2", "new": "15.3"}}
|
2019-10-25 11:14:18 +02:00
|
|
|
+ )
|
|
|
|
+
|
|
|
|
def test_remove_purge(self):
|
2021-01-08 13:41:50 +01:00
|
|
|
"""
|
2019-10-25 11:14:18 +02:00
|
|
|
Test package removal
|
|
|
|
--
|
2021-01-08 13:41:50 +01:00
|
|
|
2.29.2
|
2019-10-25 11:14:18 +02:00
|
|
|
|
|
|
|
|