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

blivet fstab method change #1263

Merged
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
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)