[master 3/6] Move parents checking and update into a seprarate methods
vpodzime
installerbot-noreply at redhat.com
Thu Jun 4 18:22:06 UTC 2015
From: Vratislav Podzimek <vpodzime at redhat.com>
Internal LVs are not going to be referenced by the DeviceTree instance and are
going to have no parents. Their "parent" LVs are going to be referenced as
'self.parent_lv' instead of 'self.parents[0]' because all the other devices use
the opposite logic for parent-children relations -- children are consisting of
or built on top of parents (whereas "parent" LVs are consisting of their
internal LVs).
This way internal LVs can easily override these methods.
---
blivet/devices/lvm.py | 35 +++++++++++++++++++++++------------
1 file changed, 23 insertions(+), 12 deletions(-)
diff --git a/blivet/devices/lvm.py b/blivet/devices/lvm.py
index 3b94a22..394aa40 100644
--- a/blivet/devices/lvm.py
+++ b/blivet/devices/lvm.py
@@ -489,16 +489,6 @@ def __init__(self, name, parents=None, size=None, uuid=None,
:type percent: int
"""
- if isinstance(parents, list):
- if len(parents) != 1:
- raise ValueError("constructor requires a single %s instance" % self._containerClass.__name__)
-
- container = parents[0]
- else:
- container = parents
-
- if not isinstance(container, self._containerClass):
- raise ValueError("constructor requires a %s instance" % self._containerClass.__name__)
DMDevice.__init__(self, name, size=size, fmt=fmt,
sysfsPath=sysfsPath, parents=parents,
@@ -523,8 +513,29 @@ def __init__(self, name, parents=None, size=None, uuid=None,
self.req_size = self._size
self.req_percent = util.numeric_type(percent)
- # here we go with the circular references
- self.parents[0]._addLogVol(self)
+ # check that we got parents as expected and add this device to them
+ self._check_parents()
+ self._add_to_parents()
+
+ def _check_parents(self):
+ """Check that this device has parents as expected"""
+
+ if isinstance(self.parents, list):
+ if len(self.parents) != 1:
+ raise ValueError("constructor requires a single %s instance" % self._containerClass.__name__)
+
+ container = self.parents[0]
+ else:
+ container = self.parents
+
+ if not isinstance(container, self._containerClass):
+ raise ValueError("constructor requires a %s instance" % self._containerClass.__name__)
+
+ def _add_to_parents(self):
+ """Add this device to its parents"""
+
+ # a normal LV has only exactly parent -- the VG it belongs to
+ self._parents[0]._addLogVol(self)
def __repr__(self):
s = DMDevice.__repr__(self)
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/6b586972b2661026a006e361977605fecd0a88e2
More information about the anaconda-patches
mailing list