File accumulated-changes-required-for-yomi-165.patch of Package salt

From 7d35fdba84b6e1b62a3abc71e518366a35efb662 Mon Sep 17 00:00:00 2001
From: Alberto Planas <>
Date: Tue, 30 Jul 2019 11:23:12 +0200
Subject: [PATCH] Accumulated changes required for Yomi (#165)

* cmdmod: fix runas and group in run_chroot

The parameters runas and group for will change the efective
user and group before executing the command. But in a chroot environment is
expected that the change happends inside the chroot, not outside, as the
user and groups are refering to objects that can only exist inside the

This patch add the userspec parameter to the chroot command, to change
the user in the correct place.

(cherry picked from commit f0434aaeeee3ace4e3fc65c04e69984f08b2541e)

* chroot: add missing sys directory

(cherry picked from commit cdf74426bcad4e8bf329bf604c77ea83bfca8b2c)

* chroot: change variable name to root

(cherry picked from commit 7f68b65b1b0f9eec2a6b07b02714ead0121f0e4b)

* chroot: fix bug in safe_kwargs iteration

(cherry picked from commit 39da1c69ea2781bed6e9d8e6879b70d65fa5a5b0)

* test_cmdmod: fix test_run_cwd_in_combination_with_runas

(cherry picked from commit 42640ecf161caf64c61e9b02927882f92c850092)

* test_cmdmod: add test_run_chroot_runas test

(cherry picked from commit d900035089a22f6741d2095fd1f6694597041a88)

* freezer: do not fail in cache dir is present

(cherry picked from commit 25137c51e6d6e53e3099b6cddbf51d4cb2c53d8d)

* freezer: clean freeze YAML profile on restore

(cherry picked from commit 56b97c997257f12038399549dc987b7723ab225f)

* zypperpkg: fix pkg.list_pkgs cache

The cache from pkg.list_pkgs for the zypper installer is too aggresive.
Some parameters will deliver different package lists, like root and
includes. The current cache do not take those parameters into
consideration, so the next time that this function is called, the last
list of packages will be returned, without checking if the current
parameters match the old one.

This patch create a different cache key for each parameter combination,
so the cached data will be separated too.

(cherry picked from commit 9c54bb3e8c93ba21fc583bdefbcadbe53cbcd7b5)
 salt/modules/            |  1 -
 tests/unit/modules/ | 22 +++++++++++++++++++++-
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/salt/modules/ b/salt/modules/
index c996935bff..b099f3e5d7 100644
--- a/salt/modules/
+++ b/salt/modules/
@@ -879,7 +879,6 @@ def list_pkgs(versions_as_list=False, root=None, includes=None, **kwargs):
     # inclusion types are passed
     contextkey = "pkg.list_pkgs_{}_{}".format(root, includes)
-    # TODO(aplanas): this cached value depends on the parameters
     if contextkey not in __context__:
         ret = {}
         cmd = ["rpm"]
diff --git a/tests/unit/modules/ b/tests/unit/modules/
index 032785395e..5d4e7766b6 100644
--- a/tests/unit/modules/
+++ b/tests/unit/modules/
@@ -912,7 +912,8 @@ Repository 'DUMMY' not found by its alias, number, or URI.
         ), patch.dict(
             zypper.__salt__, {"pkg_resource.stringify": MagicMock()}
         ), patch.dict(
-            pkg_resource.__salt__, {"pkg.parse_arch": zypper.parse_arch}
+            pkg_resource.__salt__,
+            {"pkg.parse_arch_from_name": zypper.parse_arch_from_name},
             pkgs = zypper.list_pkgs(
                 attr=["epoch", "release", "arch", "install_date_time_t"]
@@ -1950,3 +1951,22 @@ pattern() = package-c"""
             "package-a": {"installed": True, "summary": "description a",},
             "package-b": {"installed": False, "summary": "description b",},
+    def test__clean_cache_empty(self):
+        """Test that an empty cached can be cleaned"""
+        context = {}
+        with patch.dict(zypper.__context__, context):
+            zypper._clean_cache()
+            assert context == {}
+    def test__clean_cache_filled(self):
+        """Test that a filled cached can be cleaned"""
+        context = {
+            "pkg.list_pkgs_/mnt_[]": None,
+            "pkg.list_pkgs_/mnt_[patterns]": None,
+            "pkg.list_provides": None,
+            "pkg.other_data": None,
+        }
+        with patch.dict(zypper.__context__, context):
+            zypper._clean_cache()
+            self.assertEqual(zypper.__context__, {"pkg.other_data": None})
openSUSE Build Service is sponsored by