From 8cbd84aa93525ad58d3eeb4ddec5bd7861795d58 Mon Sep 17 00:00:00 2001
From: "Samantha N. Bueno" <sbueno+anaconda@redhat.com>
Date: Mon, 28 Mar 2016 15:27:19 -0400
Subject: [PATCH 1/7] Move some StorageDiscoveryConfig attrs into Blivet.

Move ignored_disks, exclusive_disks, and disk_images from
StorageDiscoveryConfig to Blivet class. This allows us to isolate
our dependence upon StorageDiscoveryConfig so we can later move it
into blivet.osinstall.

Update the devicetree function headers to take in these newly-moved
attrs. With this, we break devicetree dependence upon
StorageDiscoveryConfig.

Also update populator function headers to take in newly-moved attr.
With this, we also break populator dependence upon
StorageDiscoveryConfig.
---
 blivet/blivet.py              | 35 +++++++++++++++++++----------------
 blivet/devicetree.py          | 36 ++++++++++++++++++++++--------------
 blivet/populator/populator.py | 14 +++++++-------
 3 files changed, 48 insertions(+), 37 deletions(-)

diff --git a/blivet/blivet.py b/blivet/blivet.py
index 5d360dc..aefb410 100644
--- a/blivet/blivet.py
+++ b/blivet/blivet.py
@@ -79,14 +79,11 @@ class StorageDiscoveryConfig(object):
     def __init__(self):
         # storage configuration variables
         self.ignore_disk_interactive = False
-        self.ignored_disks = []
-        self.exclusive_disks = []
         self.clear_part_type = None
         self.clear_part_disks = []
         self.clear_part_devices = []
         self.initialize_disks = False
         self.protected_dev_specs = []
-        self.disk_images = {}
         self.zero_mbr = False
 
         # Whether clear_partitions removes scheduled/non-existent devices and
@@ -99,8 +96,6 @@ class StorageDiscoveryConfig(object):
             :param ksdata: kickstart data used as data source
             :type ksdata: :class:`pykickstart.Handler`
         """
-        self.ignored_disks = ksdata.ignoredisk.ignoredisk[:]
-        self.exclusive_disks = ksdata.ignoredisk.onlyuse[:]
         self.clear_part_type = ksdata.clearpart.type
         self.clear_part_disks = ksdata.clearpart.drives[:]
         self.clear_part_devices = ksdata.clearpart.devices[:]
@@ -135,6 +130,10 @@ class Blivet(object, metaclass=SynchronizedMeta):
         self.autopart_requests = []
         self.edd_dict = {}
 
+        self.ignored_disks = []
+        self.exclusive_disks = []
+        self.disk_images = {}
+
         self.__luks_devs = {}
         self.size_sets = []
         self.set_default_fstype(get_default_filesystem_type())
@@ -144,9 +143,11 @@ class Blivet(object, metaclass=SynchronizedMeta):
         self._dump_file = "%s/storage.state" % tempfile.gettempdir()
 
         # these will both be empty until our reset method gets called
-        self.devicetree = DeviceTree(conf=self.config,
-                                     passphrase=self.encryption_passphrase,
-                                     luks_dict=self.__luks_devs)
+        self.devicetree = DeviceTree(passphrase=self.encryption_passphrase,
+                                     luks_dict=self.__luks_devs,
+                                     ignored_disks=self.ignored_disks,
+                                     exclusive_disks=self.exclusive_disks,
+                                     disk_images=self.disk_images)
         self.fsset = FSSet(self.devicetree)
         self.roots = []
         self.services = set()
@@ -266,9 +267,11 @@ class Blivet(object, metaclass=SynchronizedMeta):
             fcoe.startup()
             zfcp.startup()
 
-        self.devicetree.reset(conf=self.config,
-                              passphrase=self.encryption_passphrase,
-                              luks_dict=self.__luks_devs)
+        self.devicetree.reset(passphrase=self.encryption_passphrase,
+                              luks_dict=self.__luks_devs,
+                              ignored_disks=self.ignored_disks,
+                              exclusive_disks=self.exclusive_disks,
+                              disk_images=self.disk_images)
         self.devicetree.populate(cleanup_only=cleanup_only)
         self.fsset = FSSet(self.devicetree)
         self.edd_dict = get_edd_dict(self.partitioned)
@@ -1330,7 +1333,7 @@ class Blivet(object, metaclass=SynchronizedMeta):
             self.devicetree.save_luks_passphrase(device)
 
     def setup_disk_images(self):
-        self.devicetree.set_disk_images(self.config.disk_images)
+        self.devicetree.set_disk_images(self.disk_images)
         self.devicetree.setup_disk_images()
 
     @property
@@ -1749,10 +1752,10 @@ class Blivet(object, metaclass=SynchronizedMeta):
         # bootloader
 
         # ignoredisk
-        if self.config.ignored_disks:
-            self.ksdata.ignoredisk.drives = self.config.ignored_disks[:]
-        elif self.config.exclusive_disks:
-            self.ksdata.ignoredisk.onlyuse = self.config.exclusive_disks[:]
+        if self.ignored_disks:
+            self.ksdata.ignoredisk.drives = self.ignored_disks[:]
+        elif self.exclusive_disks:
+            self.ksdata.ignoredisk.onlyuse = self.exclusive_disks[:]
 
         # autopart
         self.ksdata.autopart.autopart = self.do_autopart
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index 832dce5..edfa0bb 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -69,15 +69,23 @@ class DeviceTreeBase(object, metaclass=SynchronizedMeta):
         :class:`~.deviceaction.DeviceAction` instances can only be registered
         for leaf devices, except for resize actions.
     """
-    def __init__(self, conf=None):
+    def __init__(self, ignored_disks=None, exclusive_disks=None):
         """
-            :keyword conf: storage discovery configuration
-            :type conf: :class:`~.StorageDiscoveryConfig`
+            :keyword ignored_disks: ignored disks
+            :type ignored_disks: list
+            :keyword exclusive_disks: exclusive didks
+            :type exclusive_disks: list
         """
-        self.reset(conf)
+        self.reset(ignored_disks, exclusive_disks)
 
-    def reset(self, conf=None):
-        """ Reset the instance to its initial state. """
+    def reset(self, ignored_disks=None, exclusive_disks=None):
+        """ Reset the instance to its initial state.
+
+            :keyword ignored_disks: ignored disks
+            :type ignored_disks: list
+            :keyword exclusive_disks: exclusive didks
+            :type exclusive_disks: list
+        """
         # internal data members
         self._devices = []
         self._actions = ActionList(addfunc=self._register_action,
@@ -90,8 +98,8 @@ class DeviceTreeBase(object, metaclass=SynchronizedMeta):
 
         lvm.lvm_cc_resetFilter()
 
-        self.exclusive_disks = getattr(conf, "exclusive_disks", [])
-        self.ignored_disks = getattr(conf, "ignored_disks", [])
+        self.exclusive_disks= exclusive_disks
+        self.ignored_disks = ignored_disks
 
         self.edd_dict = {}
 
@@ -882,12 +890,12 @@ class DeviceTreeBase(object, metaclass=SynchronizedMeta):
 
 
 class DeviceTree(DeviceTreeBase, PopulatorMixin, EventHandlerMixin):
-    def __init__(self, conf=None, passphrase=None, luks_dict=None):
-        DeviceTreeBase.__init__(self, conf=conf)
-        PopulatorMixin.__init__(self, conf=conf, passphrase=passphrase, luks_dict=luks_dict)
+    def __init__(self, passphrase=None, luks_dict=None, ignored_disks=None, exclusive_disks=None, disk_images=None):
+        DeviceTreeBase.__init__(self, ignored_disks=ignored_disks, exclusive_disks=exclusive_disks)
+        PopulatorMixin.__init__(self, passphrase=passphrase, luks_dict=luks_dict, disk_images=disk_images)
         EventHandlerMixin.__init__(self)
 
     # pylint: disable=arguments-differ
-    def reset(self, conf=None, passphrase=None, luks_dict=None):
-        DeviceTreeBase.reset(self, conf=conf)
-        PopulatorMixin.reset(self, conf=conf, passphrase=passphrase, luks_dict=luks_dict)
+    def reset(self, passphrase=None, luks_dict=None, ignored_disks=None, exclusive_disks=None, disk_images=None):
+        DeviceTreeBase.reset(self, ignored_disks=ignored_disks, exclusive_disks=exclusive_disks)
+        PopulatorMixin.reset(self, passphrase=passphrase, luks_dict=luks_dict, disk_images=disk_images)
diff --git a/blivet/populator/populator.py b/blivet/populator/populator.py
index 816c226..54fd53e 100644
--- a/blivet/populator/populator.py
+++ b/blivet/populator/populator.py
@@ -63,23 +63,23 @@ def parted_exn_handler(exn_type, exn_options, exn_msg):
 
 
 class PopulatorMixin(object, metaclass=SynchronizedMeta):
-    def __init__(self, conf=None, passphrase=None, luks_dict=None):
+    def __init__(self, passphrase=None, luks_dict=None, disk_images=None):
         """
-            :keyword conf: storage discovery configuration
-            :type conf: :class:`~.StorageDiscoveryConfig`
             :keyword passphrase: default LUKS passphrase
             :keyword luks_dict: a dict with UUID keys and passphrase values
             :type luks_dict: dict
+            :keyword disk_images: dictoinary of disk images
+            :type list: dict
 
         """
-        self.reset(conf=conf, passphrase=passphrase, luks_dict=luks_dict)
+        self.reset(passphrase=passphrase, luks_dict=luks_dict, disk_images=disk_images)
 
     def reset(self, conf=None, passphrase=None, luks_dict=None):
+    def reset(self, passphrase=None, luks_dict=None, disk_images=None):
         self.disk_images = {}
-        images = getattr(conf, "disk_images", {})
-        if images:
+        if disk_images:
             # this will overwrite self.exclusive_disks
-            self.set_disk_images(images)
+            self.set_disk_images(disk_images)
 
         # protected device specs as provided by the user
         self.protected_dev_specs = getattr(conf, "protected_dev_specs", [])
-- 
2.7.4

