Don't try to chown if the user salt does not exist

This commit is contained in:
Pedro Algarvio 2024-05-08 22:10:39 +01:00
parent 036f2c3f58
commit 857dbeba1d

View file

@ -476,13 +476,21 @@ def salt_minion(salt_factories, salt_master, install_salt):
# which sets root perms on /srv/salt and /srv/pillar since we are running
# the test suite as root, but we want to run Salt master as salt
if not platform.is_windows() and not platform.is_darwin():
state_tree = "/srv/salt"
pillar_tree = "/srv/pillar"
check_paths = [state_tree, pillar_tree, CODE_DIR / ".nox"]
for path in check_paths:
if os.path.exists(path) is False:
continue
subprocess.run(["chown", "-R", "salt:salt", str(path)], check=False)
import pwd
try:
pwd.getpwnam("salt")
except KeyError:
# The salt user does not exist
pass
else:
state_tree = "/srv/salt"
pillar_tree = "/srv/pillar"
check_paths = [state_tree, pillar_tree, CODE_DIR / ".nox"]
for path in check_paths:
if os.path.exists(path) is False:
continue
subprocess.run(["chown", "-R", "salt:salt", str(path)], check=False)
factory.after_terminate(
pytest.helpers.remove_stale_minion_key, salt_master, factory.id