[master 1/1] Enforce sane disk selections.
dwlehman
installerbot-noreply at redhat.com
Thu Apr 2 16:34:04 UTC 2015
From: David Lehman <dlehman at redhat.com>
There is no value (and a great deal of trouble) in allowing users to split
up an existing md array, lvm vg, or btrfs volume by selecting a subset of
the disks it uses.
---
po/POTFILES.in | 1 +
pyanaconda/ui/gui/spokes/storage.py | 12 +++++++++++-
pyanaconda/ui/lib/disks.py | 26 ++++++++++++++++++++++++++
pyanaconda/ui/tui/spokes/storage.py | 13 +++++++++++--
4 files changed, 49 insertions(+), 3 deletions(-)
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 6ba4fac..2b663cc 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -46,6 +46,7 @@ pyanaconda/ui/categories/user_settings.py
# Common stuff
pyanaconda/ui/lib/space.py
pyanaconda/ui/lib/entropy.py
+pyanaconda/ui/lib/disks.py
# Text interface
pyanaconda/ui/tui/hubs/summary.py
diff --git a/pyanaconda/ui/gui/spokes/storage.py b/pyanaconda/ui/gui/spokes/storage.py
index abca0c4..b7b5671 100644
--- a/pyanaconda/ui/gui/spokes/storage.py
+++ b/pyanaconda/ui/gui/spokes/storage.py
@@ -42,7 +42,7 @@
from gi.repository import Gdk, GLib, AnacondaWidgets
from pyanaconda.ui.communication import hubQ
-from pyanaconda.ui.lib.disks import getDisks, isLocalDisk, applyDiskSelection
+from pyanaconda.ui.lib.disks import getDisks, isLocalDisk, applyDiskSelection, checkDiskSelection
from pyanaconda.ui.gui import GUIObject
from pyanaconda.ui.gui.spokes import NormalSpoke
from pyanaconda.ui.gui.spokes.lib.cart import SelectedDisksDialog
@@ -754,6 +754,16 @@ def on_back_clicked(self, button):
partition in self.storage.partitions:
self.storage.recursiveRemove(partition)
+ # make sure no containers were split up by the user's disk selection
+ self.clear_info()
+ self.errors = checkDiskSelection(self.storage, self.selected_disks)
+ if self.errors:
+ # The disk selection has to make sense before we can proceed.
+ self.set_error(_("There was a problem with your disk selection. "
+ "Click here for details."))
+ self.back_clicked = False
+ return
+
# hide/unhide disks as requested
for disk in self.disks:
if disk.name not in self.selected_disks and \
diff --git a/pyanaconda/ui/lib/disks.py b/pyanaconda/ui/lib/disks.py
index 9d4607f..a47c7be 100644
--- a/pyanaconda/ui/lib/disks.py
+++ b/pyanaconda/ui/lib/disks.py
@@ -23,6 +23,7 @@
from blivet.devices import MultipathDevice, iScsiDiskDevice, FcoeDiskDevice
from pyanaconda.flags import flags
+from pyanaconda.i18n import _, P_
__all__ = ["FakeDiskLabel", "FakeDisk", "getDisks", "isLocalDisk"]
@@ -92,3 +93,28 @@ def applyDiskSelection(storage, data, use_names):
data.ignoredisk.onlyuse = onlyuse
data.clearpart.drives = use_names[:]
+
+def checkDiskSelection(storage, selected_disks):
+ """ Return a list of errors related to a proposed disk selection.
+
+ :param :class:`blivet.Blivet` storage: storage data
+ :param selected_disks: names of proposed selected disks
+ :type selected_disks: list of str
+ :returns: a list of error messages
+ :rtype: list of str
+ """
+ errors = []
+ for name in selected_disks:
+ selected = storage.devicetree.getDeviceByName(name, hidden=True)
+ related = sorted(storage.devicetree.getRelatedDisks(selected))
+ missing = [r.name for r in related if r.name not in selected_disks]
+ if missing:
+ errors.append(_("You selected disk %(selected)s, which contains "
+ "devices that also use unselected %(disk)s "
+ "%(unselected)s. You must select or de-select "
+ "these disks as a set.") %
+ {"selected": selected.name,
+ "disk": P_("disk", "disks", len(missing)),
+ "unselected": ",".join(missing)})
+
+ return errors
diff --git a/pyanaconda/ui/tui/spokes/storage.py b/pyanaconda/ui/tui/spokes/storage.py
index 1bb0d11..ca78f9b 100644
--- a/pyanaconda/ui/tui/spokes/storage.py
+++ b/pyanaconda/ui/tui/spokes/storage.py
@@ -22,7 +22,7 @@
# which has the same license and authored by David Lehman <dlehman at redhat.com>
#
-from pyanaconda.ui.lib.disks import getDisks, applyDiskSelection
+from pyanaconda.ui.lib.disks import getDisks, applyDiskSelection, checkDiskSelection
from pyanaconda.ui.categories.system import SystemCategory
from pyanaconda.ui.tui.spokes import NormalTUISpoke
from pyanaconda.ui.tui.simpleline import TextWidget, CheckboxWidget
@@ -260,7 +260,7 @@ def _format_disk_info(self, disk):
def input(self, args, key):
"""Grab the disk choice and update things"""
-
+ self.errors = []
try:
keyid = int(key) - 1
self.selection = keyid
@@ -281,6 +281,15 @@ def input(self, args, key):
self.run_dasdfmt(to_format)
return None
+ # make sure no containers were split up by the user's disk
+ # selection
+ self.errors.extend(checkDiskSelection(self.storage,
+ self.selected_disks))
+ if self.errors:
+ # The disk selection has to make sense before we can
+ # proceed.
+ return None
+
newspoke = AutoPartSpoke(self.app, self.data, self.storage,
self.payload, self.instclass)
self.app.switch_screen_modal(newspoke)
--
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/6ca866cd2db8651b4a646bb27c391618feacaecb
More information about the anaconda-patches
mailing list