Skip to content

Commit

Permalink
Merge pull request #1166 from japokorn/3.9-devel-fstab_swap_fix
Browse files Browse the repository at this point in the history
 Added missing fstab object to SwapSpace
  • Loading branch information
vojtechtrefny authored Nov 6, 2023
2 parents a40a3ad + 179381c commit b9c683a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
6 changes: 4 additions & 2 deletions blivet/actionlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,16 @@ def process(self, callbacks=None, devices=None, fstab=None, dry_run=None):
devices = devices or []
self._pre_process(devices=devices)

skip_fstab = fstab is None or fstab.dest_file is None

for action in self._actions[:]:
log.info("executing action: %s", action)
if dry_run:
continue

# get (b)efore (a)ction.(e)xecute fstab entry
# (device may not exist afterwards)
if fstab is not None:
if not skip_fstab:
try:
entry = fstab.entry_from_device(action.device)
except ValueError:
Expand Down Expand Up @@ -328,7 +330,7 @@ def process(self, callbacks=None, devices=None, fstab=None, dry_run=None):
self._completed_actions.append(self._actions.pop(0))
_callbacks.action_executed(action=action)

if fstab is not None:
if not skip_fstab:
fstab.update(action, bae_entry)
fstab.write()

Expand Down
3 changes: 3 additions & 0 deletions blivet/formats/swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from parted import PARTITION_SWAP, fileSystemType
from ..errors import FSWriteUUIDError, SwapSpaceError
from ..fstab import FSTabOptions
from ..storage_log import log_method_call
from ..tasks import availability
from ..tasks import fsuuid
Expand Down Expand Up @@ -78,6 +79,8 @@ def __init__(self, **kwargs):
log_method_call(self, **kwargs)
DeviceFormat.__init__(self, **kwargs)

self.fstab = FSTabOptions()

self.priority = kwargs.get("priority", -1)
self.label = kwargs.get("label")

Expand Down
2 changes: 1 addition & 1 deletion blivet/fstab.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ def write(self, dest_file=None):
new_entry = self._copy_fs_entry(entry)
clean_table.add_fs(new_entry)
else:
log.warning("Fstab entry: '%s' is not complete, it will not be written into the file", entry)
log.warning("Fstab entry: '%s' is incomplete, it will not be written into the file", entry)
entry = self._table.next_fs()

if os.path.exists(dest_file):
Expand Down
19 changes: 19 additions & 0 deletions tests/storage_tests/fstab_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,22 @@ def test_fstab(self):
contents = f.read()
self.assertFalse("blivetTestLVMine" in contents)
self.assertFalse("/mnt/test2" in contents)

def test_swap_creation(self):
# test swap creation for presence of FSTabOptions object
disk = self.storage.devicetree.get_device_by_path(self.vdevs[0])
self.assertIsNotNone(disk)

with tempfile.TemporaryDirectory() as tmpdirname:
fstab_path = os.path.join(tmpdirname, 'fstab')

# change write path of blivet.fstab
self.storage.fstab.dest_file = fstab_path

self.storage.format_device(disk, blivet.formats.get_format("swap"))

try:
self.storage.do_it()
except AttributeError as e:
if "has no attribute 'fstab'" in str(e):
self.fail("swap creation test failed on missing FSTabOptions object: %s" % str(e))

0 comments on commit b9c683a

Please sign in to comment.