Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix order specific mount.mounted options for persist #62557

Merged
merged 9 commits into from
Sep 14, 2022
1 change: 1 addition & 0 deletions changelog/62556.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix order specific mount.mounted options for persist
24 changes: 21 additions & 3 deletions salt/modules/mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,12 @@ def match(self, line):
"""
entry = self.dict_from_line(line)
for key, value in self.criteria.items():
if entry[key] != value:
if key == "opts":
ex_opts = sorted(entry.get(key, "").split(","))
cr_opts = sorted(value.split(","))
if ex_opts != cr_opts:
return False
elif entry[key] != value:
return False
return True

Expand Down Expand Up @@ -467,7 +472,12 @@ def match(self, line):
"""
entry = self.dict_from_line(line)
for key, value in self.criteria.items():
if entry[key] != value:
if key == "opts":
ex_opts = sorted(entry.get(key, "").split(","))
cr_opts = sorted(value.split(","))
if ex_opts != cr_opts:
return False
elif entry[key] != value:
return False
return True

Expand Down Expand Up @@ -628,7 +638,12 @@ def match(self, fsys_view):
evalue_dict = fsys_view[1]
for key, value in self.criteria.items():
if key in evalue_dict:
if evalue_dict[key] != value:
if key == "opts":
ex_opts = sorted(evalue_dict.get(key, "").split(","))
cr_opts = sorted(value.split(","))
if ex_opts != cr_opts:
return False
elif evalue_dict[key] != value:
return False
else:
return False
Expand Down Expand Up @@ -867,6 +882,9 @@ def set_fstab(
line = salt.utils.stringutils.to_unicode(line)
try:
if criteria.match(line):
log.debug(
"Checking ( %s ) against current line ( %s )", entry, line
nicholasmhughes marked this conversation as resolved.
Show resolved Hide resolved
)
# Note: If ret isn't None here,
# we've matched multiple lines
ret = "present"
Expand Down
4 changes: 0 additions & 4 deletions salt/states/mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ def mounted(
# string
if isinstance(opts, str):
opts = opts.split(",")
if opts:
opts.sort()

if isinstance(hidden_opts, str):
hidden_opts = hidden_opts.split(",")
Expand Down Expand Up @@ -345,8 +343,6 @@ def mounted(
if label_device and label_device not in device_list:
device_list.append(label_device)
if opts:
opts.sort()

mount_invisible_options = [
"_netdev",
"actimeo",
Expand Down
12 changes: 12 additions & 0 deletions tests/pytests/unit/modules/test_mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ def test_active():
assert mount.active() == {}


def test_fstab_entry_ignores_opt_ordering():
entry = mount._fstab_entry(
name="/tmp",
device="tmpfs",
fstype="tmpfs",
opts="defaults,nodev,noexec",
dump=0,
pass_num=0,
)
assert entry.match("tmpfs\t\t/tmp\ttmpfs\tnodev,defaults,noexec\t0 0\n")


def test_fstab():
"""
List the content of the fstab
Expand Down
4 changes: 2 additions & 2 deletions tests/pytests/unit/states/test_mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,12 @@ def test_mounted():
)
== ret
)
# Test to check the options order #57520
# Test to check the options order #57520, reverted in #62557
set_fstab_mock.assert_called_with(
name2,
"//SERVER/SHARE/",
"cifs",
["gid=group1", "uid=user1"],
["uid=user1", "gid=group1"],
0,
0,
"/etc/fstab",
Expand Down