From dd218173fa91c62489e0d73e2be576efaa48d5c9 Mon Sep 17 00:00:00 2001 From: David Lehman Date: Fri, 6 Mar 2015 12:21:58 -0600 Subject: [PATCH 06/19] Split _getSlaveNames out of _getSlaveDevices for reuse elsewhere. Also do the cciss name fixup after we've verified that we actually got udev info for the slave to avoid an unhandled exception. --- blivet/discoverer.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/blivet/discoverer.py b/blivet/discoverer.py index e10a8e2..0f7d2a8 100644 --- a/blivet/discoverer.py +++ b/blivet/discoverer.py @@ -198,9 +198,24 @@ class DeviceDiscoverer(object): (udev.device_is_md(info) and not udev.device_get_md_container(info)))) + def _getSlaveNames(self, info): + """ Return a list of slave device names as found in sysfs. + + :param :class:`pyudev.Device` info: the device's udev info + :returns: a list of slave/parent device names + :rtype: list of str + """ + sysfs_path = udev.device_get_sysfs_path(info) + slave_dir = os.path.normpath("%s/slaves" % sysfs_path) + slave_names = [] + if os.path.isdir(os.path.realpath(slave_dir)): + slave_names = os.listdir(slave_dir) + return slave_names + def _addSlaveDevices(self, info): """ Add all slaves of a device, raising DeviceTreeError on failure. + :param :class:`pyudev.Device` info: the device's udev info :raises: :class:`~.errors.DeviceTreeError if no slaves are found or if we fail to add any slave :returns: a list of slave devices @@ -208,23 +223,22 @@ class DeviceDiscoverer(object): """ name = udev.device_get_name(info) sysfs_path = udev.device_get_sysfs_path(info) - slave_dir = os.path.normpath("%s/slaves" % sysfs_path) - slave_names = os.listdir(slave_dir) + slave_names = self._getSlaveNames(info) slave_devices = [] if not slave_names: log.error("no slaves found for %s", name) raise DeviceTreeError("no slaves found for device %s" % name) + slave_dir = os.path.normpath("%s/slaves" % sysfs_path) for slave_name in slave_names: path = os.path.normpath("%s/%s" % (slave_dir, slave_name)) slave_info = udev.get_device(os.path.realpath(path)) - # cciss in sysfs is "cciss!cXdYpZ" but we need "cciss/cXdYpZ" - slave_name = udev.device_get_name(slave_info).replace("!", "/") - if not slave_info: log.warning("unable to get udev info for %s", slave_name) + # cciss in sysfs is "cciss!cXdYpZ" but we need "cciss/cXdYpZ" + slave_name = udev.device_get_name(slave_info).replace("!", "/") slave_dev = self.devicetree.getDeviceByName(slave_name) if not slave_dev and slave_info: # we haven't scanned the slave yet, so do it now -- 1.9.3