Skip to content

Commit

Permalink
fstab: Use 'mount_type' when writing filesystem type to fstab
Browse files Browse the repository at this point in the history
FOr some formats the 'type' value is not valid for mounting/fstab,
for example for Stratis devices we internally use 'stratis xfs'
but we need to use 'xfs' for mounting and fstab.
  • Loading branch information
vojtechtrefny committed Apr 3, 2024
1 parent 3993194 commit 9bece1f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
11 changes: 9 additions & 2 deletions blivet/fstab.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,11 @@ def entry_from_device(self, device):
entry.spec = self._get_spec(device)
if entry.spec is None:
entry.spec = getattr(device, "fstab_spec", None)
entry.vfstype = device.format.type

if hasattr(device.format, "mount_type") and device.format.mount_type is not None:
entry.vfstype = device.format.mount_type
else:
entry.vfstype = device.format.type

return entry

Expand Down Expand Up @@ -434,7 +438,10 @@ def entry_from_action(self, action):
if entry.spec is None:
entry.spec = getattr(action.device, "fstab_spec", None)

entry.vfstype = action.device.format.type
if hasattr(action.device.format, "mount_type") and action.device.format.mount_type is not None:
entry.vfstype = action.device.format.mount_type
else:
entry.vfstype = action.device.format.type

return entry

Expand Down
12 changes: 11 additions & 1 deletion tests/unit_tests/fstab_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import copy

from blivet.fstab import FSTabManager, FSTabEntry, HAVE_LIBMOUNT
from blivet.devices import DiskDevice
from blivet.devices import DiskDevice, StratisPoolDevice, StratisFilesystemDevice
from blivet.formats import get_format
from blivet.size import Size
from blivet import Blivet

FSTAB_WRITE_FILE = "/tmp/test-blivet-fstab2"
Expand Down Expand Up @@ -100,6 +101,15 @@ def test_entry_from_device(self):
_entry = self.fstab.entry_from_device(device)
self.assertEqual(_entry, FSTabEntry('/dev/test_device', '/media/fstab_test', 'ext4', None, 0, 0))

def test_entry_from_device_stratis(self):
pool = StratisPoolDevice("testpool", parents=[], exists=True)
device = StratisFilesystemDevice("testfs", parents=[pool], size=Size("1 GiB"), exists=True)
device.format = get_format("stratis xfs")
device.format.mountpoint = "/media/fstab_test"

_entry = self.fstab.entry_from_device(device)
self.assertEqual(_entry, FSTabEntry('/dev/stratis/testpool/testfs', '/media/fstab_test', 'xfs', None, 0, 0))

def test_update(self):

# Reset table
Expand Down

0 comments on commit 9bece1f

Please sign in to comment.