[anaconda:rhel7/master 2/2] Verify that designated label can be set (#1038590)

mulhern amulhern at redhat.com
Thu Jan 9 18:57:58 UTC 2014


Resolves: rhbz#1038590

Once the user has pressed accept verify that the label they have designated,
if it is changed from the previous label, can actually be set.

Display an informative message and reset values if not.

One variable name was changed in the process and had to be substituted in
a couple of places.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 pyanaconda/ui/gui/spokes/custom.py | 53 +++++++++++++++++++++++++++++++++-----
 1 file changed, 47 insertions(+), 6 deletions(-)

diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py
index 74611d3..699f78b 100644
--- a/pyanaconda/ui/gui/spokes/custom.py
+++ b/pyanaconda/ui/gui/spokes/custom.py
@@ -109,6 +109,10 @@ unrecoverable_error_msg = N_("Storage configuration reset due to unrecoverable "
 device_configuration_error_msg = N_("Device reconfiguration failed. Click for "
                                     "details.")
 
+label_format_invalid_msg = N_("Unacceptable label format for filesystem.")
+label_application_unavailable_msg = N_("Can not set label on filesystem.")
+label_resetting_forbidden_msg = N_("Can not relabel already existing filesystem.")
+
 empty_mountpoint_msg = N_("Please enter a valid mountpoint.")
 invalid_mountpoint_msg = N_("That mount point is invalid. Try something else?")
 mountpoint_in_use_msg = N_("That mount point is already in use. Try something else?")
@@ -123,6 +127,18 @@ container_type_names = {DEVICE_TYPE_LVM: lvm_container_name,
                         DEVICE_TYPE_LVM_THINP: lvm_container_name,
                         DEVICE_TYPE_BTRFS: btrfs_container_name}
 
+LABEL_OK = 0
+LABEL_FORMAT_INVALID = 1
+LABEL_APPLICATION_UNAVAILABLE = 2
+LABEL_RESETTING_FORBIDDEN = 3
+
+label_validation_msgs = {
+    LABEL_OK: "",
+    LABEL_FORMAT_INVALID: label_format_invalid_msg,
+    LABEL_APPLICATION_UNAVAILABLE: label_application_unavailable_msg,
+    LABEL_RESETTING_FORBIDDEN: label_resetting_forbidden_msg}
+
+
 MOUNTPOINT_OK = 0
 MOUNTPOINT_INVALID = 1
 MOUNTPOINT_IN_USE = 2
@@ -198,6 +214,22 @@ def populate_mountpoint_store(store, used_mountpoints):
         if path not in used_mountpoints:
             store.append([path])
 
+def validate_label(label, fmt):
+    """Returns a code indicating either that the given label can be set for
+       this filesystem or the reason why it can not.
+
+       :param str label: The label
+       :param DeviceFormat fmt: The device format to label
+
+    """
+    if fmt.exists:
+        return LABEL_RESETTING_FORBIDDEN
+    if not fmt.labeling():
+        return LABEL_APPLICATION_UNAVAILABLE
+    if not fmt.labelFormatOK(label):
+        return LABEL_FORMAT_INVALID
+    return LABEL_OK
+
 def validate_mountpoint(mountpoint, used_mountpoints, strict=True):
     if strict:
         fake_mountpoints = []
@@ -1117,10 +1149,11 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
         old_fs_type = device.format.type
         fs_type_index = self._fsCombo.get_active()
         fs_type = self._fsCombo.get_model()[fs_type_index][0]
-        fs_type_short = getFormat(fs_type).type
-        changed_fs_type = (old_fs_type != fs_type_short)
+        new_fs = getFormat(fs_type)
+        new_fs_type = new_fs.type
+        changed_fs_type = (old_fs_type != new_fs_type)
         log.debug("old fs type: %s" % old_fs_type)
-        log.debug("new fs type: %s" % fs_type_short)
+        log.debug("new fs type: %s" % new_fs_type)
 
         # ENCRYPTION
         old_encrypted = isinstance(device, LUKSDevice)
@@ -1138,6 +1171,14 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
         changed_label = (label != old_label)
         log.debug("old label: %s" % old_label)
         log.debug("new_label: %s" % label)
+        if changed_label:
+            error = validate_label(label, new_fs)
+            if error:
+                self._error = _(label_validation_msgs[error])
+                self.set_warning(self._error)
+                self.window.show_all()
+                self._populate_right_side(selector)
+                return
 
         # MOUNTPOINT
         mountpoint = None   # None means format type is not mountable
@@ -1185,12 +1226,12 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             error = (_("/boot/efi must be on a device of type %s")
                      % _(DEVICE_TEXT_PARTITION))
         elif device_type != DEVICE_TYPE_PARTITION and \
-             fs_type_short in partition_only_format_types:
+             new_fs_type in partition_only_format_types:
             error = (_("%s must be on a device of type %s")
                      % (fs_type, _(DEVICE_TEXT_PARTITION)))
         elif mountpoint and encrypted and mountpoint.startswith("/boot"):
             error = _("%s cannot be encrypted") % mountpoint
-        elif encrypted and fs_type_short in partition_only_format_types:
+        elif encrypted and new_fs_type in partition_only_format_types:
             error = _("%s cannot be encrypted") % fs_type
         elif mountpoint == "/" and device.format.exists and not reformat:
             error = _("You must create a new filesystem on the root device.")
@@ -1464,7 +1505,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             # FORMATTING
             #
             log.info("scheduling reformat of %s as %s" % (device.name,
-                                                          fs_type_short))
+                                                          new_fs_type))
             with ui_storage_logger():
                 old_format = device.format
                 new_format = getFormat(fs_type,
-- 
1.8.3.1



More information about the anaconda-patches mailing list