From e5d1e4db9dfffc2c91719ae7b72b4c48b97ad449 Mon Sep 17 00:00:00 2001 From: Shane Lee Date: Wed, 27 Mar 2024 12:09:19 -0600 Subject: [PATCH] Keep directory structure the same on Master and Masterless Fixes winrepo.update_git_repos so that the directory structure is the same whether run on the master or on a minion using salt-call. --- salt/utils/gitfs.py | 2 +- .../functional/runners/test_winrepo.py | 41 ++++++++++++------- tests/pytests/unit/utils/test_gitfs.py | 2 +- tests/unit/utils/test_gitfs.py | 4 +- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/salt/utils/gitfs.py b/salt/utils/gitfs.py index aa9190b6ee3..e6924ae6f70 100644 --- a/salt/utils/gitfs.py +++ b/salt/utils/gitfs.py @@ -472,7 +472,7 @@ class GitProvider: "/", "_" ) # replace "/" with "_" to not cause trouble with file system self._cache_hash = salt.utils.path.join(cache_root, self._cache_basehash) - self._cache_basename = "_" + self._cache_basename = "" if self.id.startswith("__env__"): try: self._cache_basename = self.get_checkout_target() diff --git a/tests/pytests/functional/runners/test_winrepo.py b/tests/pytests/functional/runners/test_winrepo.py index b22764fbe4d..65d54df62ec 100644 --- a/tests/pytests/functional/runners/test_winrepo.py +++ b/tests/pytests/functional/runners/test_winrepo.py @@ -1,3 +1,5 @@ +import os + import pytest from salt.runners import winrepo @@ -10,27 +12,21 @@ pytestmark = [ @pytest.fixture def configure_loader_modules(minion_opts, tmp_path): - opts = minion_opts.copy() winrepo_dir = tmp_path / "winrepo" winrepo_dir.mkdir() winrepo_dir_ng = tmp_path / "winrepo_ng" winrepo_dir_ng.mkdir() - opts["winrepo_dir"] = str(winrepo_dir) - opts["winrepo_dir_ng"] = str(winrepo_dir_ng) - - return { - winrepo: { - "__opts__": opts, - } - } + minion_opts["winrepo_dir"] = str(winrepo_dir) + minion_opts["winrepo_dir_ng"] = str(winrepo_dir_ng) + return {winrepo: {"__opts__": minion_opts}} @pytest.fixture def winrepo_remotes(minion_opts): - winrepo_remotes = minion_opts.get("winrepo_remotes", []) - winrepo_remotes_ng = minion_opts.get("winrepo_remotes_ng", []) - winrepo_remotes.extend(winrepo_remotes_ng) - return winrepo_remotes + remotes = set() + remotes.update(minion_opts.get("winrepo_remotes", [])) + remotes.update(minion_opts.get("winrepo_remotes_ng", [])) + return remotes def test_update_git_repos(winrepo_remotes): @@ -38,15 +34,18 @@ def test_update_git_repos(winrepo_remotes): Ensure update git repos works as intended. """ res = winrepo.update_git_repos() - assert res for remote in winrepo_remotes: assert remote in res assert res[remote] + # Make sure there are package definitions in the root + pkg_def = os.path.join(res[remote], "7zip.sls") + assert os.path.exists(pkg_def) -def test_legacy_update_git_repos(winrepo_remotes): + +def test_legacy_update_git_repos(winrepo_remotes, minion_opts): """ Ensure update git repos works as intended with legacy (non-gitfs) code. """ @@ -58,3 +57,15 @@ def test_legacy_update_git_repos(winrepo_remotes): for remote in winrepo_remotes: assert remote in res assert res[remote] + + # Make sure there are package definitions in the root + # We have to look up the actual repo dir here because the legacy + # update only returns True or False, not a path + if "-ng" in remote: + path = minion_opts["winrepo_dir_ng"] + pkg_def = os.path.join(path, "salt-winrepo-ng", "7zip.sls") + else: + path = minion_opts["winrepo_dir"] + pkg_def = os.path.join(path, "salt-winrepo", "7zip.sls") + + assert os.path.exists(pkg_def) diff --git a/tests/pytests/unit/utils/test_gitfs.py b/tests/pytests/unit/utils/test_gitfs.py index 4b0c11afd60..91d5a392feb 100644 --- a/tests/pytests/unit/utils/test_gitfs.py +++ b/tests/pytests/unit/utils/test_gitfs.py @@ -248,4 +248,4 @@ def test_checkout_pygit2(_prepare_provider): reason="Skip Pygit2 on windows, due to pygit2 access error on windows" ) def test_get_cachedir_basename_pygit2(_prepare_provider): - assert "_" == _prepare_provider.get_cache_basename() + assert "" == _prepare_provider.get_cache_basename() diff --git a/tests/unit/utils/test_gitfs.py b/tests/unit/utils/test_gitfs.py index e72f94050c8..95994d6e6b4 100644 --- a/tests/unit/utils/test_gitfs.py +++ b/tests/unit/utils/test_gitfs.py @@ -117,11 +117,11 @@ class TestGitBase(TestCase, AdaptedConfigurationTestCaseMixin): def test_get_cachedir_basename(self): self.assertEqual( self.main_class.remotes[0].get_cache_basename(), - "_", + "", ) self.assertEqual( self.main_class.remotes[1].get_cache_basename(), - "_", + "", ) def test_git_provider_mp_lock(self):