From 179381cb87aa1ee9f394ef836cd686fa5124ddb5 Mon Sep 17 00:00:00 2001 From: Jan Pokorny Date: Thu, 2 Nov 2023 11:55:41 +0100 Subject: [PATCH] Added missing fstab object to SwapSpace Anaconda tests revealed missing FSTabOptions object in SwapSpace class. This issue is related to the recent merge of fstab rework PR #1119 which added this object to FS class. SwapSpace does not inherit from FS and was overlooked. This change adds the missing object. It also adds logic that skips all fstab related operations if fstab file is not to be written (i.e. fstab.dest_file is None). The reason for this is to eliminate the risk of potential issues caused by unused component. The test for above has been added as well. --- blivet/actionlist.py | 6 ++++-- blivet/formats/swap.py | 3 +++ blivet/fstab.py | 2 +- tests/storage_tests/fstab_test.py | 19 +++++++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/blivet/actionlist.py b/blivet/actionlist.py index 68dbdb8f2..9b3f727e9 100644 --- a/blivet/actionlist.py +++ b/blivet/actionlist.py @@ -281,6 +281,8 @@ 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: @@ -288,7 +290,7 @@ def process(self, callbacks=None, devices=None, fstab=None, dry_run=None): # 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: @@ -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() diff --git a/blivet/formats/swap.py b/blivet/formats/swap.py index 03aa3cc68..77deb2a4d 100644 --- a/blivet/formats/swap.py +++ b/blivet/formats/swap.py @@ -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 @@ -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") diff --git a/blivet/fstab.py b/blivet/fstab.py index 7129648bf..5981a9514 100644 --- a/blivet/fstab.py +++ b/blivet/fstab.py @@ -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): diff --git a/tests/storage_tests/fstab_test.py b/tests/storage_tests/fstab_test.py index 87a4dc48c..a6710fb45 100644 --- a/tests/storage_tests/fstab_test.py +++ b/tests/storage_tests/fstab_test.py @@ -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))