Skip to content

Commit

Permalink
Merge pull request #1263 from japokorn/3.10-devel-fstab_devicetree_fix
Browse files Browse the repository at this point in the history
blivet fstab method change
  • Loading branch information
vojtechtrefny authored Jul 30, 2024
2 parents 4fdf560 + f62e0c9 commit d41a0ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions blivet/fstab.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,12 @@ def read(self):

self._table.parse_fstab(self.src_file)

def find_device(self, blivet, spec=None, mntops=None, blkid_tab=None, crypt_tab=None, *, entry=None):
def find_device(self, devicetree, spec=None, mntops=None, blkid_tab=None, crypt_tab=None, *, entry=None):
""" Find a blivet device, based on spec or entry. Mount options can be used to refine the search.
If both entry and spec/mntops are given, spec/mntops are prioritized over entry values.
:param blivet: Blivet instance with populated devicetree
:type blivet: :class: `Blivet`
:param devicetree: populated blivet.Devicetree instance
:type devicetree: :class: `blivet.Devicetree`
:keyword spec: searched device specs (see man fstab(5) fs_spec)
:type spec: str
:keyword mntops: list of mount option strings (see man fstab(5) fs_mntops)
Expand All @@ -488,16 +488,16 @@ def find_device(self, blivet, spec=None, mntops=None, blkid_tab=None, crypt_tab=
_mntops = mntops or (entry.mntops if entry is not None else None)
_mntops_str = ",".join(_mntops) if mntops is not None else None

return blivet.devicetree.resolve_device(_spec, options=_mntops_str, blkid_tab=blkid_tab, crypt_tab=crypt_tab)
return devicetree.resolve_device(_spec, options=_mntops_str, blkid_tab=blkid_tab, crypt_tab=crypt_tab)

def get_device(self, blivet, spec=None, file=None, vfstype=None,
def get_device(self, devicetree, spec=None, file=None, vfstype=None,
mntops=None, blkid_tab=None, crypt_tab=None, *, entry=None):
""" Parse an fstab entry for a device and return the corresponding device from the devicetree.
If not found, try to create a new device based on given values.
Raises UnrecognizedFSTabError in case of invalid or incomplete data.
:param blivet: Blivet instance with populated devicetree
:type blivet: :class: `Blivet`
:param devicetree: populated blivet.Devicetree instance
:type devicetree: :class: `blivet.Devicetree`
:keyword spec: searched device specs (see man fstab(5) fs_spec)
:type spec: str
:keyword mntops: list of mount option strings (see man fstab(5) fs_mntops)
Expand All @@ -521,21 +521,21 @@ def get_device(self, blivet, spec=None, file=None, vfstype=None,
_mntops_str = ",".join(_mntops) if mntops is not None else None

# find device in the tree
device = blivet.devicetree.resolve_device(_spec, options=_mntops_str, blkid_tab=blkid_tab, crypt_tab=crypt_tab)
device = devicetree.resolve_device(_spec, options=_mntops_str, blkid_tab=blkid_tab, crypt_tab=crypt_tab)

if device is None:
if vfstype == "swap":
# swap file
device = FileDevice(_spec,
parents=blivet.devicetree.resolve_device(_spec),
parents=devicetree.resolve_device(_spec),
fmt=get_format(vfstype, device=_spec, exists=True),
exists=True)
elif vfstype == "bind" or (_mntops is not None and "bind" in _mntops):
# bind mount... set vfstype so later comparison won't
# turn up false positives
vfstype = "bind"

parents = blivet.devicetree.resolve_device(_spec)
parents = devicetree.resolve_device(_spec)
device = DirectoryDevice(_spec, parents=parents, exists=True)
device.format = get_format("bind", device=device.path, exists=True)

Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/fstab_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def test_find_device(self):
dev1.format.mountpoint = "/mnt/mountpath"
b.devicetree._add_device(dev1)

dev2 = self.fstab.find_device(b, "/dev/sda_dummy")
dev2 = self.fstab.find_device(b.devicetree, "/dev/sda_dummy")

self.assertEqual(dev1, dev2)

Expand All @@ -190,6 +190,6 @@ def test_get_device(self):
dev1.format.mountpoint = "/mnt/mountpath"
b.devicetree._add_device(dev1)

dev2 = self.fstab.get_device(b, "/dev/sda_dummy", "/mnt/mountpath", "xfs", ["defaults"])
dev2 = self.fstab.get_device(b.devicetree, "/dev/sda_dummy", "/mnt/mountpath", "xfs", ["defaults"])

self.assertEqual(dev1, dev2)

0 comments on commit d41a0ce

Please sign in to comment.