119 lines
4.2 KiB
Diff
119 lines
4.2 KiB
Diff
From a45b33839a88572a9776deec61234917fb66fb4f Mon Sep 17 00:00:00 2001
|
|
From: Vojtech Trefny <vtrefny@redhat.com>
|
|
Date: Tue, 31 Dec 2019 15:37:32 +0100
|
|
Subject: [PATCH 1/2] Define the 'relabels' method for all formats
|
|
|
|
---
|
|
blivet/formats/__init__.py | 4 ++++
|
|
1 file changed, 4 insertions(+)
|
|
|
|
diff --git a/blivet/formats/__init__.py b/blivet/formats/__init__.py
|
|
index 84657e01..0dbbae93 100644
|
|
--- a/blivet/formats/__init__.py
|
|
+++ b/blivet/formats/__init__.py
|
|
@@ -250,6 +250,10 @@ def labeling(self):
|
|
"""Returns False by default since most formats are non-labeling."""
|
|
return False
|
|
|
|
+ def relabels(self):
|
|
+ """Returns False by default since most formats are non-labeling."""
|
|
+ return False
|
|
+
|
|
def label_format_ok(self, label):
|
|
"""Checks whether the format of the label is OK for whatever
|
|
application is used by blivet to write a label for this format.
|
|
|
|
From 2e5e1b5f07be00a0b594742007bcadc2abdf2912 Mon Sep 17 00:00:00 2001
|
|
From: Vojtech Trefny <vtrefny@redhat.com>
|
|
Date: Tue, 31 Dec 2019 16:32:07 +0100
|
|
Subject: [PATCH 2/2] Add support for relabeling of the swap format
|
|
|
|
---
|
|
blivet/formats/swap.py | 39 ++++++++++++++++++++++++++++-
|
|
tests/formats_test/labeling_test.py | 6 +++++
|
|
2 files changed, 44 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/blivet/formats/swap.py b/blivet/formats/swap.py
|
|
index 36b50cb6..4b8a7edf 100644
|
|
--- a/blivet/formats/swap.py
|
|
+++ b/blivet/formats/swap.py
|
|
@@ -20,8 +20,10 @@
|
|
# Red Hat Author(s): Dave Lehman <dlehman@redhat.com>
|
|
#
|
|
|
|
+import os
|
|
+
|
|
from parted import PARTITION_SWAP, fileSystemType
|
|
-from ..errors import FSWriteUUIDError
|
|
+from ..errors import FSWriteUUIDError, SwapSpaceError
|
|
from ..storage_log import log_method_call
|
|
from ..tasks import availability
|
|
from ..tasks import fsuuid
|
|
@@ -53,6 +55,8 @@ class SwapSpace(DeviceFormat):
|
|
# see rhbz#744129 for details
|
|
_max_size = Size("128 GiB")
|
|
|
|
+ config_actions_map = {"label": "write_label"}
|
|
+
|
|
def __init__(self, **kwargs):
|
|
"""
|
|
:keyword device: path to the block device node
|
|
@@ -105,10 +109,43 @@ def labeling(self):
|
|
"""Returns True as mkswap can write a label to the swap space."""
|
|
return True
|
|
|
|
+ def relabels(self):
|
|
+ """Returns True as mkswap can write a label to the swap space."""
|
|
+ return True and self._plugin.available
|
|
+
|
|
def label_format_ok(self, label):
|
|
"""Returns True since no known restrictions on the label."""
|
|
return True
|
|
|
|
+ def write_label(self, dry_run=False):
|
|
+ """ Create a label for this format.
|
|
+
|
|
+ :raises: SwapSpaceError
|
|
+
|
|
+ If self.label is None, this means accept the default, so raise
|
|
+ an SwapSpaceError in this case.
|
|
+
|
|
+ Raises a SwapSpaceError if the label can not be set.
|
|
+ """
|
|
+
|
|
+ if not self._plugin.available:
|
|
+ raise SwapSpaceError("application to set label on swap format is not available")
|
|
+
|
|
+ if not dry_run:
|
|
+ if not self.exists:
|
|
+ raise SwapSpaceError("swap has not been created")
|
|
+
|
|
+ if not os.path.exists(self.device):
|
|
+ raise SwapSpaceError("device does not exist")
|
|
+
|
|
+ if self.label is None:
|
|
+ raise SwapSpaceError("makes no sense to write a label when accepting default label")
|
|
+
|
|
+ if not self.label_format_ok(self.label):
|
|
+ raise SwapSpaceError("bad label format")
|
|
+
|
|
+ blockdev.swap.mkswap(self.device, self.label)
|
|
+
|
|
label = property(lambda s: s._get_label(), lambda s, l: s._set_label(l),
|
|
doc="the label for this swap space")
|
|
|
|
diff --git a/tests/formats_test/labeling_test.py b/tests/formats_test/labeling_test.py
|
|
index e2569201..e26cb7df 100644
|
|
--- a/tests/formats_test/labeling_test.py
|
|
+++ b/tests/formats_test/labeling_test.py
|
|
@@ -113,3 +113,9 @@ def test_creating_swap_space_none(self):
|
|
def test_creating_swap_space_empty(self):
|
|
swp = swap.SwapSpace(device=self.loop_devices[0], label="")
|
|
self.assertIsNone(swp.create())
|
|
+
|
|
+ def test_relabel(self):
|
|
+ swp = swap.SwapSpace(device=self.loop_devices[0])
|
|
+ self.assertIsNone(swp.create())
|
|
+ swp.label = "label"
|
|
+ swp.write_label()
|