Fix cloud config root_dir paths on windows

This commit is contained in:
Daniel A. Wozniak 2024-06-22 10:00:09 -07:00 committed by Daniel Wozniak
parent 57d2becb8f
commit 9bfe7cf898
3 changed files with 26 additions and 4 deletions

View file

@ -2215,6 +2215,13 @@ def include_config(include, orig_path, verbose, exit_on_config_errors=False):
return configuration
def should_prepend_root_dir(key, opts):
return (
key in opts
and urllib.parse.urlparse(os.path.splitdrive(opts[key])[1]).scheme == ""
)
def prepend_root_dir(opts, path_options):
"""
Prepends the options that represent filesystem paths with value of the
@ -2764,7 +2771,7 @@ def cloud_config(
# prepend root_dir
prepend_root_dirs = ["cachedir"]
if "log_file" in opts and urllib.parse.urlparse(opts["log_file"]).scheme == "":
if should_prepend_root_dir("log_file", opts):
prepend_root_dirs.append("log_file")
prepend_root_dir(opts, prepend_root_dirs)

View file

@ -27,7 +27,7 @@ def test_minion_config_type_check(caplog):
os.remove(path)
def test_cloud_config_relative_logfile(tmp_path):
def test_cloud_config_relative_log_file(tmp_path):
root_path = tmp_path
config_path = tmp_path / "conf"
config_path.mkdir()
@ -38,3 +38,16 @@ def test_cloud_config_relative_logfile(tmp_path):
master_config.write_text(f"root_dir: {root_path}")
opts = salt.config.cloud_config(cloud_config)
assert opts["log_file"] == str(root_path / "var" / "log" / "salt" / "cloud")
def test_cloud_config_relative_cachedir(tmp_path):
root_path = tmp_path
config_path = tmp_path / "conf"
config_path.mkdir()
cloud_config = config_path / "cloud"
cloud_config.write_text("")
master_config = config_path / "master"
master_config = config_path / "master"
master_config.write_text(f"root_dir: {root_path}")
opts = salt.config.cloud_config(cloud_config)
assert opts["cachedir"] == str(root_path / "var" / "cache" / "salt" / "cloud")

View file

@ -5,9 +5,10 @@ tests.pytests.unit.test_config
Unit tests for salt's config modulet
"""
import sys
import pathlib
import salt.config
import salt.syspaths
def test_call_id_function(tmp_path):
@ -29,7 +30,8 @@ def test_prepend_root_dir(tmp_path):
root = tmp_path / "root"
opts = {
"root_dir": root,
"foo": "c:\\var\\foo" if sys.platform == "win32" else "/var/foo",
"foo": str(pathlib.Path(salt.syspaths.ROOT_DIR) / "var" / "foo"),
}
salt.config.prepend_root_dir(opts, ["foo"])
print(f"after {opts['foo']}")
assert opts["foo"] == str(root / "var" / "foo")