Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/16084.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed `mount.swap` reporting "failed to activate" on every run when the swap device is given as a `UUID=`, `LABEL=`, `PARTUUID=` or `PARTLABEL=` specification, as a symlink such as `/dev/disk/by-uuid/<uuid>`, or as a device-mapper name such as `/dev/mapper/<name>`
1 change: 1 addition & 0 deletions changelog/70201.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``resolve_canonical`` argument to different functions of the ``mount`` execution and states modules, to allow the matching mechanism for the existing fstab entries to always compare using the canonical names of the devices, even if there are defined as with ``UUID`` or other labels. This prevents the creation of duplicate entries in fstab that refer to the same device.
31 changes: 26 additions & 5 deletions salt/modules/mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def norm_path(path):
"""
return os.path.normcase(os.path.normpath(path))

def match(self, line):
def match(self, line, resolve_canonical=False):
"""
Compare potentially partial criteria against line
"""
Expand All @@ -370,6 +370,11 @@ def match(self, line):
cr_opts = sorted(value.split(","))
if ex_opts != cr_opts:
return False
elif key == "device" and resolve_canonical:
if salt.utils.mount._resolve_canonical(
entry[key], __salt__
) != salt.utils.mount._resolve_canonical(value, __salt__):
return False
elif entry[key] != value:
return False
return True
Expand Down Expand Up @@ -463,7 +468,7 @@ def norm_path(path):
"""
return os.path.normcase(os.path.normpath(path))

def match(self, line):
def match(self, line, **kwargs):
"""
Compare potentially partial criteria against line
"""
Expand Down Expand Up @@ -709,12 +714,19 @@ def vfstab(config="/etc/vfstab"):
return fstab(config)


def rm_fstab(name, device, config="/etc/fstab"):
def rm_fstab(name, device, config="/etc/fstab", resolve_canonical=False):
"""
.. versionchanged:: 2016.3.2

Remove the mount point from the fstab

resolve_canonical
``UUID=``, ``LABEL=``, ``PARTUUID=`` and ``PARTLABEL=`` names are
resolved to the underlying device, so the canonical device path is
used for comparison.

.. versionadded:: 3008.3

CLI Example:

.. code-block:: bash
Expand All @@ -734,7 +746,8 @@ def rm_fstab(name, device, config="/etc/fstab"):
for line in ifile:
line = salt.utils.stringutils.to_unicode(line)
try:
if criteria.match(line):
# pylint: disable-next=too-many-function-args
if criteria.match(line, resolve_canonical):
modified = True
else:
lines.append(line)
Expand Down Expand Up @@ -788,6 +801,7 @@ def set_fstab(
test=False,
match_on="auto",
not_change=False,
resolve_canonical=False,
**kwargs,
):
"""
Expand All @@ -797,6 +811,13 @@ def set_fstab(
If the entry is found via `match_on` and `not_change` is True, the
current line will be preserved.

resolve_canonical
``UUID=``, ``LABEL=``, ``PARTUUID=`` and ``PARTLABEL=`` names are
resolved to the underlying device, so the canonical device path is
used for comparison.

.. versionadded:: 3008.3

CLI Example:

.. code-block:: bash
Expand Down Expand Up @@ -880,7 +901,7 @@ def filterFn(key):
for line in ifile:
line = salt.utils.stringutils.to_unicode(line)
try:
if criteria.match(line):
if criteria.match(line, resolve_canonical):
# Note: If ret isn't None here,
# we've matched multiple lines
ret = "present"
Expand Down
Loading
Loading