Skip to content

Commit

Permalink
Fstab support
Browse files Browse the repository at this point in the history
 - added support for blivet to directly modify fstab based
on blivet actions
 - added tests and unit tests
  • Loading branch information
japokorn committed Mar 22, 2023
1 parent 1ea8de6 commit 16e18a6
Show file tree
Hide file tree
Showing 7 changed files with 587 additions and 3 deletions.
8 changes: 7 additions & 1 deletion blivet/actionlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,13 @@ def _post_process(self, devices=None):
partition.parted_partition = pdisk.getPartitionByPath(partition.path)

@with_flag("processing")
def process(self, callbacks=None, devices=None, dry_run=None):
def process(self, callbacks=None, devices=None, fstab=None, dry_run=None):
"""
Execute all registered actions.
:param callbacks: callbacks to be invoked when actions are executed
:param devices: a list of all devices current in the devicetree
:param fstab: FSTabManagerObject tied to blivet, if None fstab file will not be modified
:type callbacks: :class:`~.callbacks.DoItCallbacks`
"""
Expand All @@ -284,6 +285,7 @@ def process(self, callbacks=None, devices=None, dry_run=None):
continue

with blivet_lock:

try:
action.execute(callbacks)
except DiskLabelCommitError:
Expand All @@ -310,6 +312,10 @@ def process(self, callbacks=None, devices=None, dry_run=None):
device.update_name()
device.format.device = device.path

if fstab is not None:
fstab.update(devices)
fstab.write()

self._completed_actions.append(self._actions.pop(0))
_callbacks.action_executed(action=action)

Expand Down
10 changes: 9 additions & 1 deletion blivet/blivet.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from .errors import StorageError, DependencyError
from .size import Size
from .devicetree import DeviceTree
from .fstab import FSTabManager
from .formats import get_default_filesystem_type
from .flags import flags
from .formats import get_format
Expand Down Expand Up @@ -71,6 +72,10 @@ def __init__(self):
self.size_sets = []
self.set_default_fstype(get_default_filesystem_type())

# fstab write location purposedly set to None. It has to be overriden
# manually when using blivet.
self.fstab = FSTabManager(src_file="/etc/fstab", dest_file=None)

self._short_product_name = 'blivet'

self._next_id = 0
Expand Down Expand Up @@ -111,7 +116,8 @@ def do_it(self, callbacks=None):
"""

self.devicetree.actions.process(callbacks=callbacks, devices=self.devices)
self.devicetree.actions.process(callbacks=callbacks, devices=self.devices, fstab=self.fstab)
self.fstab.read()

@property
def next_id(self):
Expand Down Expand Up @@ -141,6 +147,8 @@ def reset(self, cleanup_only=False):
self.edd_dict = get_edd_dict(self.partitioned)
self.devicetree.edd_dict = self.edd_dict

self.fstab.read()

if flags.include_nodev:
self.devicetree.handle_nodev_filesystems()

Expand Down
8 changes: 7 additions & 1 deletion blivet/formats/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class FS(DeviceFormat):
# value is already unpredictable and can change in the future...
_metadata_size_factor = 1.0

config_actions_map = {"label": "write_label"}
config_actions_map = {"label": "write_label",
"mountpoint": "change_mountpoint"}

def __init__(self, **kwargs):
"""
Expand Down Expand Up @@ -627,6 +628,11 @@ def _teardown(self, **kwargs):

udev.settle()

def change_mountpoint(self, dry_run=False):
# This function is intentionally left blank. Mountpoint change utilizes
# only the generic part of this code branch
pass

def read_label(self):
"""Read this filesystem's label.
Expand Down
Loading

0 comments on commit 16e18a6

Please sign in to comment.