[PATCH 1/2] Move blivet.storageInitialize into pyanaconda.storage_utils.

David Lehman dlehman at redhat.com
Fri Jan 9 21:34:56 UTC 2015


Related: rhbz#1123450
---
 anaconda                                |  4 ++--
 pyanaconda/errors.py                    |  3 +++
 pyanaconda/rescue.py                    |  3 ++-
 pyanaconda/storage_utils.py             | 33 +++++++++++++++++++++++++++++++++
 pyanaconda/ui/gui/spokes/lib/refresh.py |  5 ++---
 5 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/anaconda b/anaconda
index 4ded503..a91e8a6 100755
--- a/anaconda
+++ b/anaconda
@@ -1270,7 +1270,7 @@ if __name__ == "__main__":
     signal.signal(signal.SIGUSR2, lambda signum, frame: anaconda.dumpState())
     atexit.register(exitHandler, ksdata.reboot, anaconda.storage)
 
-    from blivet import storageInitialize
+    from pyanaconda.storage_utils import initialize_storage
     from pyanaconda.packaging import payloadMgr
     from pyanaconda.timezone import time_initialize
 
@@ -1280,7 +1280,7 @@ if __name__ == "__main__":
         cleanPStore()
 
     if not flags.dirInstall:
-        threadMgr.add(AnacondaThread(name=constants.THREAD_STORAGE, target=storageInitialize,
+        threadMgr.add(AnacondaThread(name=constants.THREAD_STORAGE, target=initialize_storage,
                                      args=(anaconda.storage, ksdata, anaconda.protected)))
         threadMgr.add(AnacondaThread(name=constants.THREAD_TIME_INIT, target=time_initialize,
                                      args=(ksdata.timezone, anaconda.storage, anaconda.bootloader)))
diff --git a/pyanaconda/errors.py b/pyanaconda/errors.py
index 72c4488..a1671c6 100644
--- a/pyanaconda/errors.py
+++ b/pyanaconda/errors.py
@@ -63,6 +63,9 @@ class PasswordCryptError(Exception):
 class ZIPLError(Exception):
     pass
 
+class UnknownSourceDeviceError(Exception):
+    pass
+
 # These constants are returned by the callback in the ErrorHandler class.
 # Each represents a different kind of action the caller can take:
 #
diff --git a/pyanaconda/rescue.py b/pyanaconda/rescue.py
index 6702e2b..065c77e 100644
--- a/pyanaconda/rescue.py
+++ b/pyanaconda/rescue.py
@@ -35,6 +35,7 @@ from pyanaconda.flags import flags
 from pyanaconda.installinterfacebase import InstallInterfaceBase
 from pyanaconda.i18n import _
 from pyanaconda.kickstart import runPostScripts
+from pyanaconda.storage_utils import initialize_storage
 
 from blivet import mountExistingSystem
 from blivet.errors import StorageError
@@ -305,7 +306,7 @@ def doRescue(intf, rescue_mount, ksdata):
             break
 
     sto = blivet.Blivet(ksdata=ksdata)
-    blivet.storageInitialize(sto, ksdata, [])
+    initialize_storage(sto, ksdata, [])
     _unlock_devices(intf, sto)
     roots = blivet.findExistingInstallations(sto.devicetree)
 
diff --git a/pyanaconda/storage_utils.py b/pyanaconda/storage_utils.py
index d0906d3..ca24ecb 100644
--- a/pyanaconda/storage_utils.py
+++ b/pyanaconda/storage_utils.py
@@ -39,6 +39,8 @@ from blivet.devicefactory import DEVICE_TYPE_DISK
 from pyanaconda.i18n import _, N_
 from pyanaconda import isys
 from pyanaconda.constants import productName
+from pyanaconda.errors import UnknownSourceDeviceError
+from pyanaconda.flags import flags
 
 from pykickstart.constants import AUTOPART_TYPE_PLAIN, AUTOPART_TYPE_BTRFS
 from pykickstart.constants import AUTOPART_TYPE_LVM, AUTOPART_TYPE_LVM_THINP
@@ -90,6 +92,37 @@ AUTOPART_DEVICE_TYPES = {AUTOPART_TYPE_LVM: DEVICE_TYPE_LVM,
 NAMED_DEVICE_TYPES = (DEVICE_TYPE_BTRFS, DEVICE_TYPE_LVM, DEVICE_TYPE_MD, DEVICE_TYPE_LVM_THINP)
 CONTAINER_DEVICE_TYPES = (DEVICE_TYPE_LVM, DEVICE_TYPE_BTRFS, DEVICE_TYPE_LVM_THINP)
 
+def initialize_storage(storage, ksdata, protected):
+    """ Perform installer-specific storage initialization. """
+    from blivet.flags import flags as blivet_flags
+    blivet_flags.update_from_anaconda_flags(flags)
+
+    # Platform class setup depends on flags, re-initialize it.
+    _platform.update_from_flags()
+
+    storage.shutdown()
+
+    # Before we set up the storage system, we need to know which disks to
+    # ignore, etc.  Luckily that's all in the kickstart data.
+    storage.config.update(ksdata)
+
+    # Set up the protected partitions list now.
+    if protected:
+        storage.config.protectedDevSpecs.extend(protected)
+
+    storage.reset()
+
+    if protected and not flags.livecdInstall and \
+       not any(d.protected for d in storage.devices):
+        raise UnknownSourceDeviceError(protected)
+
+    # kickstart uses all the disks
+    if flags.automatedInstall:
+        if not ksdata.ignoredisk.onlyuse:
+            ksdata.ignoredisk.onlyuse = [d.name for d in storage.disks \
+                                         if d.name not in ksdata.ignoredisk.ignoredisk]
+            log.debug("onlyuse is now: %s", ",".join(ksdata.ignoredisk.onlyuse))
+
 def size_from_input(input_str, units=None):
     """ Get a Size object from an input string.
 
diff --git a/pyanaconda/ui/gui/spokes/lib/refresh.py b/pyanaconda/ui/gui/spokes/lib/refresh.py
index 396c38f..c2c3c91 100644
--- a/pyanaconda/ui/gui/spokes/lib/refresh.py
+++ b/pyanaconda/ui/gui/spokes/lib/refresh.py
@@ -24,8 +24,7 @@ from gi.repository import GLib
 from pyanaconda.threads import threadMgr, AnacondaThread
 from pyanaconda.ui.gui import GUIObject
 from pyanaconda import constants
-
-from blivet import storageInitialize
+from pyanaconda.storage_utils import initialize_storage
 
 __all__ = ["RefreshDialog"]
 
@@ -89,7 +88,7 @@ class RefreshDialog(GUIObject):
         self._notebook.set_current_page(1)
 
         # And now to fire up the storage reinitialization.
-        threadMgr.add(AnacondaThread(name=constants.THREAD_STORAGE, target=storageInitialize,
+        threadMgr.add(AnacondaThread(name=constants.THREAD_STORAGE, target=initialize_storage,
                                      args=(self.storage, self.data, self.storage.devicetree.protectedDevNames)))
 
         self._elapsed = 0
-- 
1.9.3



More information about the anaconda-patches mailing list