[master 22/27] Convert Populator to a mixin class.
by dashea
From: David Lehman <dlehman(a)redhat.com>
This seems like a better way of handling the tight coupling of
DeviceTree and Populator.
---
blivet/devicetree.py | 149 ++++------------------------
blivet/populator/__init__.py | 2 +-
blivet/populator/helpers/btrfs.py | 6 +-
blivet/populator/helpers/disk.py | 10 +-
blivet/populator/helpers/dm.py | 6 +-
blivet/populator/helpers/dmraid.py | 6 +-
blivet/populator/helpers/formatpopulator.py | 6 +-
blivet/populator/helpers/loop.py | 8 +-
blivet/populator/helpers/luks.py | 14 +--
blivet/populator/helpers/lvm.py | 40 ++++----
blivet/populator/helpers/mdraid.py | 14 +--
blivet/populator/helpers/multipath.py | 4 +-
blivet/populator/helpers/optical.py | 2 +-
blivet/populator/helpers/partition.py | 12 +--
blivet/populator/helpers/populatorhelper.py | 6 +-
blivet/populator/populator.py | 84 ++++++++++------
tests/populator_test.py | 135 +++++++++++++------------
17 files changed, 205 insertions(+), 299 deletions(-)
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index 9afadad..fb9b146 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -1,7 +1,7 @@
# devicetree.py
# Device management for anaconda's storage configuration module.
#
-# Copyright (C) 2009-2014 Red Hat, Inc.
+# Copyright (C) 2009-2015 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
@@ -35,11 +35,8 @@
from .devices import LVMLogicalVolumeDevice, LVMVolumeGroupDevice
from . import formats, arch
from .devicelibs import lvm
-from . import udev
from . import util
-from .util import open # pylint: disable=redefined-builtin
-from .flags import flags
-from .populator import Populator
+from .populator import PopulatorMixin
from .storage_log import log_method_call, log_method_return
import logging
@@ -48,7 +45,7 @@
_LVM_DEVICE_CLASSES = (LVMLogicalVolumeDevice, LVMVolumeGroupDevice)
-class DeviceTree(object):
+class DeviceTreeBase(object):
""" A quasi-tree that represents the devices in the system.
@@ -69,25 +66,14 @@ class DeviceTree(object):
for leaf devices, except for resize actions.
"""
- def __init__(self, conf=None, passphrase=None, luks_dict=None,
- iscsi=None, dasd=None):
+ def __init__(self, conf=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 iscsi: ISCSI control object
- :type iscsi: :class:`~.iscsi.iscsi`
- :keyword dasd: DASD control object
- :type dasd: :class:`~.dasd.DASD`
-
"""
- self.reset(conf, passphrase, luks_dict, iscsi, dasd)
+ self.reset(conf)
- def reset(self, conf=None, passphrase=None, luks_dict=None,
- iscsi=None, dasd=None):
+ def reset(self, conf=None):
""" Reset the instance to its initial state. """
# internal data members
self._devices = []
@@ -106,13 +92,6 @@ def reset(self, conf=None, passphrase=None, luks_dict=None,
self.edd_dict = {}
- self._populator = Populator(self,
- conf=conf,
- passphrase=passphrase,
- luks_dict=luks_dict,
- iscsi=iscsi,
- dasd=dasd)
-
def __str__(self):
done = []
@@ -326,62 +305,6 @@ def _cancel_action(self, action):
self._add_device(action.device, new=False)
#
- # Device detection
- #
- def populate(self, cleanup_only=False):
- """ Locate all storage devices.
-
- Everything should already be active. We just go through and gather
- details as needed and set up the relations between various devices.
-
- Devices excluded via disk filtering (or because of disk images) are
- scanned just the rest, but then they are hidden at the end of this
- process.
- """
- udev.settle()
- try:
- self._populator.populate(cleanup_only=cleanup_only)
- except Exception:
- raise
- finally:
- self._hide_ignored_disks()
-
- if flags.installer_mode:
- self.teardown_all()
-
- def update_format(self, device):
- return self._populator.update_format(device)
-
- def handle_nodev_filesystems(self):
- for line in open("/proc/mounts").readlines():
- try:
- (_devspec, mountpoint, fstype, _options, _rest) = line.split(None, 4)
- except ValueError:
- log.error("failed to parse /proc/mounts line: %s", line)
- continue
- if fstype in formats.fslib.nodev_filesystems:
- if not flags.include_nodev:
- continue
-
- log.info("found nodev %s filesystem mounted at %s",
- fstype, mountpoint)
- # nodev filesystems require some special handling.
- # For now, a lot of this is based on the idea that it's a losing
- # battle to require the presence of an FS class for every type
- # of nodev filesystem. Based on that idea, we just instantiate
- # NoDevFS directly and then hack in the fstype as the device
- # attribute.
- fmt = formats.get_format("nodev")
- fmt.device = fstype
-
- # NoDevice also needs some special works since they don't have
- # per-instance names in the kernel.
- device = NoDevice(fmt=fmt)
- n = len([d for d in self.devices if d.format.type == fstype])
- device._name += ".%d" % n
- self._add_device(device)
-
- #
# Device control
#
def teardown_all(self):
@@ -963,6 +886,7 @@ def hide(self, device):
lvm.lvm_cc_addFilterRejectRegexp(device.name)
if isinstance(device, DASDDevice):
+ # pylint: disable=no-member
self.dasd.remove(device)
if device.name not in self.names:
@@ -994,6 +918,7 @@ def unhide(self, device):
hidden.add_hook(new=False)
lvm.lvm_cc_removeFilterRejectRegexp(hidden.name)
if isinstance(device, DASDDevice):
+ # pylint: disable=no-member
self.dasd.append(device)
def _is_ignored_disk(self, disk):
@@ -1016,54 +941,14 @@ def _hide_ignored_disks(self):
if ignored:
self.hide(disk)
- #
- # Disk images
- #
- def set_disk_images(self, images):
- """ Set the disk images and reflect them in exclusive_disks.
-
- :param images: dict with image name keys and filename values
- :type images: dict
-
- .. note::
-
- Disk images are automatically exclusive. That means that, in the
- presence of disk images, any local storage not associated with
- the disk images is ignored.
- """
- self._populator.set_disk_images(images)
-
- def setup_disk_images(self):
- """ Set up devices to represent the disk image files. """
- self._populator.setup_disk_images()
-
- def teardown_disk_images(self):
- """ Tear down any disk image stacks. """
- # teardown all devices first so that there's nothing active running on
- # top of disk images when we try to tear those down
- self.teardown_all()
- self._populator.teardown_disk_images()
-
- @property
- def disk_images(self):
- return self._populator.disk_images
-
- #
- # Miscellaneous (global) data
- #
- @property
- def dasd(self):
- return self._populator.dasd
-
- @dasd.setter
- def dasd(self, dasd):
- self._populator.dasd = dasd
-
- @property
- def protected_dev_names(self):
- return self._populator.protected_dev_names
- def save_luks_passphrase(self, device):
- """ Save a device's LUKS passphrase in case of reset. """
+class DeviceTree(DeviceTreeBase, PopulatorMixin):
+ def __init__(self, conf=None, passphrase=None, luks_dict=None, iscsi=None, dasd=None):
+ DeviceTreeBase.__init__(self, conf=conf)
+ PopulatorMixin.__init__(self, passphrase=passphrase, luks_dict=luks_dict, iscsi=iscsi, dasd=dasd)
- self._populator.save_luks_passphrase(device)
+ # pylint: disable=arguments-differ
+ def reset(self, conf=None, passphrase=None, luks_dict=None, iscsi=None, dasd=None):
+ DeviceTreeBase.reset(self, conf=conf)
+ PopulatorMixin.reset(self, conf=conf, passphrase=passphrase, luks_dict=luks_dict,
+ iscsi=iscsi, dasd=dasd)
diff --git a/blivet/populator/__init__.py b/blivet/populator/__init__.py
index bde09c1..da6ddb2 100644
--- a/blivet/populator/__init__.py
+++ b/blivet/populator/__init__.py
@@ -1 +1 @@
-from .populator import Populator
+from .populator import PopulatorMixin
diff --git a/blivet/populator/helpers/btrfs.py b/blivet/populator/helpers/btrfs.py
index b93e262..fecbbca 100644
--- a/blivet/populator/helpers/btrfs.py
+++ b/blivet/populator/helpers/btrfs.py
@@ -47,7 +47,7 @@ def run(self):
uuid = udev.device_get_uuid(self.data)
btrfs_dev = None
- for d in self._populator.devicetree.devices:
+ for d in self._devicetree.devices:
if isinstance(d, BTRFSVolumeDevice) and d.uuid == uuid:
btrfs_dev = d
break
@@ -60,7 +60,7 @@ def run(self):
log.info("creating btrfs volume btrfs.%s", label)
btrfs_dev = BTRFSVolumeDevice(label, parents=[self.device], uuid=uuid,
exists=True)
- self._populator.devicetree._add_device(btrfs_dev)
+ self._devicetree._add_device(btrfs_dev)
if not btrfs_dev.subvolumes:
snapshots = btrfs_dev.list_subvolumes(snapshots_only=True)
@@ -101,4 +101,4 @@ def run(self):
fmt=fmt,
parents=[parent],
exists=True)
- self._populator.devicetree._add_device(subvol)
+ self._devicetree._add_device(subvol)
diff --git a/blivet/populator/helpers/disk.py b/blivet/populator/helpers/disk.py
index 98642af..fb93721 100644
--- a/blivet/populator/helpers/disk.py
+++ b/blivet/populator/helpers/disk.py
@@ -73,9 +73,9 @@ def run(self):
kwargs = self._get_kwargs()
device = self._device_class(name, **kwargs)
if self._device_class == DASDDevice:
- self._populator.dasd.append(device)
+ self._devicetree.dasd.append(device)
- self._populator.devicetree._add_device(device)
+ self._devicetree._add_device(device)
return device
@@ -150,7 +150,7 @@ def _get_kwargs(self):
kwargs = super()._get_kwargs()
parent_path = udev.device_get_md_container(self.data)
parent_name = device_path_to_name(parent_path)
- container = self._populator.devicetree.get_device_by_name(parent_name)
+ container = self._devicetree.get_device_by_name(parent_name)
# FIXME: Move this whole block to an add_parent_devices method or similar
if not container:
@@ -162,8 +162,8 @@ def _get_kwargs(self):
parent_name, container_sysfs)
return
- self._populator.handle_device(container_info)
- container = self._populator.devicetree.get_device_by_name(parent_name)
+ self._devicetree.handle_device(container_info)
+ container = self._devicetree.get_device_by_name(parent_name)
if not container:
log.error("failed to scan md container %s", parent_name)
return
diff --git a/blivet/populator/helpers/dm.py b/blivet/populator/helpers/dm.py
index 2e90d68..9143611 100644
--- a/blivet/populator/helpers/dm.py
+++ b/blivet/populator/helpers/dm.py
@@ -45,8 +45,8 @@ def run(self):
name = udev.device_get_name(self.data)
log_method_call(self, name=name)
sysfs_path = udev.device_get_sysfs_path(self.data)
- slave_devices = self._populator._add_slave_devices(self.data)
- device = self._populator.devicetree.get_device_by_name(name)
+ slave_devices = self._devicetree._add_slave_devices(self.data)
+ device = self._devicetree.get_device_by_name(name)
# create a device for the livecd OS image(s)
if device is None and udev.device_is_dm_livecd(self.data):
@@ -55,7 +55,7 @@ def run(self):
parents=[slave_devices[0]])
device.protected = True
device.controllable = False
- self._populator.devicetree._add_device(device)
+ self._devicetree._add_device(device)
# if we get here, we found all of the slave devices and
# something must be wrong -- if all of the slaves are in
diff --git a/blivet/populator/helpers/dmraid.py b/blivet/populator/helpers/dmraid.py
index 7e30502..24d5139 100644
--- a/blivet/populator/helpers/dmraid.py
+++ b/blivet/populator/helpers/dmraid.py
@@ -60,7 +60,7 @@ def run(self):
return
for rs_name in rs_names:
- dm_array = self._populator.devicetree.get_device_by_name(rs_name, incomplete=True)
+ dm_array = self._devicetree.get_device_by_name(rs_name, incomplete=True)
if dm_array is not None:
# We add the new device.
dm_array.parents.append(self.device)
@@ -70,7 +70,7 @@ def run(self):
dm_array = DMRaidArrayDevice(rs_name,
parents=[self.device])
- self._populator.devicetree._add_device(dm_array)
+ self._devicetree._add_device(dm_array)
# Wait for udev to scan the just created nodes, to avoid a race
# with the udev.get_device() call below.
@@ -80,4 +80,4 @@ def run(self):
# its partitions get scanned before it does.
dm_array.update_sysfs_path()
dm_array_info = udev.get_device(dm_array.sysfs_path)
- self._populator.handle_device(dm_array_info, update_orig_fmt=True)
+ self._devicetree.handle_device(dm_array_info, update_orig_fmt=True)
diff --git a/blivet/populator/helpers/formatpopulator.py b/blivet/populator/helpers/formatpopulator.py
index 6eb0ffc..b65a37f 100644
--- a/blivet/populator/helpers/formatpopulator.py
+++ b/blivet/populator/helpers/formatpopulator.py
@@ -34,14 +34,14 @@ class FormatPopulator(PopulatorHelper):
priority = 0
_type_specifier = None
- def __init__(self, populator, data, device):
+ def __init__(self, devicetree, data, device):
"""
- :param :class:`~.Populator` populator: the calling populator
+ :param :class:`blivet.devicetree.DeviceTree` devicetree: the calling devicetree
:param :class:`pyudev.Device` data: udev data describing a device
:param device: device instance corresponding to the udev data
:type device: :class:`~.devices.StorageDevice`
"""
- super().__init__(populator, data)
+ super().__init__(devicetree, data)
self.device = device
@classmethod
diff --git a/blivet/populator/helpers/loop.py b/blivet/populator/helpers/loop.py
index c723b8f..27c33b3 100644
--- a/blivet/populator/helpers/loop.py
+++ b/blivet/populator/helpers/loop.py
@@ -41,18 +41,18 @@ def run(self):
log_method_call(self, name=name)
sysfs_path = udev.device_get_sysfs_path(self.data)
backing_file = blockdev.loop.get_backing_file(name)
- file_device = self._populator.devicetree.get_device_by_name(backing_file)
+ file_device = self._devicetree.get_device_by_name(backing_file)
if not file_device:
file_device = FileDevice(backing_file, exists=True)
- self._populator.devicetree._add_device(file_device)
+ self._devicetree._add_device(file_device)
device = LoopDevice(name,
parents=[file_device],
sysfs_path=sysfs_path,
exists=True)
- if not self._populator._cleanup or file_device not in self._populator.disk_images.values():
+ if not self._devicetree._cleanup or file_device not in self._devicetree.disk_images.values():
# don't allow manipulation of loop devices other than those
# associated with disk images, and then only during cleanup
file_device.controllable = False
device.controllable = False
- self._populator.devicetree._add_device(device)
+ self._devicetree._add_device(device)
return device
diff --git a/blivet/populator/helpers/luks.py b/blivet/populator/helpers/luks.py
index a06a739..c0deaed 100644
--- a/blivet/populator/helpers/luks.py
+++ b/blivet/populator/helpers/luks.py
@@ -51,16 +51,16 @@ def run(self):
return
# look up or create the mapped device
- if not self._populator.devicetree.get_device_by_name(self.device.format.map_name):
- passphrase = self._populator._Populator__luks_devs.get(self.device.format.uuid)
+ if not self._devicetree.get_device_by_name(self.device.format.map_name):
+ passphrase = self._devicetree._Populator__luks_devs.get(self.device.format.uuid)
if self.device.format.configured:
pass
elif passphrase:
self.device.format.passphrase = passphrase
- elif self.device.format.uuid in self._populator._Populator__luks_devs:
+ elif self.device.format.uuid in self._devicetree._Populator__luks_devs:
log.info("skipping previously-skipped luks device %s",
self.device.name)
- elif self._populator._cleanup or flags.testing:
+ elif self._devicetree._cleanup or flags.testing:
# if we're only building the devicetree so that we can
# tear down all of the devices we don't need a passphrase
if self.device.format.status:
@@ -71,7 +71,7 @@ def run(self):
# passphrase has been set for a specific device without a full
# reset/populate, in which case the new passphrase would not be
# in self.__passphrases.
- passphrases = self._populator._Populator__passphrases + list(self._populator._Populator__luks_devs.values())
+ passphrases = self._devicetree._Populator__passphrases + list(self._devicetree._Populator__luks_devs.values())
for passphrase in passphrases:
self.device.format.passphrase = passphrase
try:
@@ -91,13 +91,13 @@ def run(self):
self.device.remove_child()
else:
luks_device.update_sysfs_path()
- self._populator.devicetree._add_device(luks_device)
+ self._devicetree._add_device(luks_device)
luks_info = udev.get_device(luks_device.sysfs_path)
if not luks_info:
log.error("failed to get udev data for %s", luks_device.name)
return
- self._populator.handle_device(luks_info, update_orig_fmt=True)
+ self._devicetree.handle_device(luks_info, update_orig_fmt=True)
else:
log.warning("luks device %s already in the tree",
self.device.format.map_name)
diff --git a/blivet/populator/helpers/lvm.py b/blivet/populator/helpers/lvm.py
index 377a7a8..8681df2 100644
--- a/blivet/populator/helpers/lvm.py
+++ b/blivet/populator/helpers/lvm.py
@@ -51,21 +51,21 @@ def run(self):
log_method_call(self, name=name)
vg_name = udev.device_get_lv_vg_name(self.data)
- device = self._populator.devicetree.get_device_by_name(vg_name, hidden=True)
+ device = self._devicetree.get_device_by_name(vg_name, hidden=True)
if device and not isinstance(device, LVMVolumeGroupDevice):
log.warning("found non-vg device with name %s", vg_name)
device = None
- self._populator._add_slave_devices(self.data)
+ self._devicetree._add_slave_devices(self.data)
# LVM provides no means to resolve conflicts caused by duplicated VG
# names, so we're just being optimistic here. Woo!
vg_name = udev.device_get_lv_vg_name(self.data)
- vg_device = self._populator.devicetree.get_device_by_name(vg_name)
+ vg_device = self._devicetree.get_device_by_name(vg_name)
if not vg_device:
log.error("failed to find vg '%s' after scanning pvs", vg_name)
- return self._populator.devicetree.get_device_by_name(name)
+ return self._devicetree.get_device_by_name(name)
class LVMFormatPopulator(FormatPopulator):
@@ -75,7 +75,7 @@ class LVMFormatPopulator(FormatPopulator):
def _get_kwargs(self):
kwargs = super()._get_kwargs()
- pv_info = self._populator.pv_info.get(self.device.path, None)
+ pv_info = self._devicetree.pv_info.get(self.device.path, None)
name = udev.device_get_name(self.data)
if pv_info:
if pv_info.vg_name:
@@ -96,10 +96,10 @@ def _get_kwargs(self):
def _handle_vg_lvs(self, vg_device):
""" Handle setup of the LV's in the vg_device. """
vg_name = vg_device.name
- lv_info = dict((k, v) for (k, v) in iter(self._populator.lv_info.items())
+ lv_info = dict((k, v) for (k, v) in iter(self._devicetree.lv_info.items())
if v.vg_name == vg_name)
- self._populator.names.extend(n for n in lv_info.keys() if n not in self._populator.names)
+ self._devicetree.names.extend(n for n in lv_info.keys() if n not in self._devicetree.names)
if not vg_device.complete:
log.warning("Skipping LVs for incomplete VG %s", vg_name)
@@ -126,12 +126,12 @@ def add_required_lv(name, msg):
:raises: :class:`~.errors.DeviceTreeError` on failure
"""
- vol = self._populator.devicetree.get_device_by_name(name)
+ vol = self._devicetree.get_device_by_name(name)
if vol is None:
new_lv = add_lv(lv_info[name])
if new_lv:
all_lvs.append(new_lv)
- vol = self._populator.devicetree.get_device_by_name(name)
+ vol = self._devicetree.get_device_by_name(name)
if vol is None:
log.error("%s: %s", msg, name)
@@ -150,7 +150,7 @@ def add_lv(lv):
lv_kwargs = {}
name = "%s-%s" % (vg_name, lv_name)
- if self._populator.devicetree.get_device_by_name(name):
+ if self._devicetree.get_device_by_name(name):
# some lvs may have been added on demand below
log.debug("already added %s", name)
return
@@ -170,7 +170,7 @@ def add_lv(lv):
origin_device_name = "%s-%s" % (vg_name, origin_name)
add_required_lv(origin_device_name,
"failed to locate origin lv")
- origin = self._populator.devicetree.get_device_by_name(origin_device_name)
+ origin = self._devicetree.get_device_by_name(origin_device_name)
lv_kwargs["origin"] = origin
lv_class = LVMSnapShotDevice
@@ -196,13 +196,13 @@ def add_lv(lv):
if origin_name:
origin_device_name = "%s-%s" % (vg_name, origin_name)
add_required_lv(origin_device_name, "failed to locate origin lv")
- origin = self._populator.devicetree.get_device_by_name(origin_device_name)
+ origin = self._devicetree.get_device_by_name(origin_device_name)
lv_kwargs["origin"] = origin
lv_class = LVMThinSnapShotDevice
else:
lv_class = LVMThinLogicalVolumeDevice
- lv_parents = [self._populator.devicetree.get_device_by_name(pool_device_name)]
+ lv_parents = [self._devicetree.get_device_by_name(pool_device_name)]
elif lv_name.endswith(']'):
# unrecognized Internal LVM2 device
return
@@ -218,12 +218,12 @@ def add_lv(lv):
# C cached LV
return
- lv_dev = self._populator.devicetree.get_device_by_uuid(lv_uuid)
+ lv_dev = self._devicetree.get_device_by_uuid(lv_uuid)
if lv_dev is None:
lv_device = lv_class(lv_name, parents=lv_parents,
uuid=lv_uuid, size=lv_size, seg_type=lv_type,
exists=True, **lv_kwargs)
- self._populator.devicetree._add_device(lv_device)
+ self._devicetree._add_device(lv_device)
if flags.installer_mode:
lv_device.setup()
@@ -236,7 +236,7 @@ def add_lv(lv):
return lv_device
# do format handling now
- self._populator.handle_device(lv_info, update_orig_fmt=True)
+ self._devicetree.handle_device(lv_info, update_orig_fmt=True)
return lv_device
@@ -308,7 +308,7 @@ def create_internal_lv(lv):
def run(self):
super().run()
- pv_info = self._populator.pv_info.get(self.device.path, None)
+ pv_info = self._devicetree.pv_info.get(self.device.path, None)
if pv_info:
vg_name = pv_info.vg_name
vg_uuid = pv_info.vg_uuid
@@ -320,11 +320,11 @@ def run(self):
log.info("lvm pv %s has no vg", self.device.name)
return
- vg_device = self._populator.devicetree.get_device_by_uuid(vg_uuid, incomplete=True)
+ vg_device = self._devicetree.get_device_by_uuid(vg_uuid, incomplete=True)
if vg_device:
vg_device.parents.append(self.device)
else:
- same_name = self._populator.devicetree.get_device_by_name(vg_name)
+ same_name = self._devicetree.get_device_by_name(vg_name)
if isinstance(same_name, LVMVolumeGroupDevice):
raise DuplicateVGError("multiple LVM volume groups with the same name (%s)" % vg_name)
@@ -349,6 +349,6 @@ def run(self):
pe_free=pe_free,
pv_count=pv_count,
exists=True)
- self._populator.devicetree._add_device(vg_device)
+ self._devicetree._add_device(vg_device)
self._handle_vg_lvs(vg_device)
diff --git a/blivet/populator/helpers/mdraid.py b/blivet/populator/helpers/mdraid.py
index 7047016..22df189 100644
--- a/blivet/populator/helpers/mdraid.py
+++ b/blivet/populator/helpers/mdraid.py
@@ -51,10 +51,10 @@ def run(self):
name = udev.device_get_md_name(self.data)
log_method_call(self, name=name)
- self._populator._add_slave_devices(self.data)
+ self._devicetree._add_slave_devices(self.data)
# try to get the device again now that we've got all the slaves
- device = self._populator.devicetree.get_device_by_name(name, incomplete=flags.allow_imperfect_devices)
+ device = self._devicetree.get_device_by_name(name, incomplete=flags.allow_imperfect_devices)
if device is None:
try:
@@ -62,7 +62,7 @@ def run(self):
except KeyError:
log.warning("failed to obtain uuid for mdraid device")
else:
- device = self._populator.devicetree.get_device_by_uuid(uuid, incomplete=flags.allow_imperfect_devices)
+ device = self._devicetree.get_device_by_uuid(uuid, incomplete=flags.allow_imperfect_devices)
if device and name:
# update the device instance with the real name in case we had to
@@ -114,7 +114,7 @@ def run(self):
# Use mdadm info if udev info is missing
md_uuid = md_info.uuid
self.device.format.md_uuid = self.device.format.md_uuid or md_uuid
- md_array = self._populator.devicetree.get_device_by_uuid(self.device.format.md_uuid, incomplete=True)
+ md_array = self._devicetree.get_device_by_uuid(self.device.format.md_uuid, incomplete=True)
if md_array:
md_array.parents.append(self.device)
@@ -162,7 +162,7 @@ def run(self):
md_name = md_name[2:]
if md_name:
- array = self._populator.devicetree.get_device_by_name(md_name, incomplete=True)
+ array = self._devicetree.get_device_by_name(md_name, incomplete=True)
if array and array.uuid != md_uuid:
log.error("found multiple devices with the name %s", md_name)
@@ -197,11 +197,11 @@ def run(self):
md_array.update_sysfs_path()
md_array.parents.append(self.device)
- self._populator.devicetree._add_device(md_array)
+ self._devicetree._add_device(md_array)
if md_array.status:
array_info = udev.get_device(md_array.sysfs_path)
if not array_info:
log.error("failed to get udev data for %s", md_array.name)
return
- self._populator.handle_device(array_info, update_orig_fmt=True)
+ self._devicetree.handle_device(array_info, update_orig_fmt=True)
diff --git a/blivet/populator/helpers/multipath.py b/blivet/populator/helpers/multipath.py
index 8405cec..177ccd1 100644
--- a/blivet/populator/helpers/multipath.py
+++ b/blivet/populator/helpers/multipath.py
@@ -41,7 +41,7 @@ def run(self):
name = udev.device_get_name(self.data)
log_method_call(self, name=name)
- slave_devices = self._populator._add_slave_devices(self.data)
+ slave_devices = self._devicetree._add_slave_devices(self.data)
device = None
if slave_devices:
@@ -54,7 +54,7 @@ def run(self):
device = MultipathDevice(name, parents=slave_devices,
sysfs_path=udev.device_get_sysfs_path(self.data),
serial=serial)
- self._populator.devicetree._add_device(device)
+ self._devicetree._add_device(device)
return device
diff --git a/blivet/populator/helpers/optical.py b/blivet/populator/helpers/optical.py
index c0466bf..1ffec42 100644
--- a/blivet/populator/helpers/optical.py
+++ b/blivet/populator/helpers/optical.py
@@ -42,5 +42,5 @@ def run(self):
sysfs_path=udev.device_get_sysfs_path(self.data),
vendor=udev.device_get_vendor(self.data),
model=udev.device_get_model(self.data))
- self._populator.devicetree._add_device(device)
+ self._devicetree._add_device(device)
return device
diff --git a/blivet/populator/helpers/partition.py b/blivet/populator/helpers/partition.py
index 3709599..4af23d7 100644
--- a/blivet/populator/helpers/partition.py
+++ b/blivet/populator/helpers/partition.py
@@ -51,21 +51,21 @@ def run(self):
if name.startswith("md"):
name = blockdev.md.name_from_node(name)
- device = self._populator.devicetree.get_device_by_name(name)
+ device = self._devicetree.get_device_by_name(name)
if device:
return device
disk_name = udev.device_get_partition_disk(self.data)
if disk_name.startswith("md"):
disk_name = blockdev.md.name_from_node(disk_name)
- disk = self._populator.devicetree.get_device_by_name(disk_name)
+ disk = self._devicetree.get_device_by_name(disk_name)
if disk is None:
# create a device instance for the disk
new_info = udev.get_device(os.path.dirname(sysfs_path))
if new_info:
- self._populator.handle_device(new_info)
- disk = self._populator.devicetree.get_device_by_name(disk_name)
+ self._devicetree.handle_device(new_info)
+ disk = self._devicetree.get_device_by_name(disk_name)
if disk is None:
# if the current device is still not in
@@ -83,7 +83,7 @@ def run(self):
if disk.partitionable and \
disk.format.type != "iso9660" and \
not disk.format.hidden and \
- not self._populator.devicetree._is_ignored_disk(disk):
+ not self._devicetree._is_ignored_disk(disk):
if self.data.get("ID_PART_TABLE_TYPE") == "gpt":
msg = "corrupt gpt disklabel on disk %s" % disk.name
cls = CorruptGPTError
@@ -117,5 +117,5 @@ def run(self):
log.error("Failed to instantiate PartitionDevice: %s", e)
return
- self._populator.devicetree._add_device(device)
+ self._devicetree._add_device(device)
return device
diff --git a/blivet/populator/helpers/populatorhelper.py b/blivet/populator/helpers/populatorhelper.py
index 5d1b66d..fc7cbe8 100644
--- a/blivet/populator/helpers/populatorhelper.py
+++ b/blivet/populator/helpers/populatorhelper.py
@@ -27,12 +27,12 @@ class PopulatorHelper:
priority = 100
""" Higher priority value gets checked for match first. """
- def __init__(self, populator, data):
+ def __init__(self, devicetree, data):
"""
- :param :class:`~.Populator` populator: the calling populator
+ :param :class:`~.DeviceTree` devicetree: the calling devicetree
:param :class:`pyudev.Device` data: udev data describing a device
"""
- self._populator = populator
+ self._devicetree = devicetree
self.data = data
@classmethod
diff --git a/blivet/populator/populator.py b/blivet/populator/populator.py
index d529053..7f2c243 100644
--- a/blivet/populator/populator.py
+++ b/blivet/populator/populator.py
@@ -35,7 +35,9 @@
from ..devices import FileDevice, LoopDevice
from ..devices import MDRaidArrayDevice
from ..devices import MultipathDevice
+from ..devices import NoDevice
from ..devicelibs import lvm
+from .. import formats
from .. import udev
from .. import util
from ..util import open # pylint: disable=redefined-builtin
@@ -60,10 +62,8 @@ def parted_exn_handler(exn_type, exn_options, exn_msg):
return ret
-class Populator(object):
-
- def __init__(self, devicetree=None, conf=None, passphrase=None,
- luks_dict=None, iscsi=None, dasd=None):
+class PopulatorMixin(object):
+ def __init__(self, conf=None, passphrase=None, luks_dict=None, iscsi=None, dasd=None):
"""
:keyword conf: storage discovery configuration
:type conf: :class:`~.StorageDiscoveryConfig`
@@ -76,8 +76,9 @@ def __init__(self, devicetree=None, conf=None, passphrase=None,
:type dasd: :class:`~.dasd.DASD`
"""
- self.devicetree = devicetree
+ self.reset(conf=conf, passphrase=passphrase, luks_dict=luks_dict, iscsi=iscsi, dasd=dasd)
+ def reset(self, conf=None, passphrase=None, luks_dict=None, iscsi=None, dasd=None):
# indicates whether or not the tree has been fully populated
self.populated = False
@@ -97,8 +98,6 @@ def __init__(self, devicetree=None, conf=None, passphrase=None,
# names of protected devices at the time of tree population
self.protected_dev_names = []
- self.unused_raid_members = []
-
self.__passphrases = []
if passphrase:
self.__passphrases.append(passphrase)
@@ -172,7 +171,7 @@ def _add_slave_devices(self, info):
slave_dev = self.get_device_by_name(slave_name)
if slave_dev is None:
if udev.device_is_dm_lvm(info):
- if slave_name not in self.devicetree.lv_info:
+ if slave_name not in self.lv_info:
# we do not expect hidden lvs to be in the tree
continue
@@ -197,9 +196,9 @@ def _reason_to_skip_device(self, info):
# make sure this device was not scheduled for removal and also has not
# been hidden
- removed = [a.device for a in self.devicetree.actions.find(action_type="destroy",
- object_type="device")]
- for ignored in removed + self.devicetree._hidden:
+ removed = [a.device for a in self.actions.find(action_type="destroy",
+ object_type="device")]
+ for ignored in removed + self._hidden:
if (sysfs_path and ignored.sysfs_path == sysfs_path) or \
(uuid and uuid in (ignored.uuid, ignored.format.uuid)):
if ignored in removed:
@@ -249,8 +248,8 @@ def _clear_new_multipath_member(self, device):
if device.format and device.format.type != "multipath_member":
log.debug("%s newly detected as multipath member, dropping old format and removing kids", device.name)
# remove children from tree so that we don't stumble upon them later
- for child in self.devicetree.get_children(device):
- self.devicetree.recursive_remove(child, actions=False)
+ for child in self.get_children(device):
+ self.recursive_remove(child, actions=False)
device.format = None
@@ -277,10 +276,10 @@ def _update_exclusive_disks(self, device):
# we have to make sure all of its members are in the list too.
mdclasses = (DMRaidArrayDevice, MDRaidArrayDevice, MultipathDevice)
if device.is_disk and isinstance(device, mdclasses):
- if device.name in self.devicetree.exclusive_disks:
+ if device.name in self.exclusive_disks:
for parent in device.parents:
- if parent.name not in self.devicetree.exclusive_disks:
- self.devicetree.exclusive_disks.append(parent.name)
+ if parent.name not in self.exclusive_disks:
+ self.exclusive_disks.append(parent.name)
def handle_device(self, info, update_orig_fmt=False):
"""
@@ -371,7 +370,7 @@ def update_format(self, device):
self.handle_format(info, device)
def _handle_inconsistencies(self):
- for vg in [d for d in self.devicetree.devices if d.type == "lvmvg"]:
+ for vg in [d for d in self.devices if d.type == "lvmvg"]:
if vg.complete:
continue
@@ -434,9 +433,9 @@ def setup_disk_images(self):
except (ValueError, DeviceError) as e:
log.error("failed to set up disk image: %s", e)
else:
- self.devicetree._add_device(filedev)
- self.devicetree._add_device(loopdev)
- self.devicetree._add_device(dmdev)
+ self._add_device(filedev)
+ self._add_device(loopdev)
+ self._add_device(dmdev)
info = udev.get_device(dmdev.sysfs_path)
self.handle_device(info, update_orig_fmt=True)
@@ -479,6 +478,10 @@ def populate(self, cleanup_only=False):
raise
finally:
parted.clear_exn_handler()
+ self._hide_ignored_disks()
+
+ if flags.installer_mode:
+ self.teardown_all()
def _resolve_protected_device_specs(self):
# resolve the protected device specs to device names
@@ -505,7 +508,7 @@ def _find_live_backing_device(self):
def _populate(self):
log.info("DeviceTree.populate: ignored_disks is %s ; exclusive_disks is %s",
- self.devicetree.ignored_disks, self.devicetree.exclusive_disks)
+ self.ignored_disks, self.exclusive_disks)
self.drop_lvm_cache()
@@ -550,16 +553,6 @@ def _populate(self):
self._handle_inconsistencies()
@property
- def names(self):
- return self.devicetree.names
-
- def get_device_by_name(self, *args, **kwargs):
- return self.devicetree.get_device_by_name(*args, **kwargs)
-
- def get_device_by_uuid(self, *args, **kwargs):
- return self.devicetree.get_device_by_uuid(*args, **kwargs)
-
- @property
def pv_info(self):
if self._pvs_cache is None:
pvs = blockdev.lvm.pvs()
@@ -579,3 +572,32 @@ def drop_lvm_cache(self):
""" Drop cached lvm information. """
self._pvs_cache = None # pylint: disable=attribute-defined-outside-init
self._lvs_cache = None # pylint: disable=attribute-defined-outside-init
+
+ def handle_nodev_filesystems(self):
+ for line in open("/proc/mounts").readlines():
+ try:
+ (_devspec, mountpoint, fstype, _options, _rest) = line.split(None, 4)
+ except ValueError:
+ log.error("failed to parse /proc/mounts line: %s", line)
+ continue
+ if fstype in formats.fslib.nodev_filesystems:
+ if not flags.include_nodev:
+ continue
+
+ log.info("found nodev %s filesystem mounted at %s",
+ fstype, mountpoint)
+ # nodev filesystems require some special handling.
+ # For now, a lot of this is based on the idea that it's a losing
+ # battle to require the presence of an FS class for every type
+ # of nodev filesystem. Based on that idea, we just instantiate
+ # NoDevFS directly and then hack in the fstype as the device
+ # attribute.
+ fmt = formats.get_format("nodev")
+ fmt.device = fstype
+
+ # NoDevice also needs some special works since they don't have
+ # per-instance names in the kernel.
+ device = NoDevice(fmt=fmt)
+ n = len([d for d in self.devices if d.format.type == fstype])
+ device._name += ".%d" % n
+ self._add_device(device)
diff --git a/tests/populator_test.py b/tests/populator_test.py
index ae535be..b65aeec 100644
--- a/tests/populator_test.py
+++ b/tests/populator_test.py
@@ -16,7 +16,6 @@
from blivet.formats import get_device_format_class, get_format, DeviceFormat
from blivet.formats.disklabel import DiskLabel
from blivet.osinstall import storage_initialize
-from blivet.populator import Populator
from blivet.populator.helpers import DiskDevicePopulator, DMDevicePopulator, LoopDevicePopulator
from blivet.populator.helpers import LVMDevicePopulator, MDDevicePopulator, MultipathDevicePopulator
from blivet.populator.helpers import OpticalDevicePopulator, PartitionDevicePopulator
@@ -132,7 +131,7 @@ def test_get_helper(self, *args):
@patch.object(DeviceTree, "get_device_by_name")
@patch.object(DMDevice, "status", return_value=True)
- @patch.object(Populator, "_add_slave_devices")
+ @patch.object(DeviceTree, "_add_slave_devices")
@patch("blivet.udev.device_is_dm_livecd", return_value=False)
@patch("blivet.udev.device_get_name")
@patch("blivet.udev.device_get_sysfs_path", return_value=sentinel.sysfs_path)
@@ -141,35 +140,35 @@ def test_run(self, *args):
device_is_dm_livecd = args[2]
device_get_name = args[1]
- populator = Populator(devicetree=DeviceTree())
+ devicetree = DeviceTree()
# The general case for dm devices is that adding the slave/parent devices
# will result in the dm device itself being in the tree.
device = Mock()
- populator.devicetree.get_device_by_name.return_value = device
+ devicetree.get_device_by_name.return_value = device
data = {"DM_UUID": sentinel.dm_uuid}
- helper = self.helper_class(populator, data)
+ helper = self.helper_class(devicetree, data)
self.assertEqual(helper.run(), device)
- self.assertEqual(populator._add_slave_devices.call_count, 1)
- self.assertEqual(populator.devicetree.get_device_by_name.call_count, 1)
+ self.assertEqual(devicetree._add_slave_devices.call_count, 1)
+ self.assertEqual(devicetree.get_device_by_name.call_count, 1)
# since we faked the lookup as if the device was already in the tree
# the helper should not have added it, meaning it shouldn't be there
- self.assertFalse(device in populator.devicetree.devices)
+ self.assertFalse(device in devicetree.devices)
# The other case is adding a live media image
parent = Mock()
parent.parents = []
- populator._add_slave_devices.return_value = [parent]
- populator.devicetree._add_device(parent)
- populator.devicetree.get_device_by_name.return_value = None
+ devicetree._add_slave_devices.return_value = [parent]
+ devicetree._add_device(parent)
+ devicetree.get_device_by_name.return_value = None
device_name = "livedevice"
device_get_name.return_value = device_name
device_is_dm_livecd.return_value = True
device = helper.run()
self.assertIsInstance(device, DMDevice)
- self.assertTrue(device in populator.devicetree.devices)
+ self.assertTrue(device in devicetree.devices)
self.assertEqual(device.dm_uuid, sentinel.dm_uuid)
self.assertEqual(device.name, device_name)
self.assertEqual(device.sysfs_path, sentinel.sysfs_path)
@@ -236,28 +235,28 @@ def test_run(self, *args):
device_get_name = args[1]
get_backing_file = args[2]
- populator = Populator(devicetree=DeviceTree())
+ devicetree = DeviceTree()
data = Mock()
# Add backing file and loop device.
- populator.devicetree.get_device_by_name.return_value = None
+ devicetree.get_device_by_name.return_value = None
device_name = "loop3"
device_get_name.return_value = device_name
backing_file = "/some/file"
get_backing_file.return_value = backing_file
- helper = self.helper_class(populator, data)
+ helper = self.helper_class(devicetree, data)
device = helper.run()
self.assertIsInstance(device, LoopDevice)
- self.assertTrue(device in populator.devicetree.devices)
+ self.assertTrue(device in devicetree.devices)
self.assertTrue(device.exists)
self.assertEqual(device.name, device_name)
self.assertIsInstance(device.parents[0], FileDevice)
self.assertTrue(device.parents[0].exists)
- self.assertEqual(populator.devicetree.get_device_by_name.call_count, 1)
- populator.devicetree.get_device_by_name.assert_called_with(backing_file)
+ self.assertEqual(devicetree.get_device_by_name.call_count, 1)
+ devicetree.get_device_by_name.assert_called_with(backing_file)
class LVMDevicePopulatorTestCase(PopulatorHelperTestCase):
@@ -292,7 +291,7 @@ def test_get_helper(self, *args):
# could be the first helper class checked.
@patch.object(DeviceTree, "get_device_by_name")
- @patch.object(Populator, "_add_slave_devices")
+ @patch.object(DeviceTree, "_add_slave_devices")
@patch("blivet.udev.device_get_name")
@patch("blivet.udev.device_get_lv_vg_name")
def test_run(self, *args):
@@ -301,12 +300,12 @@ def test_run(self, *args):
device_get_name = args[1]
get_device_by_name = args[3]
- populator = Populator(devicetree=DeviceTree())
+ devicetree = DeviceTree()
data = Mock()
# Add slave/parent devices and then look up the device.
device_get_name.return_value = sentinel.lv_name
- populator.devicetree.get_device_by_name.return_value = None
+ devicetree.get_device_by_name.return_value = None
# pylint: disable=unused-argument
def _get_device_by_name(name, **kwargs):
@@ -315,10 +314,10 @@ def _get_device_by_name(name, **kwargs):
get_device_by_name.side_effect = _get_device_by_name
device_get_lv_vg_name.return_value = sentinel.vg_name
- helper = self.helper_class(populator, data)
+ helper = self.helper_class(devicetree, data)
self.assertEqual(helper.run(), sentinel.lv_device)
- self.assertEqual(populator.devicetree.get_device_by_name.call_count, 3)
+ self.assertEqual(devicetree.get_device_by_name.call_count, 3)
get_device_by_name.assert_has_calls(
[call(sentinel.vg_name, hidden=True),
call(sentinel.vg_name),
@@ -385,10 +384,10 @@ def test_run(self, *args):
"""Test optical device populator."""
device_get_name = args[0]
- populator = Populator(devicetree=DeviceTree())
+ devicetree = DeviceTree()
data = Mock()
- helper = self.helper_class(populator, data)
+ helper = self.helper_class(devicetree, data)
device_name = "sr0"
device_get_name.return_value = device_name
@@ -396,7 +395,7 @@ def test_run(self, *args):
self.assertIsInstance(device, OpticalDevice)
self.assertTrue(device.exists)
self.assertEqual(device.name, device_name)
- self.assertTrue(device in populator.devicetree.devices)
+ self.assertTrue(device in devicetree.devices)
class PartitionDevicePopulatorTestCase(PopulatorHelperTestCase):
@@ -462,7 +461,7 @@ def test_run(self, *args):
device_get_name = args[1]
get_device_by_name = args[2]
- populator = Populator(devicetree=DeviceTree())
+ devicetree = DeviceTree()
data = Mock()
# for every case:
@@ -473,19 +472,19 @@ def test_run(self, *args):
# base case: disk is already in the tree, normal disk
fmt = get_format("disklabel", exists=True, device="/dev/xyz")
disk = DiskDevice("xyz", fmt=fmt, exists=True)
- populator.devicetree._add_device(disk)
+ devicetree._add_device(disk)
device_name = "xyz1"
device_get_name.return_value = device_name
device_get_partition_disk.return_value = "xyz"
get_device_by_name.return_value = disk
- helper = self.helper_class(populator, data)
+ helper = self.helper_class(devicetree, data)
device = helper.run()
self.assertIsInstance(device, PartitionDevice)
self.assertTrue(device.exists)
self.assertEqual(device.name, device_name)
- self.assertTrue(device in populator.devicetree.devices)
+ self.assertTrue(device in devicetree.devices)
# TODO: disk not already in the tree
@@ -545,19 +544,19 @@ def test_run(self, *args):
"""Test disk device populator."""
device_get_name = args[0]
- populator = Populator(devicetree=DeviceTree())
+ devicetree = DeviceTree()
data = Mock()
device_name = "nop"
device_get_name.return_value = device_name
- helper = self.helper_class(populator, data)
+ helper = self.helper_class(devicetree, data)
device = helper.run()
self.assertIsInstance(device, DiskDevice)
self.assertTrue(device.exists)
self.assertTrue(device.is_disk)
self.assertEqual(device.name, device_name)
- self.assertTrue(device in populator.devicetree.devices)
+ self.assertTrue(device in devicetree.devices)
class MDDevicePopulatorTestCase(PopulatorHelperTestCase):
@@ -608,7 +607,7 @@ def test_get_helper(self, *args):
# could be the first helper class checked.
@patch.object(DeviceTree, "get_device_by_name")
- @patch.object(Populator, "_add_slave_devices")
+ @patch.object(DeviceTree, "_add_slave_devices")
@patch("blivet.udev.device_get_name")
@patch("blivet.udev.device_get_md_uuid")
@patch("blivet.udev.device_get_md_name")
@@ -617,7 +616,7 @@ def test_run(self, *args):
device_get_md_name = args[0]
get_device_by_name = args[4]
- populator = Populator(devicetree=DeviceTree())
+ devicetree = DeviceTree()
# base case: _add_slave_devices gets the array into the tree
data = Mock()
@@ -627,7 +626,7 @@ def test_run(self, *args):
device_name = "mdtest"
device_get_md_name.return_value = device_name
get_device_by_name.return_value = device
- helper = self.helper_class(populator, data)
+ helper = self.helper_class(devicetree, data)
self.assertEqual(helper.run(), device)
@@ -682,14 +681,14 @@ def test_get_helper(self, *args):
# could be the first helper class checked.
@patch("blivet.udev.device_get_sysfs_path")
- @patch.object(Populator, "_add_slave_devices")
+ @patch.object(DeviceTree, "_add_slave_devices")
@patch("blivet.udev.device_get_name")
def test_run(self, *args):
"""Test multipath device populator."""
device_get_name = args[0]
add_slave_devices = args[1]
- populator = Populator(devicetree=DeviceTree())
+ devicetree = DeviceTree()
data = {"DM_UUID": "1-2-3-4"}
device_name = "mpathtest"
@@ -698,17 +697,17 @@ def test_run(self, *args):
slave_1.parents = []
slave_2 = Mock()
slave_2.parents = []
- populator.devicetree._add_device(slave_1)
- populator.devicetree._add_device(slave_2)
+ devicetree._add_device(slave_1)
+ devicetree._add_device(slave_2)
add_slave_devices.return_value = [slave_1, slave_2]
- helper = self.helper_class(populator, data)
+ helper = self.helper_class(devicetree, data)
device = helper.run()
self.assertIsInstance(device, MultipathDevice)
self.assertTrue(device.exists)
self.assertEqual(device.name, device_name)
- self.assertTrue(device in populator.devicetree.devices)
+ self.assertTrue(device in devicetree.devices)
class FormatPopulatorTestCase(PopulatorHelperTestCase):
@@ -752,12 +751,12 @@ def test_run(self):
if self.udev_type is None:
return
- populator = Populator(devicetree=DeviceTree())
+ devicetree = DeviceTree()
data = dict()
device = Mock()
with patch("blivet.udev.device_get_format", return_value=self.udev_type):
- helper = self.helper_class(populator, data, device)
+ helper = self.helper_class(devicetree, data, device)
helper.run()
self.assertEqual(device.format.type,
self.blivet_type,
@@ -863,12 +862,12 @@ def test_run(self, *args):
"""Test lvm format populator."""
get_device_by_uuid = args[0]
- populator = Populator(devicetree=DeviceTree())
+ devicetree = DeviceTree()
data = dict()
device = Mock()
device.parents = []
device.size = Size("10g")
- populator.devicetree._add_device(device)
+ devicetree._add_device(device)
# pylint: disable=attribute-defined-outside-init
self._pvs = blockdev.lvm.pvs
@@ -877,7 +876,7 @@ def test_run(self, *args):
# base case: pv format with no vg
with patch("blivet.udev.device_get_format", return_value=self.udev_type):
- helper = self.helper_class(populator, data, device)
+ helper = self.helper_class(devicetree, data, device)
helper.run()
self.assertEqual(device.format.type,
self.blivet_type,
@@ -890,15 +889,15 @@ def test_run(self, *args):
pv_info.vg_uuid = sentinel.vg_uuid
pv_info.pe_start = 0
- populator._pvs_cache = dict()
- populator._pvs_cache[sentinel.pv_path] = pv_info
+ devicetree._pvs_cache = dict()
+ devicetree._pvs_cache[sentinel.pv_path] = pv_info
device.path = sentinel.pv_path
vg_device = Mock()
get_device_by_uuid.return_value = vg_device
with patch("blivet.udev.device_get_format", return_value=self.udev_type):
- helper = self.helper_class(populator, data, device)
+ helper = self.helper_class(devicetree, data, device)
helper.run()
self.assertEqual(device.format.type,
self.blivet_type,
@@ -920,7 +919,7 @@ def test_run(self, *args):
pv_info.vg_pv_count = 1
with patch("blivet.udev.device_get_format", return_value=self.udev_type):
- helper = self.helper_class(populator, data, device)
+ helper = self.helper_class(devicetree, data, device)
helper.run()
self.assertEqual(device.format.type,
self.blivet_type,
@@ -928,9 +927,9 @@ def test_run(self, *args):
self.assertEqual(get_device_by_uuid.call_count, 1)
get_device_by_uuid.assert_called_with(pv_info.vg_uuid, incomplete=True)
- vg_device = populator.devicetree.get_device_by_name(pv_info.vg_name)
+ vg_device = devicetree.get_device_by_name(pv_info.vg_name)
self.assertTrue(vg_device is not None)
- populator.devicetree._remove_device(vg_device)
+ devicetree._remove_device(vg_device)
get_device_by_uuid.reset_mock()
@@ -955,10 +954,10 @@ def test_run(self, *args):
lv_info = {lv1_name: lv1,
lv2_name: lv2}
- populator._lvs_cache = lv_info
+ devicetree._lvs_cache = lv_info
with patch("blivet.udev.device_get_format", return_value=self.udev_type):
- helper = self.helper_class(populator, data, device)
+ helper = self.helper_class(devicetree, data, device)
helper.run()
self.assertEqual(device.format.type,
self.blivet_type,
@@ -969,12 +968,12 @@ def test_run(self, *args):
call(lv1.uuid),
call(lv2.uuid)],
any_order=True)
- vg_device = populator.devicetree.get_device_by_name(pv_info.vg_name)
+ vg_device = devicetree.get_device_by_name(pv_info.vg_name)
self.assertTrue(vg_device is not None)
- lv1_device = populator.devicetree.get_device_by_name(lv1_name)
+ lv1_device = devicetree.get_device_by_name(lv1_name)
self.assertEqual(lv1_device.uuid, lv1.uuid)
- lv2_device = populator.devicetree.get_device_by_name(lv2_name)
+ lv2_device = devicetree.get_device_by_name(lv2_name)
self.assertEqual(lv2_device.uuid, lv2.uuid)
@@ -998,13 +997,13 @@ def test_run(self, *args):
get_devices = args[1]
device_is_md = args[2]
- populator = Populator(devicetree=DeviceTree())
+ devicetree = DeviceTree()
data = dict()
device = Mock()
device.name = sentinel.dev1_name
device.parents = []
device.size = Size("10g")
- populator.devicetree._add_device(device)
+ devicetree._add_device(device)
# pylint: disable=attribute-defined-outside-init
self._examine = blockdev.md.examine
@@ -1020,7 +1019,7 @@ def test_run(self, *args):
get_device_by_uuid.return_value = md_device
with patch("blivet.udev.device_get_format", return_value=self.udev_type):
- helper = self.helper_class(populator, data, device)
+ helper = self.helper_class(devicetree, data, device)
helper.run()
self.assertEqual(device.format.type,
self.blivet_type,
@@ -1046,7 +1045,7 @@ def test_run(self, *args):
get_devices.return_value = [md_udev]
with patch("blivet.udev.device_get_format", return_value=self.udev_type):
- helper = self.helper_class(populator, data, device)
+ helper = self.helper_class(devicetree, data, device)
helper.run()
self.assertEqual(device.format.type,
self.blivet_type,
@@ -1054,15 +1053,15 @@ def test_run(self, *args):
self.assertEqual(get_device_by_uuid.call_count, 1)
get_device_by_uuid.assert_called_with(md_info.uuid, incomplete=True)
- array = populator.devicetree.get_device_by_name(array_name)
+ array = devicetree.get_device_by_name(array_name)
self.assertTrue(array is None)
- array = populator.devicetree.get_device_by_name(array_name, incomplete=True)
+ array = devicetree.get_device_by_name(array_name, incomplete=True)
self.assertTrue(array is not None)
self.assertFalse(array.complete)
self.assertEqual(array.name, array_name)
get_device_by_uuid.reset_mock()
- array = populator.devicetree.get_device_by_name(array_name, incomplete=True)
+ array = devicetree.get_device_by_name(array_name, incomplete=True)
get_device_by_uuid.return_value = array
# second of two members belonging to a valid array
@@ -1070,10 +1069,10 @@ def test_run(self, *args):
device2.name = sentinel.dev2_name
device2.parents = []
device2.size = Size("10g")
- populator.devicetree._add_device(device2)
+ devicetree._add_device(device2)
with patch("blivet.udev.device_get_format", return_value=self.udev_type):
- helper = self.helper_class(populator, data, device2)
+ helper = self.helper_class(devicetree, data, device2)
helper.run()
self.assertEqual(device2.format.type,
self.blivet_type,
@@ -1082,7 +1081,7 @@ def test_run(self, *args):
self.assertEqual(get_device_by_uuid.call_count, 1) # one for the array
get_device_by_uuid.assert_called_with(md_info.uuid, incomplete=True)
- array = populator.devicetree.get_device_by_name(array_name)
+ array = devicetree.get_device_by_name(array_name)
self.assertTrue(array is not None)
self.assertTrue(array.complete)
self.assertEqual(array.name, array_name)
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/f2342210bcd723acbe368eb8bc47...
8 years, 5 months
[master 21/27] Move disk filter bits from Populator into DeviceTree.
by dashea
From: David Lehman <dlehman(a)redhat.com>
All disk filtering handling is in DeviceTree.
---
blivet/devicetree.py | 11 +++--------
blivet/populator/helpers/partition.py | 2 +-
blivet/populator/populator.py | 15 +++++----------
3 files changed, 9 insertions(+), 19 deletions(-)
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index 637d3d3..9afadad 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -101,6 +101,9 @@ def reset(self, conf=None, passphrase=None, luks_dict=None,
lvm.lvm_cc_resetFilter()
+ self.exclusive_disks = getattr(conf, "exclusive_disks", [])
+ self.ignored_disks = getattr(conf, "ignored_disks", [])
+
self.edd_dict = {}
self._populator = Populator(self,
@@ -891,14 +894,6 @@ def labels(self):
#
# Disk filter
#
- @property
- def exclusive_disks(self):
- return self._populator.exclusive_disks
-
- @property
- def ignored_disks(self):
- return self._populator.ignored_disks
-
def hide(self, device):
""" Hide the specified device.
diff --git a/blivet/populator/helpers/partition.py b/blivet/populator/helpers/partition.py
index 971a965..3709599 100644
--- a/blivet/populator/helpers/partition.py
+++ b/blivet/populator/helpers/partition.py
@@ -83,7 +83,7 @@ def run(self):
if disk.partitionable and \
disk.format.type != "iso9660" and \
not disk.format.hidden and \
- not self._populator._is_ignored_disk(disk):
+ not self._populator.devicetree._is_ignored_disk(disk):
if self.data.get("ID_PART_TABLE_TYPE") == "gpt":
msg = "corrupt gpt disklabel on disk %s" % disk.name
cls = CorruptGPTError
diff --git a/blivet/populator/populator.py b/blivet/populator/populator.py
index 4d511db..d529053 100644
--- a/blivet/populator/populator.py
+++ b/blivet/populator/populator.py
@@ -81,8 +81,6 @@ def __init__(self, devicetree=None, conf=None, passphrase=None,
# indicates whether or not the tree has been fully populated
self.populated = False
- self.exclusive_disks = getattr(conf, "exclusive_disks", [])
- self.ignored_disks = getattr(conf, "ignored_disks", [])
self.iscsi = iscsi
self.dasd = dasd
@@ -112,11 +110,8 @@ def __init__(self, devicetree=None, conf=None, passphrase=None,
# initialize attributes that may later hold cached lvm info
self.drop_lvm_cache()
-
- self._cleanup = False
- def _is_ignored_disk(self, disk):
- return self.devicetree._is_ignored_disk(disk)
+ self._cleanup = False
def _udev_device_is_disk(self, info):
""" Return True if the udev device looks like a disk.
@@ -282,10 +277,10 @@ def _update_exclusive_disks(self, device):
# we have to make sure all of its members are in the list too.
mdclasses = (DMRaidArrayDevice, MDRaidArrayDevice, MultipathDevice)
if device.is_disk and isinstance(device, mdclasses):
- if device.name in self.exclusive_disks:
+ if device.name in self.devicetree.exclusive_disks:
for parent in device.parents:
- if parent.name not in self.exclusive_disks:
- self.exclusive_disks.append(parent.name)
+ if parent.name not in self.devicetree.exclusive_disks:
+ self.devicetree.exclusive_disks.append(parent.name)
def handle_device(self, info, update_orig_fmt=False):
"""
@@ -510,7 +505,7 @@ def _find_live_backing_device(self):
def _populate(self):
log.info("DeviceTree.populate: ignored_disks is %s ; exclusive_disks is %s",
- self.ignored_disks, self.exclusive_disks)
+ self.devicetree.ignored_disks, self.devicetree.exclusive_disks)
self.drop_lvm_cache()
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/fffb905a145c1de66acfda64c639...
8 years, 5 months
[master 20/27] Move the LVM data cache from DeviceTree to Populator.
by dashea
From: David Lehman <dlehman(a)redhat.com>
It is only used in the context of populating the devicetree.
---
blivet/devicetree.py | 25 -------------------------
blivet/populator/helpers/lvm.py | 6 +++---
blivet/populator/populator.py | 26 +++++++++++++++++++++++++-
tests/populator_test.py | 6 +++---
4 files changed, 31 insertions(+), 32 deletions(-)
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index eb949ae..637d3d3 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -99,9 +99,6 @@ def reset(self, conf=None, passphrase=None, luks_dict=None,
self._hidden = []
- # initialize attributes that may later hold cached lvm info
- self.drop_lvm_cache()
-
lvm.lvm_cc_resetFilter()
self.edd_dict = {}
@@ -339,7 +336,6 @@ def populate(self, cleanup_only=False):
process.
"""
udev.settle()
- self.drop_lvm_cache()
try:
self._populator.populate(cleanup_only=cleanup_only)
except Exception:
@@ -1061,27 +1057,6 @@ def disk_images(self):
# Miscellaneous (global) data
#
@property
- def pv_info(self):
- if self._pvs_cache is None:
- pvs = blockdev.lvm.pvs()
- self._pvs_cache = dict((pv.pv_name, pv) for pv in pvs) # pylint: disable=attribute-defined-outside-init
-
- return self._pvs_cache
-
- @property
- def lv_info(self):
- if self._lvs_cache is None:
- lvs = blockdev.lvm.lvs()
- self._lvs_cache = dict(("%s-%s" % (lv.vg_name, lv.lv_name), lv) for lv in lvs) # pylint: disable=attribute-defined-outside-init
-
- return self._lvs_cache
-
- def drop_lvm_cache(self):
- """ Drop cached lvm information. """
- self._pvs_cache = None # pylint: disable=attribute-defined-outside-init
- self._lvs_cache = None # pylint: disable=attribute-defined-outside-init
-
- @property
def dasd(self):
return self._populator.dasd
diff --git a/blivet/populator/helpers/lvm.py b/blivet/populator/helpers/lvm.py
index 62060b5..377a7a8 100644
--- a/blivet/populator/helpers/lvm.py
+++ b/blivet/populator/helpers/lvm.py
@@ -75,7 +75,7 @@ class LVMFormatPopulator(FormatPopulator):
def _get_kwargs(self):
kwargs = super()._get_kwargs()
- pv_info = self._populator.devicetree.pv_info.get(self.device.path, None)
+ pv_info = self._populator.pv_info.get(self.device.path, None)
name = udev.device_get_name(self.data)
if pv_info:
if pv_info.vg_name:
@@ -96,7 +96,7 @@ def _get_kwargs(self):
def _handle_vg_lvs(self, vg_device):
""" Handle setup of the LV's in the vg_device. """
vg_name = vg_device.name
- lv_info = dict((k, v) for (k, v) in iter(self._populator.devicetree.lv_info.items())
+ lv_info = dict((k, v) for (k, v) in iter(self._populator.lv_info.items())
if v.vg_name == vg_name)
self._populator.names.extend(n for n in lv_info.keys() if n not in self._populator.names)
@@ -308,7 +308,7 @@ def create_internal_lv(lv):
def run(self):
super().run()
- pv_info = self._populator.devicetree.pv_info.get(self.device.path, None)
+ pv_info = self._populator.pv_info.get(self.device.path, None)
if pv_info:
vg_name = pv_info.vg_name
vg_uuid = pv_info.vg_uuid
diff --git a/blivet/populator/populator.py b/blivet/populator/populator.py
index 7be974a..4d511db 100644
--- a/blivet/populator/populator.py
+++ b/blivet/populator/populator.py
@@ -110,6 +110,9 @@ def __init__(self, devicetree=None, conf=None, passphrase=None,
self.__luks_devs = luks_dict
self.__passphrases.extend([p for p in luks_dict.values() if p])
+ # initialize attributes that may later hold cached lvm info
+ self.drop_lvm_cache()
+
self._cleanup = False
def _is_ignored_disk(self, disk):
@@ -509,7 +512,7 @@ def _populate(self):
log.info("DeviceTree.populate: ignored_disks is %s ; exclusive_disks is %s",
self.ignored_disks, self.exclusive_disks)
- self.devicetree.drop_lvm_cache()
+ self.drop_lvm_cache()
if flags.installer_mode and not flags.image_install:
blockdev.mpath.set_friendly_names(flags.multipath_friendly_names)
@@ -560,3 +563,24 @@ def get_device_by_name(self, *args, **kwargs):
def get_device_by_uuid(self, *args, **kwargs):
return self.devicetree.get_device_by_uuid(*args, **kwargs)
+
+ @property
+ def pv_info(self):
+ if self._pvs_cache is None:
+ pvs = blockdev.lvm.pvs()
+ self._pvs_cache = dict((pv.pv_name, pv) for pv in pvs) # pylint: disable=attribute-defined-outside-init
+
+ return self._pvs_cache
+
+ @property
+ def lv_info(self):
+ if self._lvs_cache is None:
+ lvs = blockdev.lvm.lvs()
+ self._lvs_cache = dict(("%s-%s" % (lv.vg_name, lv.lv_name), lv) for lv in lvs) # pylint: disable=attribute-defined-outside-init
+
+ return self._lvs_cache
+
+ def drop_lvm_cache(self):
+ """ Drop cached lvm information. """
+ self._pvs_cache = None # pylint: disable=attribute-defined-outside-init
+ self._lvs_cache = None # pylint: disable=attribute-defined-outside-init
diff --git a/tests/populator_test.py b/tests/populator_test.py
index 987b45e..ae535be 100644
--- a/tests/populator_test.py
+++ b/tests/populator_test.py
@@ -890,8 +890,8 @@ def test_run(self, *args):
pv_info.vg_uuid = sentinel.vg_uuid
pv_info.pe_start = 0
- populator.devicetree._pvs_cache = dict()
- populator.devicetree._pvs_cache[sentinel.pv_path] = pv_info
+ populator._pvs_cache = dict()
+ populator._pvs_cache[sentinel.pv_path] = pv_info
device.path = sentinel.pv_path
vg_device = Mock()
@@ -955,7 +955,7 @@ def test_run(self, *args):
lv_info = {lv1_name: lv1,
lv2_name: lv2}
- populator.devicetree._lvs_cache = lv_info
+ populator._lvs_cache = lv_info
with patch("blivet.udev.device_get_format", return_value=self.udev_type):
helper = self.helper_class(populator, data, device)
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/fc0dbed732492b4563441c848f08...
8 years, 5 months
[master 19/27] Rename per-device Populator entry points.
by dashea
From: David Lehman <dlehman(a)redhat.com>
Main entry point is handle_device, which calls handle_format.
---
blivet/devicetree.py | 4 ++--
blivet/populator/helpers/disk.py | 2 +-
blivet/populator/helpers/dmraid.py | 2 +-
blivet/populator/helpers/luks.py | 2 +-
blivet/populator/helpers/lvm.py | 2 +-
blivet/populator/helpers/mdraid.py | 2 +-
blivet/populator/helpers/partition.py | 2 +-
blivet/populator/populator.py | 16 ++++++++--------
8 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index 953d977..eb949ae 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -350,8 +350,8 @@ def populate(self, cleanup_only=False):
if flags.installer_mode:
self.teardown_all()
- def update_device_format(self, device):
- return self._populator.update_device_format(device)
+ def update_format(self, device):
+ return self._populator.update_format(device)
def handle_nodev_filesystems(self):
for line in open("/proc/mounts").readlines():
diff --git a/blivet/populator/helpers/disk.py b/blivet/populator/helpers/disk.py
index fbadda5..98642af 100644
--- a/blivet/populator/helpers/disk.py
+++ b/blivet/populator/helpers/disk.py
@@ -162,7 +162,7 @@ def _get_kwargs(self):
parent_name, container_sysfs)
return
- self._populator.add_udev_device(container_info)
+ self._populator.handle_device(container_info)
container = self._populator.devicetree.get_device_by_name(parent_name)
if not container:
log.error("failed to scan md container %s", parent_name)
diff --git a/blivet/populator/helpers/dmraid.py b/blivet/populator/helpers/dmraid.py
index c2ed941..7e30502 100644
--- a/blivet/populator/helpers/dmraid.py
+++ b/blivet/populator/helpers/dmraid.py
@@ -80,4 +80,4 @@ def run(self):
# its partitions get scanned before it does.
dm_array.update_sysfs_path()
dm_array_info = udev.get_device(dm_array.sysfs_path)
- self._populator.add_udev_device(dm_array_info, update_orig_fmt=True)
+ self._populator.handle_device(dm_array_info, update_orig_fmt=True)
diff --git a/blivet/populator/helpers/luks.py b/blivet/populator/helpers/luks.py
index 1edd56c..a06a739 100644
--- a/blivet/populator/helpers/luks.py
+++ b/blivet/populator/helpers/luks.py
@@ -97,7 +97,7 @@ def run(self):
log.error("failed to get udev data for %s", luks_device.name)
return
- self._populator.add_udev_device(luks_info, update_orig_fmt=True)
+ self._populator.handle_device(luks_info, update_orig_fmt=True)
else:
log.warning("luks device %s already in the tree",
self.device.format.map_name)
diff --git a/blivet/populator/helpers/lvm.py b/blivet/populator/helpers/lvm.py
index 5020abb..62060b5 100644
--- a/blivet/populator/helpers/lvm.py
+++ b/blivet/populator/helpers/lvm.py
@@ -236,7 +236,7 @@ def add_lv(lv):
return lv_device
# do format handling now
- self._populator.add_udev_device(lv_info, update_orig_fmt=True)
+ self._populator.handle_device(lv_info, update_orig_fmt=True)
return lv_device
diff --git a/blivet/populator/helpers/mdraid.py b/blivet/populator/helpers/mdraid.py
index 6653abb..7047016 100644
--- a/blivet/populator/helpers/mdraid.py
+++ b/blivet/populator/helpers/mdraid.py
@@ -204,4 +204,4 @@ def run(self):
log.error("failed to get udev data for %s", md_array.name)
return
- self._populator.add_udev_device(array_info, update_orig_fmt=True)
+ self._populator.handle_device(array_info, update_orig_fmt=True)
diff --git a/blivet/populator/helpers/partition.py b/blivet/populator/helpers/partition.py
index 52d94f7..971a965 100644
--- a/blivet/populator/helpers/partition.py
+++ b/blivet/populator/helpers/partition.py
@@ -64,7 +64,7 @@ def run(self):
# create a device instance for the disk
new_info = udev.get_device(os.path.dirname(sysfs_path))
if new_info:
- self._populator.add_udev_device(new_info)
+ self._populator.handle_device(new_info)
disk = self._populator.devicetree.get_device_by_name(disk_name)
if disk is None:
diff --git a/blivet/populator/populator.py b/blivet/populator/populator.py
index b658308..7be974a 100644
--- a/blivet/populator/populator.py
+++ b/blivet/populator/populator.py
@@ -170,7 +170,7 @@ def _add_slave_devices(self, info):
slave_dev = self.get_device_by_name(slave_name)
if not slave_dev and slave_info:
# we haven't scanned the slave yet, so do it now
- self.add_udev_device(slave_info)
+ self.handle_device(slave_info)
slave_dev = self.get_device_by_name(slave_name)
if slave_dev is None:
if udev.device_is_dm_lvm(info):
@@ -284,7 +284,7 @@ def _update_exclusive_disks(self, device):
if parent.name not in self.exclusive_disks:
self.exclusive_disks.append(parent.name)
- def add_udev_device(self, info, update_orig_fmt=False):
+ def handle_device(self, info, update_orig_fmt=False):
"""
:param :class:`pyudev.Device` info: udev info for the device
:keyword bool update_orig_fmt: update original format unconditionally
@@ -331,12 +331,12 @@ def add_udev_device(self, info, update_orig_fmt=False):
self._update_exclusive_disks(device)
# now handle the device's formatting
- self.handle_udev_device_format(info, device)
+ self.handle_format(info, device)
if device_added or update_orig_fmt:
device.original_format = copy.deepcopy(device.format)
device.device_links = udev.device_get_symlinks(info)
- def handle_udev_device_format(self, info, device):
+ def handle_format(self, info, device):
log_method_call(self, name=getattr(device, "name", None))
if not info:
@@ -360,7 +360,7 @@ def handle_udev_device_format(self, info, device):
log.info("got format: %s", device.format)
- def update_device_format(self, device):
+ def update_format(self, device):
log.info("updating format of device: %s", device)
try:
util.notify_kernel(device.sysfs_path)
@@ -370,7 +370,7 @@ def update_device_format(self, device):
udev.settle()
info = udev.get_device(device.sysfs_path)
- self.handle_udev_device_format(info, device)
+ self.handle_format(info, device)
def _handle_inconsistencies(self):
for vg in [d for d in self.devicetree.devices if d.type == "lvmvg"]:
@@ -440,7 +440,7 @@ def setup_disk_images(self):
self.devicetree._add_device(loopdev)
self.devicetree._add_device(dmdev)
info = udev.get_device(dmdev.sysfs_path)
- self.add_udev_device(info, update_orig_fmt=True)
+ self.handle_device(info, update_orig_fmt=True)
def teardown_disk_images(self):
""" Tear down any disk image stacks. """
@@ -543,7 +543,7 @@ def _populate(self):
log.info("devices to scan: %s", [udev.device_get_name(d) for d in devices])
for dev in devices:
- self.add_udev_device(dev)
+ self.handle_device(dev)
self.populated = True
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/58b631eb362202a0538f1b734597...
8 years, 5 months
[master 18/27] Make Populator.udev_device_is_disk a private method.
by dashea
From: David Lehman <dlehman(a)redhat.com>
---
blivet/populator/populator.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/blivet/populator/populator.py b/blivet/populator/populator.py
index 4421388..b658308 100644
--- a/blivet/populator/populator.py
+++ b/blivet/populator/populator.py
@@ -115,7 +115,7 @@ def __init__(self, devicetree=None, conf=None, passphrase=None,
def _is_ignored_disk(self, disk):
return self.devicetree._is_ignored_disk(disk)
- def udev_device_is_disk(self, info):
+ def _udev_device_is_disk(self, info):
""" Return True if the udev device looks like a disk.
:param info: udevdb device entry
@@ -258,7 +258,7 @@ def _clear_new_multipath_member(self, device):
def _mark_readonly_device(self, info, device):
# If this device is read-only, mark it as such now.
- if self.udev_device_is_disk(info) and \
+ if self._udev_device_is_disk(info) and \
util.get_sysfs_attr(udev.device_get_sysfs_path(info), 'ro') == '1':
device.readonly = True
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/075ba98f04c302e6018f4b42c5e9...
8 years, 5 months
[master 17/27] Stop writing an mdadm.conf.
by dashea
From: David Lehman <dlehman(a)redhat.com>
Since arrays are generally active when we arrive on the scene
there is no value in trying to control which minors mdadm uses.
In fact, we shouldn't waste any effort pretending to care at all
which minors are used for md arrays.
---
blivet/devices/md.py | 7 -------
blivet/populator/populator.py | 47 -------------------------------------------
2 files changed, 54 deletions(-)
diff --git a/blivet/devices/md.py b/blivet/devices/md.py
index b59ac3b..76e59ac 100644
--- a/blivet/devices/md.py
+++ b/blivet/devices/md.py
@@ -31,7 +31,6 @@
from .. import errors
from .. import util
-from ..flags import flags
from ..storage_log import log_method_call
from .. import udev
from ..size import Size
@@ -138,12 +137,6 @@ def __init__(self, name, level=None, major=None, minor=None, size=None,
if self.parents and self.parents[0].type == "mdcontainer" and self.type != "mdbiosraidarray":
raise errors.DeviceError("A device with mdcontainer member must be mdbiosraidarray.")
- if self.exists and self.mdadm_format_uuid and not flags.testing:
- # this is a hack to work around mdadm's insistence on giving
- # really high minors to arrays it has no config entry for
- with open("/etc/mdadm.conf", "a") as c:
- c.write("ARRAY %s UUID=%s\n" % (self.path, self.mdadm_format_uuid))
-
@property
def mdadm_format_uuid(self):
""" This array's UUID, formatted for external use.
diff --git a/blivet/populator/populator.py b/blivet/populator/populator.py
index 6edc4cf..4421388 100644
--- a/blivet/populator/populator.py
+++ b/blivet/populator/populator.py
@@ -21,7 +21,6 @@
#
import os
-import shutil
import pprint
import copy
import parted
@@ -454,50 +453,6 @@ def teardown_disk_images(self):
loop_device = dm_device.parents[0]
loop_device.teardown()
- def backup_configs(self, restore=False):
- """ Create a backup copies of some storage config files. """
- configs = ["/etc/mdadm.conf"]
- for cfg in configs:
- if restore:
- src = cfg + ".anacbak"
- dst = cfg
- func = os.rename
- op = "restore from backup"
- else:
- src = cfg
- dst = cfg + ".anacbak"
- func = shutil.copy2
- op = "create backup copy"
-
- if os.access(dst, os.W_OK):
- try:
- os.unlink(dst)
- except OSError as e:
- msg = str(e)
- log.info("failed to remove %s: %s", dst, msg)
-
- if os.access(src, os.W_OK):
- # copy the config to a backup with extension ".anacbak"
- try:
- func(src, dst)
- except (IOError, OSError) as e:
- msg = str(e)
- log.error("failed to %s of %s: %s", op, cfg, msg)
- elif restore and os.access(cfg, os.W_OK):
- # remove the config since we created it
- log.info("removing anaconda-created %s", cfg)
- try:
- os.unlink(cfg)
- except OSError as e:
- msg = str(e)
- log.error("failed to remove %s: %s", cfg, msg)
- else:
- # don't try to backup non-existent configs
- log.info("not going to %s of non-existent %s", op, cfg)
-
- def restore_configs(self):
- self.backup_configs(restore=True)
-
def save_luks_passphrase(self, device):
""" Save a device's LUKS passphrase in case of reset. """
@@ -516,7 +471,6 @@ def populate(self, cleanup_only=False):
scanned just the rest, but then they are hidden at the end of this
process.
"""
- self.backup_configs()
if cleanup_only:
self._cleanup = True
@@ -527,7 +481,6 @@ def populate(self, cleanup_only=False):
raise
finally:
parted.clear_exn_handler()
- self.restore_configs()
def _resolve_protected_device_specs(self):
# resolve the protected device specs to device names
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/a8bf63ff35f5303bf0d212c2b065...
8 years, 5 months
[master 16/27] Group disk-image-related methods together in source
code.
by dashea
From: David Lehman <dlehman(a)redhat.com>
---
blivet/populator/populator.py | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/blivet/populator/populator.py b/blivet/populator/populator.py
index b14b920..6edc4cf 100644
--- a/blivet/populator/populator.py
+++ b/blivet/populator/populator.py
@@ -113,22 +113,6 @@ def __init__(self, devicetree=None, conf=None, passphrase=None,
self._cleanup = False
- def set_disk_images(self, images):
- """ Set the disk images and reflect them in exclusive_disks.
-
- :param images: dict with image name keys and filename values
- :type images: dict
-
- .. note::
-
- Disk images are automatically exclusive. That means that, in the
- presence of disk images, any local storage not associated with
- the disk images is ignored.
- """
- self.disk_images = images
- # disk image files are automatically exclusive
- self.exclusive_disks = list(self.disk_images.keys())
-
def _is_ignored_disk(self, disk):
return self.devicetree._is_ignored_disk(disk)
@@ -400,6 +384,22 @@ def _handle_inconsistencies(self):
for pv in vg.pvs:
lvm.lvm_cc_addFilterRejectRegexp(pv.name)
+ def set_disk_images(self, images):
+ """ Set the disk images and reflect them in exclusive_disks.
+
+ :param images: dict with image name keys and filename values
+ :type images: dict
+
+ .. note::
+
+ Disk images are automatically exclusive. That means that, in the
+ presence of disk images, any local storage not associated with
+ the disk images is ignored.
+ """
+ self.disk_images = images
+ # disk image files are automatically exclusive
+ self.exclusive_disks = list(self.disk_images.keys())
+
def setup_disk_images(self):
""" Set up devices to represent the disk image files. """
for (name, path) in self.disk_images.items():
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/d22ea6c9410b9e490fdd80ab9b84...
8 years, 5 months
[master 15/27] Move some code from _populate into separate methods.
by dashea
From: David Lehman <dlehman(a)redhat.com>
---
blivet/populator/populator.py | 35 ++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)
diff --git a/blivet/populator/populator.py b/blivet/populator/populator.py
index d665b2e..b14b920 100644
--- a/blivet/populator/populator.py
+++ b/blivet/populator/populator.py
@@ -529,21 +529,7 @@ def populate(self, cleanup_only=False):
parted.clear_exn_handler()
self.restore_configs()
- def _populate(self):
- log.info("DeviceTree.populate: ignored_disks is %s ; exclusive_disks is %s",
- self.ignored_disks, self.exclusive_disks)
-
- self.devicetree.drop_lvm_cache()
-
- if flags.installer_mode and not flags.image_install:
- blockdev.mpath.set_friendly_names(flags.multipath_friendly_names)
-
- self.setup_disk_images()
-
- # mark the tree as unpopulated so exception handlers can tell the
- # exception originated while finding storage devices
- self.populated = False
-
+ def _resolve_protected_device_specs(self):
# resolve the protected device specs to device names
for spec in self.protected_dev_specs:
name = udev.resolve_devspec(spec)
@@ -551,6 +537,7 @@ def _populate(self):
if name:
self.protected_dev_names.append(name)
+ def _find_live_backing_device(self):
# FIXME: the backing dev for the live image can't be used as an
# install target. note that this is a little bit of a hack
# since we're assuming that /run/initramfs/live will exist
@@ -565,6 +552,24 @@ def _populate(self):
self.live_backing_device = live_device_name
break
+ def _populate(self):
+ log.info("DeviceTree.populate: ignored_disks is %s ; exclusive_disks is %s",
+ self.ignored_disks, self.exclusive_disks)
+
+ self.devicetree.drop_lvm_cache()
+
+ if flags.installer_mode and not flags.image_install:
+ blockdev.mpath.set_friendly_names(flags.multipath_friendly_names)
+
+ self.setup_disk_images()
+
+ # mark the tree as unpopulated so exception handlers can tell the
+ # exception originated while finding storage devices
+ self.populated = False
+
+ self._resolve_protected_device_specs()
+ self._find_live_backing_device()
+
old_devices = {}
# Now, loop and scan for devices that have appeared since the two above
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/7beca33ea68b99e6022c1bb7e14a...
8 years, 5 months
[master 14/27] Split various parts of add_udev_device into separate
methods.
by dashea
From: David Lehman <dlehman(a)redhat.com>
---
blivet/populator/populator.py | 170 +++++++++++++++++++++++-------------------
1 file changed, 92 insertions(+), 78 deletions(-)
diff --git a/blivet/populator/populator.py b/blivet/populator/populator.py
index 15c22e9..d665b2e 100644
--- a/blivet/populator/populator.py
+++ b/blivet/populator/populator.py
@@ -206,26 +206,18 @@ def _add_slave_devices(self, info):
return slave_devices
- def add_udev_device(self, info, update_orig_fmt=False):
- """
- :param :class:`pyudev.Device` info: udev info for the device
- :keyword bool update_orig_fmt: update original format unconditionally
+ def _add_name(self, name):
+ if name not in self.names:
+ self.names.append(name)
- If a device is added to the tree based on info its original format
- will be saved after the format has been detected. If the device
- that corresponds to info is already in the tree, its original format
- will not be updated unless update_orig_fmt is True.
- """
- name = udev.device_get_name(info)
- log_method_call(self, name=name, info=pprint.pformat(dict(info)))
- uuid = udev.device_get_uuid(info)
+ def _reason_to_skip_device(self, info):
sysfs_path = udev.device_get_sysfs_path(info)
+ uuid = udev.device_get_uuid(info)
# make sure this device was not scheduled for removal and also has not
# been hidden
- removed = [a.device for a in self.devicetree.actions.find(
- action_type="destroy",
- object_type="device")]
+ removed = [a.device for a in self.devicetree.actions.find(action_type="destroy",
+ object_type="device")]
for ignored in removed + self.devicetree._hidden:
if (sysfs_path and ignored.sysfs_path == sysfs_path) or \
(uuid and uuid in (ignored.uuid, ignored.format.uuid)):
@@ -234,85 +226,60 @@ def add_udev_device(self, info, update_orig_fmt=False):
else:
reason = "hidden"
- log.debug("skipping %s device %s", reason, name)
- return
-
- # make sure we note the name of every device we see
- if name not in self.names:
- self.names.append(name)
-
- if self.is_ignored(info):
- log.info("ignoring %s (%s)", name, sysfs_path)
- if name not in self.ignored_disks:
- self.add_ignored_disk(name)
+ return reason
+ def _handle_degraded_md(self, info, device):
+ if device is not None or not udev.device_is_md(info):
return
- log.info("scanning %s (%s)...", name, sysfs_path)
- device = self.get_device_by_name(name)
- if device is None and udev.device_is_md(info):
-
- # If the md name is None, then some udev info is missing. Likely,
- # this is because the array is degraded, and mdadm has deactivated
- # it. Try to activate it and re-get the udev info.
- if flags.allow_imperfect_devices and udev.device_get_md_name(info) is None:
- devname = udev.device_get_devname(info)
- if devname:
- try:
- blockdev.md.run(devname)
- except blockdev.MDRaidError as e:
- log.warning("Failed to start possibly degraded md array: %s", e)
- else:
- udev.settle()
- info = udev.get_device(sysfs_path)
+ # If the md name is None, then some udev info is missing. Likely,
+ # this is because the array is degraded, and mdadm has deactivated
+ # it. Try to activate it and re-get the udev info.
+ if flags.allow_imperfect_devices and udev.device_get_md_name(info) is None:
+ devname = udev.device_get_devname(info)
+ if devname:
+ try:
+ blockdev.md.run(devname)
+ except blockdev.MDRaidError as e:
+ log.warning("Failed to start possibly degraded md array: %s", e)
else:
- log.warning("Failed to get devname for possibly degraded md array.")
-
- md_name = udev.device_get_md_name(info)
- if md_name is None:
- log.warning("No name for possibly degraded md array.")
+ udev.settle()
+ info = udev.get_device(udev.device_get_sysfs_path(info))
else:
- device = self.get_device_by_name(md_name, incomplete=flags.allow_imperfect_devices)
-
- if device and not isinstance(device, MDRaidArrayDevice):
- log.warning("Found device %s, but it turns out not be an md array device after all.", device.name)
- device = None
-
- if device and device.is_disk and \
- blockdev.mpath.is_mpath_member(device.path):
- # newly added device (eg iSCSI) could make this one a multipath member
- if device.format and device.format.type != "multipath_member":
- log.debug("%s newly detected as multipath member, dropping old format and removing kids", device.name)
- # remove children from tree so that we don't stumble upon them later
- for child in self.devicetree.get_children(device):
- self.devicetree.recursive_remove(child, actions=False)
-
- device.format = None
-
- #
- # The first step is to either look up or create the device
- #
- device_added = True
- helper_class = None
- if device:
- device_added = False
+ log.warning("Failed to get devname for possibly degraded md array.")
+
+ md_name = udev.device_get_md_name(info)
+ if md_name is None:
+ log.warning("No name for possibly degraded md array.")
else:
- helper_class = get_device_helper(info)
+ device = self.get_device_by_name(md_name, incomplete=flags.allow_imperfect_devices)
- if helper_class is not None:
- device = helper_class(self, info).run()
+ if device and not isinstance(device, MDRaidArrayDevice):
+ log.warning("Found device %s, but it turns out not be an md array device after all.", device.name)
+ device = None
- if not device:
- log.debug("no device obtained for %s", name)
+ return device
+
+ def _clear_new_multipath_member(self, device):
+ if device is None or not device.is_disk or not blockdev.mpath.is_mpath_member(device.path):
return
- log.info("got device: %r", device)
+ # newly added device (eg iSCSI) could make this one a multipath member
+ if device.format and device.format.type != "multipath_member":
+ log.debug("%s newly detected as multipath member, dropping old format and removing kids", device.name)
+ # remove children from tree so that we don't stumble upon them later
+ for child in self.devicetree.get_children(device):
+ self.devicetree.recursive_remove(child, actions=False)
+
+ device.format = None
+ def _mark_readonly_device(self, info, device):
# If this device is read-only, mark it as such now.
if self.udev_device_is_disk(info) and \
util.get_sysfs_attr(udev.device_get_sysfs_path(info), 'ro') == '1':
device.readonly = True
+ def _mark_protected_device(self, device):
# If this device is protected, mark it as such now. Once the tree
# has been populated, devices' protected attribute is how we will
# identify protected devices.
@@ -324,6 +291,7 @@ def add_udev_device(self, info, update_orig_fmt=False):
for parent in device.parents:
parent.protected = True
+ def _update_exclusive_disks(self, device):
# If we just added a multipath or fwraid disk that is in exclusive_disks
# we have to make sure all of its members are in the list too.
mdclasses = (DMRaidArrayDevice, MDRaidArrayDevice, MultipathDevice)
@@ -333,6 +301,52 @@ def add_udev_device(self, info, update_orig_fmt=False):
if parent.name not in self.exclusive_disks:
self.exclusive_disks.append(parent.name)
+ def add_udev_device(self, info, update_orig_fmt=False):
+ """
+ :param :class:`pyudev.Device` info: udev info for the device
+ :keyword bool update_orig_fmt: update original format unconditionally
+
+ If a device is added to the tree based on info its original format
+ will be saved after the format has been detected. If the device
+ that corresponds to info is already in the tree, its original format
+ will not be updated unless update_orig_fmt is True.
+ """
+ name = udev.device_get_name(info)
+ log_method_call(self, name=name, info=pprint.pformat(dict(info)))
+ sysfs_path = udev.device_get_sysfs_path(info)
+
+ reason = self._reason_to_skip_device(info)
+ if reason:
+ log.debug("skipping %s device %s", reason, name)
+ return
+
+ log.info("scanning %s (%s)...", name, sysfs_path)
+
+ # make sure we note the name of every device we see
+ self._add_name(name)
+ device = self.get_device_by_name(name)
+ device = self._handle_degraded_md(info, device)
+ self._clear_new_multipath_member(device)
+
+ device_added = True
+ helper_class = None
+ if device:
+ device_added = False
+ else:
+ helper_class = get_device_helper(info)
+
+ if helper_class is not None:
+ device = helper_class(self, info).run()
+
+ if not device:
+ log.debug("no device obtained for %s", name)
+ return
+
+ log.info("got device: %r", device)
+ self._mark_readonly_device(info, device)
+ self._mark_protected_device(device)
+ self._update_exclusive_disks(device)
+
# now handle the device's formatting
self.handle_udev_device_format(info, device)
if device_added or update_orig_fmt:
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/abef137159a63ee1c92f5e8ee7be...
8 years, 5 months
[master 13/27] Remove some extraneous methods related to ignored
devices.
by dashea
From: David Lehman <dlehman(a)redhat.com>
This is just a bunch of code that has been mostly obsolete for a
long time.
is_ignored doesn't actually consult the list of ignored/exclusive
disks -- instead, it just adds some additional cases in which we
might want to ignore a device. I think this information is better
stored elsewhere, if only to reduce the number of methods with the
word "ignore" in the name.
Things ignored because of is_ignored:
1. /dev/ram*
This is already handled by blivet.udev.__is_blacklisted_blockdev.
2. loop devices with no backing file
This is a good idea, and is preserved by an accompanying patch
to populator.handlers.LoopDevicePopulator's match method.
Things not ignored because of is_ignored (a no-op, really):
1. md container arrays
2. fwraid arrays whose name was mangled by mdadm because of
HOMEHOST.
3. mapped disk images
4. live media images
5. loop devices with a backing file
The only place we call add_ignored_disk is right after is_ignored
returns True for a device. It is not appropriate in any of the
cases flagged by is_ignored to add the device to the lvm device
blacklist.
---
blivet/populator/populator.py | 62 -------------------------------------------
1 file changed, 62 deletions(-)
diff --git a/blivet/populator/populator.py b/blivet/populator/populator.py
index 4592b3b..15c22e9 100644
--- a/blivet/populator/populator.py
+++ b/blivet/populator/populator.py
@@ -21,7 +21,6 @@
#
import os
-import re
import shutil
import pprint
import copy
@@ -130,67 +129,6 @@ def set_disk_images(self, images):
# disk image files are automatically exclusive
self.exclusive_disks = list(self.disk_images.keys())
- def add_ignored_disk(self, disk):
- self.ignored_disks.append(disk)
- lvm.lvm_cc_addFilterRejectRegexp(disk)
-
- def is_ignored(self, info):
- """ Return True if info is a device we should ignore.
-
- :param info: udevdb device entry
- :type info: dict
- :returns: whether the device will be ignored
- :rtype: bool
-
- """
- sysfs_path = udev.device_get_sysfs_path(info)
- name = udev.device_get_name(info)
- if not sysfs_path:
- return None
-
- # Special handling for mdraid external metadata sets (mdraid BIOSRAID):
- # 1) The containers are intermediate devices which will never be
- # in exclusive_disks
- # 2) Sets get added to exclusive disks with their dmraid set name by
- # the filter ui. Note that making the ui use md names instead is not
- # possible as the md names are simpy md# and we cannot predict the #
- if udev.device_is_md(info) and \
- udev.device_get_md_level(info) == "container":
- return False
-
- if udev.device_get_md_container(info) and \
- udev.device_is_md(info) and \
- udev.device_get_md_name(info):
- md_name = udev.device_get_md_name(info)
- # mdadm may have appended _<digit>+ if the current hostname
- # does not match the one in the array metadata
- alt_name = re.sub(r"_\d+$", "", md_name)
- raw_pattern = "isw_[a-z]*_%s"
- # XXX FIXME: This is completely insane.
- for i in range(0, len(self.exclusive_disks)):
- if re.match(raw_pattern % md_name, self.exclusive_disks[i]) or \
- re.match(raw_pattern % alt_name, self.exclusive_disks[i]):
- self.exclusive_disks[i] = name
- return False
-
- # never ignore mapped disk images. if you don't want to use them,
- # don't specify them in the first place
- if udev.device_is_dm_anaconda(info) or udev.device_is_dm_livecd(info):
- return False
-
- # Ignore loop and ram devices, we normally already skip these in
- # udev.py: enumerate_block_devices(), but we can still end up trying
- # to add them to the tree when they are slaves of other devices, this
- # happens for example with the livecd
- if name.startswith("ram"):
- return True
-
- if name.startswith("loop"):
- # ignore loop devices unless they're backed by a file
- return (not blockdev.loop.get_backing_file(name))
-
- # FIXME: check for virtual devices whose slaves are on the ignore list
-
def _is_ignored_disk(self, disk):
return self.devicetree._is_ignored_disk(disk)
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/ce45f07827acf7ed2e53c3c42f6a...
8 years, 5 months