[master 2/2] Use getDiskDescription for disk description strings (#1242117)

bcl installerbot-noreply at redhat.com
Wed Aug 12 00:31:25 UTC 2015


From: "Brian C. Lane" <bcl at redhat.com>

sysfs vendor information doesn't consistently return use a user friendly
string so we use a helper, getDiskDescription, to translate any
exceptions.

Also adds a simple test for it.
---
 pyanaconda/ui/gui/spokes/custom.py                 |  3 +-
 pyanaconda/ui/gui/spokes/lib/cart.py               |  3 +-
 .../ui/gui/spokes/lib/custom_storage_helpers.py    |  5 ++-
 pyanaconda/ui/gui/spokes/lib/resize.py             |  4 +-
 pyanaconda/ui/gui/spokes/lib/summary.py            |  3 +-
 pyanaconda/ui/gui/spokes/storage.py                |  3 +-
 pyanaconda/ui/lib/disks.py                         |  2 +-
 tests/pyanaconda_tests/lib_disks_test.py           | 46 ++++++++++++++++++++++
 8 files changed, 61 insertions(+), 8 deletions(-)
 create mode 100644 tests/pyanaconda_tests/lib_disks_test.py

diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py
index 24c8474..cdb1898 100644
--- a/pyanaconda/ui/gui/spokes/custom.py
+++ b/pyanaconda/ui/gui/spokes/custom.py
@@ -80,6 +80,7 @@
 from pyanaconda.ui.communication import hubQ
 from pyanaconda.ui.gui.spokes import NormalSpoke
 from pyanaconda.ui.helpers import StorageChecker
+from pyanaconda.ui.lib.disks import getDiskDescription
 from pyanaconda.ui.gui.spokes.lib.cart import SelectedDisksDialog
 from pyanaconda.ui.gui.spokes.lib.passphrase import PassphraseDialog
 from pyanaconda.ui.gui.spokes.lib.accordion import updateSelectorFromDevice, Accordion, Page, CreateNewPage, UnknownPage
@@ -1459,7 +1460,7 @@ def _set_devices_label(self):
         if not device_disks:
             devices_desc = _("No disks assigned")
         else:
-            devices_desc = "%s (%s)" % (device_disks[0].description, device_disks[0].name)
+            devices_desc = "%s (%s)" % (getDiskDescription(device_disks[0]), device_disks[0].name)
             num_disks = len(device_disks)
             if num_disks > 1:
                 devices_desc += CP_("GUI|Custom Partitioning|Devices",
diff --git a/pyanaconda/ui/gui/spokes/lib/cart.py b/pyanaconda/ui/gui/spokes/lib/cart.py
index aad5631..d8f2750 100644
--- a/pyanaconda/ui/gui/spokes/lib/cart.py
+++ b/pyanaconda/ui/gui/spokes/lib/cart.py
@@ -28,6 +28,7 @@
 from pyanaconda.i18n import C_, P_
 from pyanaconda.ui.gui import GUIObject
 from pyanaconda.ui.gui.utils import escape_markup
+from pyanaconda.ui.lib.disks import getDiskDescription
 from blivet.size import Size
 
 __all__ = ["SelectedDisksDialog"]
@@ -61,7 +62,7 @@ def initialize(self, disks, free, showRemove=True, setBoot=True):
 
         for disk in disks:
             self._store.append([False,
-                                "%s (%s)" % (disk.description, disk.serial),
+                                "%s (%s)" % (getDiskDescription(disk), disk.serial),
                                 str(disk.size),
                                 str(free[disk.name][0]),
                                 disk.name,
diff --git a/pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py b/pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py
index 8f3b6d6..e4723e0 100644
--- a/pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py
+++ b/pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py
@@ -41,6 +41,7 @@
 from pyanaconda.ui.gui import GUIObject
 from pyanaconda.ui.gui.helpers import GUIDialogInputCheckHandler
 from pyanaconda.ui.gui.utils import fancy_set_sensitive, really_hide, really_show
+from pyanaconda.ui.lib.disks import getDiskDescription
 from pyanaconda.i18n import _, N_, C_, CN_
 
 from blivet.size import Size
@@ -417,7 +418,7 @@ def __init__(self, *args, **kwargs):
         self._store = self.builder.get_object("disk_store")
         # populate the store
         for disk in self._disks:
-            self._store.append(["%s (%s)" % (disk.description, disk.serial),
+            self._store.append(["%s (%s)" % (getDiskDescription(disk), disk.serial),
                                 str(disk.size),
                                 str(free[disk.name][0]),
                                 disk.name,
@@ -505,7 +506,7 @@ def __init__(self, *args, **kwargs):
 
         # populate the store
         for disk in self._disks:
-            self._store.append([disk.description,
+            self._store.append([getDiskDescription(disk),
                                 str(disk.size),
                                 str(free[disk.name][0]),
                                 disk.serial,
diff --git a/pyanaconda/ui/gui/spokes/lib/resize.py b/pyanaconda/ui/gui/spokes/lib/resize.py
index cc086f9..42848c0 100644
--- a/pyanaconda/ui/gui/spokes/lib/resize.py
+++ b/pyanaconda/ui/gui/spokes/lib/resize.py
@@ -31,6 +31,7 @@
 from pyanaconda.i18n import _, C_, N_, P_
 from pyanaconda.ui.gui import GUIObject
 from pyanaconda.ui.gui.utils import blockedHandler, escape_markup, timed_action
+from pyanaconda.ui.lib.disks import getDiskDescription
 from blivet.size import Size
 
 __all__ = ["ResizeDialog"]
@@ -142,7 +143,8 @@ def populate(self, disks):
                 diskReclaimableSpace = disk.size
 
             itr = self._diskStore.append(None, [disk.id,
-                                                "%s %s" % (disk.size.humanReadable(max_places=1), disk.description),
+                                                "%s %s" % (disk.size.humanReadable(max_places=1),
+                                                           getDiskDescription(disk)),
                                                 fstype,
                                                 "<span foreground='grey' style='italic'>%s total</span>",
                                                 _(PRESERVE),
diff --git a/pyanaconda/ui/gui/spokes/lib/summary.py b/pyanaconda/ui/gui/spokes/lib/summary.py
index ea41734..672c6f8 100644
--- a/pyanaconda/ui/gui/spokes/lib/summary.py
+++ b/pyanaconda/ui/gui/spokes/lib/summary.py
@@ -21,6 +21,7 @@
 
 from pyanaconda.ui.gui import GUIObject
 from pyanaconda.ui.gui.utils import escape_markup
+from pyanaconda.ui.lib.disks import getDiskDescription
 from pyanaconda.i18n import _
 
 from blivet.deviceaction import ACTION_TYPE_DESTROY, ACTION_TYPE_RESIZE, ACTION_OBJECT_FORMAT
@@ -56,7 +57,7 @@ def initialize(self, actions):
                 serial = action.device.serial
             elif hasattr(action.device, "disk"):
                 desc = _("%(deviceName)s on %(container)s") % {"deviceName": action.device.name,
-                                                               "container": action.device.disk.description}
+                                                               "container": getDiskDescription(action.device.disk)}
                 serial = action.device.disk.serial
             else:
                 desc = action.device.name
diff --git a/pyanaconda/ui/gui/spokes/storage.py b/pyanaconda/ui/gui/spokes/storage.py
index 6f2b8ce..5e1bc3a 100644
--- a/pyanaconda/ui/gui/spokes/storage.py
+++ b/pyanaconda/ui/gui/spokes/storage.py
@@ -50,6 +50,7 @@
 
 from pyanaconda.ui.communication import hubQ
 from pyanaconda.ui.lib.disks import getDisks, isLocalDisk, applyDiskSelection, checkDiskSelection
+from pyanaconda.ui.lib.disks import getDiskDescription
 from pyanaconda.ui.gui import GUIObject
 from pyanaconda.ui.gui.spokes import NormalSpoke
 from pyanaconda.ui.gui.spokes.lib.cart import SelectedDisksDialog
@@ -598,7 +599,7 @@ def _add_disk_overview(self, disk, box):
             description = _("FCP device %(hba_id)s\nWWPN %(wwpn)s\nLUN %(lun)s") % \
                             {"hba_id": disk.hba_id, "wwpn": disk.wwpn, "lun": disk.fcp_lun}
         else:
-            description = disk.description
+            description = getDiskDescription(disk)
 
         free = self.storage.getFreeSpace(disks=[disk])[disk.name][0]
 
diff --git a/pyanaconda/ui/lib/disks.py b/pyanaconda/ui/lib/disks.py
index fe521c1..8a301f3 100644
--- a/pyanaconda/ui/lib/disks.py
+++ b/pyanaconda/ui/lib/disks.py
@@ -45,7 +45,7 @@ def __init__(self, name, size=0, free=0, partitioned=True, vendor=None,
 
     @property
     def description(self):
-        return "%s %s" % (self.vendor, self.model)
+        return " ".join(s for s in (self.vendor, self.model) if s)
 
 def getDisks(devicetree, fake=False):
     if not fake:
diff --git a/tests/pyanaconda_tests/lib_disks_test.py b/tests/pyanaconda_tests/lib_disks_test.py
new file mode 100644
index 0000000..4f51494
--- /dev/null
+++ b/tests/pyanaconda_tests/lib_disks_test.py
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2015  Red Hat, Inc.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions of
+# the GNU General Public License v.2, or (at your option) any later version.
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY expressed or implied, including the implied warranties of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
+# Public License for more details.  You should have received a copy of the
+# GNU General Public License along with this program; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
+# source code or documentation are not subject to the GNU General Public
+# License and may only be used or replicated with the express permission of
+# Red Hat, Inc.
+#
+# Red Hat Author(s): Brian C. Lane <bcl at redhat.com>
+#                    Martin Kolman <mkolman at redhat.com>
+
+from pyanaconda.ui.lib.disks import FakeDisk, getDiskDescription
+import unittest
+
+class GetDiskDescriptionTests(unittest.TestCase):
+    def setUp(self):
+        # pylint: disable=attribute-defined-outside-init
+        self.model_disk = FakeDisk(name="Fake Disk 1", model="Only Model")
+        self.vendor_disk = FakeDisk(name="Fake Disk 2", vendor="Only Vendor")
+        self.normal_disk = FakeDisk(name="Fake Disk 3", model="Plane", vendor="Ice Cream")
+        self.virtio_disk = FakeDisk(name="Fake Disk 4", vendor="0x1af4")
+
+    def disk_description_test(self):
+        """Disk description should be correct"""
+
+        # Just the model, no vendor
+        self.assertEqual(getDiskDescription(self.model_disk), "Only Model")
+
+        # Just the vendor, no model
+        self.assertEqual(getDiskDescription(self.vendor_disk), "Only Vendor")
+
+        # Both model and vendor
+        self.assertEqual(getDiskDescription(self.normal_disk), "Ice Cream Plane")
+
+        # Virtio translation
+        self.assertEqual(getDiskDescription(self.virtio_disk), "Virtio Block Device")


-- 
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/44c2761b5b4fb5998e8a0d57d7a4b8bfecf845e1


More information about the anaconda-patches mailing list