[blivet:f21-branch/master 3/3] Make self.formatClass not a field (#1150147)

mulhern amulhern at redhat.com
Fri Oct 10 16:24:08 UTC 2014


Related: fed#1150147

Remove constructor, because setting formatClass was all it did before
calling superconstructor.

self.formatClass field is only used in one method,
so might as well make it local to that one method as set it in constructor.

In constructor, it is necessary to set if before superclass constructor
call, which is a sign that something is slightly wrong (as superclass
state depends on additional subclass fields). Ideally, we could
be in a situation where we always call superclass constructor at start
of subclass constructor. In reality, that's not happening, but it
can here, so that's another plus.

Getting the format is not so expensive...after the first time it isn't
much more than a hash table lookup.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/devices.py     | 14 +++++---------
 tests/devices_test.py |  1 -
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/blivet/devices.py b/blivet/devices.py
index abdf8d1..90929c2 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -2326,13 +2326,6 @@ class ContainerDevice(StorageDevice):
     _formatUUIDAttr = abc.abstractproperty(lambda s: None,
         doc="The container UUID attribute in the member format class")
 
-    def __init__(self, *args, **kwargs):
-        self.formatClass = get_device_format_class(self._formatClassName)
-        if not self.formatClass:
-            raise errors.StorageError("cannot find '%s' class" % self._formatClassName)
-
-        super(ContainerDevice, self).__init__(*args, **kwargs)
-
     def _verifyMemberFormat(self, member):
         """ Whether the member has the format expected by the device.
 
@@ -2341,8 +2334,11 @@ class ContainerDevice(StorageDevice):
             :returns: error msg if the member has incorrect format, else None
             :rtype: str or NoneType
         """
-        if not isinstance(member.format, self.formatClass):
-            return "Member format %(format)s is not a subtype of expected format %(expected)s." % {'format' : member.format, 'expected' : self.formatClass}
+        formatClass = get_device_format_class(self._formatClassName)
+        if not formatClass:
+            raise errors.StorageError("cannot find '%s' class" % self._formatClassName)
+        if not isinstance(member.format, formatClass):
+            return "Member format %(format)s is not a subtype of expected format %(expected)s." % {'format' : member.format, 'expected' : formatClass}
         return None
 
     def _addParent(self, member):
diff --git a/tests/devices_test.py b/tests/devices_test.py
index 51da84c..8b84084 100644
--- a/tests/devices_test.py
+++ b/tests/devices_test.py
@@ -77,7 +77,6 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
            "exists" : self.assertFalse,
            "format" : self.assertIsNotNone,
            "formatArgs" : lambda x, m: self.assertEqual(x, [], m),
-           "formatClass" : self.assertIsNotNone,
            "isDisk" : self.assertFalse,
            "level" : self.assertIsNone,
            "major" : lambda x, m: self.assertEqual(x, 0, m),
-- 
1.9.3



More information about the anaconda-patches mailing list