Getting the unencrypted backing device is an action that happens over and over in blivet DeviceFactory and in anaconda custom spoke as well. I'ld like to make this a Device property and be consistant in always checking isinstance instead of some times checking the type string. Right now, checking either amounts to the same, because nothing extends LUKSDevice, but that could change.
mulhern (1): Make a StorageDevice.raw_device property and use it where appropriate
blivet/devicefactory.py | 16 +++------------- blivet/devices.py | 9 +++++++++ tests/devices_test.py | 1 + 3 files changed, 13 insertions(+), 13 deletions(-)
Only allow a "NoneType has no attribute <x>" exception where it would be allowed by the code that it replaces anyway. Otherwise, check for existance of device before accessing its raw_device property.
Signed-off-by: mulhern amulhern@redhat.com --- blivet/devicefactory.py | 16 +++------------- blivet/devices.py | 9 +++++++++ tests/devices_test.py | 1 + 3 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/blivet/devicefactory.py b/blivet/devicefactory.py index 055fdc2..a5717c1 100644 --- a/blivet/devicefactory.py +++ b/blivet/devicefactory.py @@ -79,10 +79,7 @@ def get_device_type(device): "btrfs volume": DEVICE_TYPE_BTRFS, "mdarray": DEVICE_TYPE_MD}
- use_dev = device - if isinstance(device, LUKSDevice): - use_dev = device.slave - + use_dev = device.raw_device if use_dev.isDisk: device_type = DEVICE_TYPE_DISK else: @@ -536,14 +533,7 @@ class DeviceFactory(object): @property def raw_device(self): """ If self.device is encrypted, this is its backing device. """ - use_dev = None - if self.device: - if isinstance(self.device, LUKSDevice): - use_dev = self.device.slave - else: - use_dev = self.device - - return use_dev + return self.device.raw_device if self.device else None
@property def devices(self): @@ -858,7 +848,7 @@ class PartitionFactory(DeviceFactory):
def _set_device_size(self): """ Set the size of a defined factory device. """ - if self.device and self.size != self.raw_device.size: + if self.raw_device and self.size != self.raw_device.size: log.info("adjusting device size from %s to %s", self.raw_device.size, self.size)
diff --git a/blivet/devices.py b/blivet/devices.py index 80282c7..d324ce1 100644 --- a/blivet/devices.py +++ b/blivet/devices.py @@ -672,6 +672,11 @@ class StorageDevice(Device):
return self._partedDevice
+ @property + def raw_device(self): + """ The device itself, or when encrypted, the backing device. """ + return self + def _setName(self, value): """Set the device's name.
@@ -2173,6 +2178,10 @@ class LUKSDevice(DMCryptDevice): uuid=None, exists=exists)
@property + def raw_device(self): + return self.slave + + @property def size(self): if not self.exists or not self.partedDevice: size = self.slave.size - crypto.LUKS_METADATA_SIZE diff --git a/tests/devices_test.py b/tests/devices_test.py index 3f8c4fc..3dc5fd1 100644 --- a/tests/devices_test.py +++ b/tests/devices_test.py @@ -82,6 +82,7 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase): self.assertIsInstance(x, ParentList, m), "path" : lambda x, m: self.assertRegexpMatches(x, "^/dev", m), "partitionable" : self.assertFalse, + "raw_device" : self.assertIsNotNone, "resizable" : self.assertFalse, "size" : lambda x, m: self.assertEqual(x, Size(0), m), "spares" : lambda x, m: self.assertEqual(x, 0, m),
On Fri, 2014-05-30 at 14:48 -0400, mulhern wrote:
Only allow a "NoneType has no attribute <x>" exception where it would be allowed by the code that it replaces anyway. Otherwise, check for existance of device before accessing its raw_device property.
Signed-off-by: mulhern amulhern@redhat.com
blivet/devicefactory.py | 16 +++------------- blivet/devices.py | 9 +++++++++ tests/devices_test.py | 1 + 3 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/blivet/devicefactory.py b/blivet/devicefactory.py index 055fdc2..a5717c1 100644 --- a/blivet/devicefactory.py +++ b/blivet/devicefactory.py @@ -79,10 +79,7 @@ def get_device_type(device): "btrfs volume": DEVICE_TYPE_BTRFS, "mdarray": DEVICE_TYPE_MD}
- use_dev = device
- if isinstance(device, LUKSDevice):
use_dev = device.slave
- use_dev = device.raw_device if use_dev.isDisk: device_type = DEVICE_TYPE_DISK else:
@@ -536,14 +533,7 @@ class DeviceFactory(object): @property def raw_device(self): """ If self.device is encrypted, this is its backing device. """
use_dev = Noneif self.device:if isinstance(self.device, LUKSDevice):use_dev = self.device.slaveelse:use_dev = self.devicereturn use_dev
return self.device.raw_device if self.device else None@property def devices(self):
@@ -858,7 +848,7 @@ class PartitionFactory(DeviceFactory):
def _set_device_size(self): """ Set the size of a defined factory device. """
if self.device and self.size != self.raw_device.size:
if self.raw_device and self.size != self.raw_device.size: log.info("adjusting device size from %s to %s", self.raw_device.size, self.size)diff --git a/blivet/devices.py b/blivet/devices.py index 80282c7..d324ce1 100644 --- a/blivet/devices.py +++ b/blivet/devices.py @@ -672,6 +672,11 @@ class StorageDevice(Device):
return self._partedDevice
- @property
- def raw_device(self):
""" The device itself, or when encrypted, the backing device. """return self- def _setName(self, value): """Set the device's name.
@@ -2173,6 +2178,10 @@ class LUKSDevice(DMCryptDevice): uuid=None, exists=exists)
@property
- def raw_device(self):
return self.slave- @property def size(self): if not self.exists or not self.partedDevice: size = self.slave.size - crypto.LUKS_METADATA_SIZE
diff --git a/tests/devices_test.py b/tests/devices_test.py index 3f8c4fc..3dc5fd1 100644 --- a/tests/devices_test.py +++ b/tests/devices_test.py @@ -82,6 +82,7 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase): self.assertIsInstance(x, ParentList, m), "path" : lambda x, m: self.assertRegexpMatches(x, "^/dev", m), "partitionable" : self.assertFalse,
"raw_device" : self.assertIsNotNone, "resizable" : self.assertFalse, "size" : lambda x, m: self.assertEqual(x, Size(0), m), "spares" : lambda x, m: self.assertEqual(x, 0, m),
Looks good to me.
anaconda-patches@lists.fedorahosted.org