2021-01-08 13:41:50 +01:00
|
|
|
From 4123cf7b9428af1442f4aa0a54489e5c0deb4aaa Mon Sep 17 00:00:00 2001
|
2020-11-04 11:58:48 +01:00
|
|
|
From: Martin Seidl <mseidl@suse.de>
|
|
|
|
Date: Tue, 27 Oct 2020 16:12:29 +0100
|
|
|
|
Subject: [PATCH] Fix novendorchange option (#284)
|
|
|
|
|
|
|
|
* Fixed novendorchange handling in zypperpkg
|
|
|
|
|
|
|
|
* refactor handling of novendorchange and fix tests
|
|
|
|
---
|
2021-01-08 13:41:50 +01:00
|
|
|
salt/modules/zypperpkg.py | 21 +++---
|
|
|
|
tests/unit/modules/test_zypperpkg.py | 100 ++++++++++++++++++++++++++-
|
|
|
|
2 files changed, 108 insertions(+), 13 deletions(-)
|
2020-11-04 11:58:48 +01:00
|
|
|
|
|
|
|
diff --git a/salt/modules/zypperpkg.py b/salt/modules/zypperpkg.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index 5369a0342e..d06c265202 100644
|
2020-11-04 11:58:48 +01:00
|
|
|
--- a/salt/modules/zypperpkg.py
|
|
|
|
+++ b/salt/modules/zypperpkg.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -1707,7 +1707,7 @@ def upgrade(
|
|
|
|
dryrun=False,
|
|
|
|
dist_upgrade=False,
|
|
|
|
fromrepo=None,
|
|
|
|
- novendorchange=False,
|
|
|
|
+ novendorchange=True,
|
|
|
|
skip_verify=False,
|
|
|
|
no_recommends=False,
|
|
|
|
root=None,
|
|
|
|
@@ -1794,19 +1794,18 @@ def upgrade(
|
|
|
|
log.info("Targeting repos: %s", fromrepo)
|
2020-11-04 11:58:48 +01:00
|
|
|
|
|
|
|
if dist_upgrade:
|
|
|
|
- if novendorchange:
|
|
|
|
- # TODO: Grains validation should be moved to Zypper class
|
2021-01-08 13:41:50 +01:00
|
|
|
- if __grains__["osrelease_info"][0] > 11:
|
2020-11-04 11:58:48 +01:00
|
|
|
+ # TODO: Grains validation should be moved to Zypper class
|
|
|
|
+ if __grains__["osrelease_info"][0] > 11:
|
|
|
|
+ if novendorchange:
|
2021-01-08 13:41:50 +01:00
|
|
|
cmd_update.append("--no-allow-vendor-change")
|
|
|
|
log.info("Disabling vendor changes")
|
2020-11-04 11:58:48 +01:00
|
|
|
else:
|
2021-01-08 13:41:50 +01:00
|
|
|
- log.warning(
|
|
|
|
- "Disabling vendor changes is not supported on this Zypper version"
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
- if no_recommends:
|
|
|
|
- cmd_update.append("--no-recommends")
|
|
|
|
- log.info("Disabling recommendations")
|
2020-11-04 11:58:48 +01:00
|
|
|
+ cmd_update.append("--allow-vendor-change")
|
|
|
|
+ log.info("Enabling vendor changes")
|
|
|
|
+ else:
|
|
|
|
+ log.warning(
|
|
|
|
+ "Enabling/Disabling vendor changes is not supported on this Zypper version"
|
|
|
|
+ )
|
|
|
|
|
|
|
|
if no_recommends:
|
2021-01-08 13:41:50 +01:00
|
|
|
cmd_update.append("--no-recommends")
|
2020-11-04 11:58:48 +01: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 a60b1546c6..eaa4d9a76a 100644
|
2020-11-04 11:58:48 +01:00
|
|
|
--- a/tests/unit/modules/test_zypperpkg.py
|
|
|
|
+++ b/tests/unit/modules/test_zypperpkg.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -642,7 +642,9 @@ class ZypperTestCase(TestCase, LoaderModuleMockMixin):
|
2020-11-04 11:58:48 +01:00
|
|
|
ret = zypper.upgrade(dist_upgrade=True)
|
|
|
|
self.assertDictEqual(ret, {"vim": {"old": "1.1", "new": "1.2"}})
|
2021-01-08 13:41:50 +01:00
|
|
|
zypper_mock.assert_any_call(
|
|
|
|
- "dist-upgrade", "--auto-agree-with-licenses"
|
2020-11-04 11:58:48 +01:00
|
|
|
+ "dist-upgrade",
|
|
|
|
+ "--auto-agree-with-licenses",
|
|
|
|
+ "--no-allow-vendor-change",
|
2021-01-08 13:41:50 +01:00
|
|
|
)
|
2020-11-04 11:58:48 +01:00
|
|
|
|
2021-01-08 13:41:50 +01:00
|
|
|
with patch(
|
|
|
|
@@ -660,6 +662,76 @@ class ZypperTestCase(TestCase, LoaderModuleMockMixin):
|
|
|
|
"--debug-solver",
|
|
|
|
)
|
2020-11-04 11:58:48 +01:00
|
|
|
|
2021-01-08 13:41:50 +01:00
|
|
|
+ with patch(
|
|
|
|
+ "salt.modules.zypperpkg.list_pkgs",
|
|
|
|
+ MagicMock(side_effect=[{"vim": "1.1"}, {"vim": "1.1"}]),
|
|
|
|
+ ):
|
|
|
|
+ ret = zypper.upgrade(
|
|
|
|
+ dist_upgrade=False, fromrepo=["Dummy", "Dummy2"], dryrun=False
|
2020-11-04 11:58:48 +01:00
|
|
|
+ )
|
|
|
|
+ zypper_mock.assert_any_call(
|
2021-01-08 13:41:50 +01:00
|
|
|
+ "update",
|
2020-11-04 11:58:48 +01:00
|
|
|
+ "--auto-agree-with-licenses",
|
2021-01-08 13:41:50 +01:00
|
|
|
+ "--repo",
|
|
|
|
+ "Dummy",
|
|
|
|
+ "--repo",
|
|
|
|
+ "Dummy2",
|
2020-11-04 11:58:48 +01:00
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ with patch(
|
|
|
|
+ "salt.modules.zypperpkg.list_pkgs",
|
2021-01-08 13:41:50 +01:00
|
|
|
+ MagicMock(side_effect=[{"vim": "1.1"}, {"vim": "1.2"}]),
|
2020-11-04 11:58:48 +01:00
|
|
|
+ ):
|
|
|
|
+ ret = zypper.upgrade(
|
|
|
|
+ dist_upgrade=True,
|
|
|
|
+ fromrepo=["Dummy", "Dummy2"],
|
2021-01-08 13:41:50 +01:00
|
|
|
+ novendorchange=True,
|
2020-11-04 11:58:48 +01:00
|
|
|
+ )
|
|
|
|
+ zypper_mock.assert_any_call(
|
|
|
|
+ "dist-upgrade",
|
|
|
|
+ "--auto-agree-with-licenses",
|
|
|
|
+ "--dry-run",
|
2021-01-08 13:41:50 +01:00
|
|
|
+ "--no-allow-vendor-change",
|
2020-11-04 11:58:48 +01:00
|
|
|
+ )
|
|
|
|
+ zypper_mock.assert_any_call(
|
|
|
|
+ "dist-upgrade",
|
|
|
|
+ "--auto-agree-with-licenses",
|
|
|
|
+ "--dry-run",
|
2021-01-08 13:41:50 +01:00
|
|
|
+ "--no-allow-vendor-change",
|
2020-11-04 11:58:48 +01:00
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ with patch(
|
|
|
|
+ "salt.modules.zypperpkg.list_pkgs",
|
|
|
|
+ MagicMock(side_effect=[{"vim": "1.1"}, {"vim": "1.1"}]),
|
|
|
|
+ ):
|
|
|
|
+ ret = zypper.upgrade(
|
|
|
|
+ dist_upgrade=True,
|
|
|
|
+ dryrun=True,
|
|
|
|
+ fromrepo=["Dummy", "Dummy2"],
|
2021-01-08 13:41:50 +01:00
|
|
|
+ novendorchange=False,
|
2020-11-04 11:58:48 +01:00
|
|
|
+ )
|
|
|
|
+ zypper_mock.assert_any_call(
|
|
|
|
+ "dist-upgrade",
|
|
|
|
+ "--auto-agree-with-licenses",
|
|
|
|
+ "--dry-run",
|
|
|
|
+ "--from",
|
|
|
|
+ "Dummy",
|
|
|
|
+ "--from",
|
|
|
|
+ "Dummy2",
|
2021-01-08 13:41:50 +01:00
|
|
|
+ "--allow-vendor-change",
|
2020-11-04 11:58:48 +01:00
|
|
|
+ )
|
|
|
|
+ zypper_mock.assert_any_call(
|
|
|
|
+ "dist-upgrade",
|
|
|
|
+ "--auto-agree-with-licenses",
|
|
|
|
+ "--dry-run",
|
|
|
|
+ "--from",
|
|
|
|
+ "Dummy",
|
|
|
|
+ "--from",
|
|
|
|
+ "Dummy2",
|
2021-01-08 13:41:50 +01:00
|
|
|
+ "--allow-vendor-change",
|
2020-11-04 11:58:48 +01:00
|
|
|
+ "--debug-solver",
|
|
|
|
+ )
|
|
|
|
+
|
2021-01-08 13:41:50 +01:00
|
|
|
with patch(
|
|
|
|
"salt.modules.zypperpkg.list_pkgs",
|
|
|
|
MagicMock(side_effect=[{"vim": "1.1"}, {"vim": "1.1"}]),
|
|
|
|
@@ -728,6 +800,26 @@ class ZypperTestCase(TestCase, LoaderModuleMockMixin):
|
|
|
|
"--no-allow-vendor-change",
|
|
|
|
)
|
2020-11-04 11:58:48 +01:00
|
|
|
|
|
|
|
+ with patch(
|
|
|
|
+ "salt.modules.zypperpkg.list_pkgs",
|
|
|
|
+ MagicMock(side_effect=[{"vim": "1.1"}, {"vim": "1.2"}]),
|
|
|
|
+ ):
|
|
|
|
+ ret = zypper.upgrade(
|
|
|
|
+ dist_upgrade=True,
|
|
|
|
+ fromrepo=["Dummy", "Dummy2"],
|
|
|
|
+ novendorchange=False,
|
|
|
|
+ )
|
|
|
|
+ self.assertDictEqual(ret, {"vim": {"old": "1.1", "new": "1.2"}})
|
|
|
|
+ zypper_mock.assert_any_call(
|
|
|
|
+ "dist-upgrade",
|
|
|
|
+ "--auto-agree-with-licenses",
|
|
|
|
+ "--from",
|
|
|
|
+ "Dummy",
|
|
|
|
+ "--from",
|
|
|
|
+ "Dummy2",
|
|
|
|
+ "--allow-vendor-change",
|
|
|
|
+ )
|
2021-01-08 13:41:50 +01:00
|
|
|
+
|
2020-11-04 11:58:48 +01:00
|
|
|
def test_upgrade_kernel(self):
|
2021-01-08 13:41:50 +01:00
|
|
|
"""
|
2020-11-04 11:58:48 +01:00
|
|
|
Test kernel package upgrade success.
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -815,7 +907,11 @@ Repository 'DUMMY' not found by its alias, number, or URI.
|
|
|
|
self.assertEqual(cmd_exc.exception.info["changes"], {})
|
|
|
|
self.assertEqual(cmd_exc.exception.info["result"]["stdout"], zypper_out)
|
|
|
|
zypper_mock.noraise.call.assert_called_with(
|
|
|
|
- "dist-upgrade", "--auto-agree-with-licenses", "--from", "DUMMY"
|
2020-11-04 11:58:48 +01:00
|
|
|
+ "dist-upgrade",
|
|
|
|
+ "--auto-agree-with-licenses",
|
|
|
|
+ "--from",
|
|
|
|
+ "DUMMY",
|
|
|
|
+ "--no-allow-vendor-change",
|
2021-01-08 13:41:50 +01:00
|
|
|
)
|
2020-11-04 11:58:48 +01:00
|
|
|
|
|
|
|
def test_upgrade_available(self):
|
|
|
|
--
|
2021-01-08 13:41:50 +01:00
|
|
|
2.29.2
|
2020-11-04 11:58:48 +01:00
|
|
|
|
|
|
|
|