[blivet 06/13] BTRFSSubVolume.volume checks the class of its return value.
mulhern
amulhern at redhat.com
Fri Dec 6 16:50:06 UTC 2013
If it is not an instance of BTRFSVolume a DeviceError is raised.
It must be a BTRFSVolume because that is how btrfs works and also because
otherwise the constructor will raise an AttributeError when calling
_addSubVolume on an object other than a BTRFSVolume.
This change causes the constructor to fail a bit more informatively and a bit
earlier than it otherwise would.
Signed-off-by: mulhern <amulhern at redhat.com>
---
blivet/devices.py | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/blivet/devices.py b/blivet/devices.py
index fe3bb1c..8a1c4a6 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -4555,6 +4555,13 @@ class BTRFSSubVolumeDevice(BTRFSDevice):
@property
def volume(self):
+ """Return the first ancestor that is not a BTRFSSubVolumeDevice.
+
+ Note: Assumes that each ancestor in traversal has only one parent.
+
+ Raises a DeviceError if the ancestor found is not a
+ BTRFSVolumeDevice.
+ """
parent = self.parents[0]
vol = None
while True:
@@ -4564,6 +4571,8 @@ class BTRFSSubVolumeDevice(BTRFSDevice):
parent = parent.parents[0]
+ if not isinstance(vol, BTRFSVolumeDevice):
+ raise DeviceError("%s %s's first non subvolume ancestor must be a btrfs volume" % (self.type, self.name))
return vol
def setupParents(self, orig=False):
--
1.8.3.1
More information about the anaconda-patches
mailing list