Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Step:15-SP6
salt.22687
accumulated-changes-from-yomi-167.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File accumulated-changes-from-yomi-167.patch of Package salt.22687
From 828650500159fd7040d2fa76b2fc4d2b627f7065 Mon Sep 17 00:00:00 2001 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) --- 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(-) diff --git a/salt/grains/core.py b/salt/grains/core.py index 0dc1d97f97..a2983e388b 100644 --- a/salt/grains/core.py +++ b/salt/grains/core.py @@ -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" - ) + pass except OSError: pass elif osdata["kernel"] == "FreeBSD": diff --git a/salt/modules/zypperpkg.py b/salt/modules/zypperpkg.py index 2daec0f380..b5621174a4 100644 --- a/salt/modules/zypperpkg.py +++ b/salt/modules/zypperpkg.py @@ -958,28 +958,6 @@ def list_pkgs(versions_as_list=False, root=None, includes=None, **kwargs): } ] - for include in includes: - if include in ("pattern", "patch"): - if include == "pattern": - pkgs = list_installed_patterns(root=root) - elif include == "patch": - pkgs = list_installed_patches(root=root) - else: - pkgs = [] - for pkg in pkgs: - 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"]( diff --git a/tests/unit/grains/test_core.py b/tests/unit/grains/test_core.py index a5ceeb8317..0dc3423646 100644 --- a/tests/unit/grains/test_core.py +++ b/tests/unit/grains/test_core.py @@ -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") + def test_kernelparams_return(self): + expectations = [ + ( + "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"), + ] + }, + ), + ] + + for cmdline, expectation in expectations: + with patch("salt.utils.files.fopen", mock_open(read_data=cmdline)): + self.assertEqual(core.kernelparams(), expectation) + @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): diff --git a/tests/unit/modules/test_zypperpkg.py b/tests/unit/modules/test_zypperpkg.py index 5d4e7766b6..1b62122e0e 100644 --- a/tests/unit/modules/test_zypperpkg.py +++ b/tests/unit/modules/test_zypperpkg.py @@ -1424,6 +1424,44 @@ Repository 'DUMMY' not found by its alias, number, or URI. ret, {"product:openSUSE": {"old": "15.2", "new": "15.3"}} ) + @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"}] + ), + ) + def test_install_product_ok(self): + """ + Test successfully product installation. + """ + 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"]) + zypper_mock.assert_called_once_with( + "--no-refresh", + "install", + "--auto-agree-with-licenses", + "--name", + "product:openSUSE", + ) + self.assertDictEqual( + ret, {"product:openSUSE": {"old": "15.2", "new": "15.3"}} + ) + def test_remove_purge(self): """ Test package removal -- 2.29.2
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor