Ryan Barry has uploaded a new change for review. Change subject: Move multipath device checking to ovirt.node.utils.storage ......................................................................
Move multipath device checking to ovirt.node.utils.storage Move translate_device_name and its essential logic to the new codebase. Change-Id: I203d16f75fd9ed3b983cc240d8c9c34fd8189499 Signed-off-by: Ryan Barry <[email protected]> --- M src/ovirt/node/utils/storage.py M src/ovirtnode/ovirtfunctions.py M src/ovirtnode/storage.py 3 files changed, 62 insertions(+), 23 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/51/19951/1 diff --git a/src/ovirt/node/utils/storage.py b/src/ovirt/node/utils/storage.py index a050090..f2fdbce 100644 --- a/src/ovirt/node/utils/storage.py +++ b/src/ovirt/node/utils/storage.py @@ -22,6 +22,7 @@ from ovirt.node import base from ovirt.node.utils import process from ovirt.node.utils.fs import File +import re import os @@ -97,32 +98,65 @@ name = "/dev/%s" % name.rstrip('0123456789') return name + def translate_device_name(self, _dev): + """Discover whether a device can be mapped to a devicemapper name so + we can match arbitrary /dev/sd? names, such as flash drives + """ + self.logger.debug("Translating %s") + if _dev is None: + return False + if "/dev/cciss" in _dev: + _dev = "/dev/mapper/%s" % process.check_output(["cciss_id", _dev]) + if not "/dev/mapper" in _dev: + if not _dev.startswith("/dev/"): + _dev = "/dev/%s" % _dev + try: + output = [x for x in process.check_output(["multipath", "-ll", + _dev]).split('\n') if re.match(r'.*?dm-[0-9]+', + x)][0].strip() + _dev = "/dev/mapper/%s" % output.split()[0] + except process.CalledProcessError as e: + # multipath got a non-zero code. + self.logger.exception("Couldn't translate %s: %s" % (_dev, + e.cmd)) + except IndexError: + self.logger.exception("Translated %s, but didn't find the dm" + "path" % _dev) + + if not hasattr(self, 'disk_dict'): + # Haven't populated yet, do that first + self.get_all() + info = self.disk_dict[_dev].split(",", 5) + device = Device(_dev, *info) + return device + def get_all(self): """Get all available storage devices attached to this system """ if self._fake_devices: return self._fake_devices - from ovirtnode.ovirtfunctions import translate_multipath_device - dev_names, disk_dict = self._storage.get_udev_devices() + self.dev_names, self.disk_dict = self._storage.get_udev_devices() devices = {} - for _dev in dev_names: - dev = translate_multipath_device(_dev) + for _dev in self.dev_names: + # Can't translate CDROM names + if "/dev/sr0" in _dev: + continue + dev = self.translate_device_name(_dev).path self.logger.debug("Checking device %s (%s)" % (dev, _dev)) if dev in devices: self.logger.warning("Device is already in dict: %s" % dev) continue - if dev not in disk_dict: + if dev not in self.disk_dict: self.logger.warning("Device in names but not in dict: " + "%s" % dev) - continue if dev == self.live_disk_name(): self.logger.info("Ignoring device " + "%s it's the live media" % dev) continue - infos = disk_dict[dev].split(",", 5) + infos = self.disk_dict[dev].split(",", 5) device = Device(dev, *infos) device.name = os.path.basename(device.name).replace(" ", "") - device.name = translate_multipath_device(device.name) + device.name = self.translate_device_name(device.name) if device.name in devices: self.logger.debug("Device with same name already " + "exists: %s" % device.name) diff --git a/src/ovirtnode/ovirtfunctions.py b/src/ovirtnode/ovirtfunctions.py index 21363cf..ef38636 100644 --- a/src/ovirtnode/ovirtfunctions.py +++ b/src/ovirtnode/ovirtfunctions.py @@ -38,7 +38,7 @@ import grp import pwd from ovirt.node.config import defaults -from ovirt.node.utils import process +from ovirt.node.utils import process, storage import ovirt.node.utils.system as osystem OVIRT_CONFIG="/config" @@ -1270,7 +1270,7 @@ # Cleans partition tables def wipe_partitions(_drive): - drive = translate_multipath_device(_drive) + drive = storage.Devices().translate_device_name(_drive).path logger.info("Wiping partitions on: %s->%s" % (_drive, drive)) logger.info("Removing HostVG") if os.path.exists("/dev/mapper/HostVG-Swap"): diff --git a/src/ovirtnode/storage.py b/src/ovirtnode/storage.py index 635ded5..9f3aa4b 100644 --- a/src/ovirtnode/storage.py +++ b/src/ovirtnode/storage.py @@ -18,6 +18,7 @@ # also available at http://www.gnu.org/copyleft/gpl.html. import ovirtnode.ovirtfunctions as _functions +from ovirt.node.utils import storage import os import sys import time @@ -61,7 +62,8 @@ init = _functions.OVIRT_VARS["OVIRT_INIT"].strip(",").split(",") for disk in init: skip = False - translated_disk = _functions.translate_multipath_device(disk) + translated_disk = storage.Devices().translate_device_name( + disk).path if disk_count < 1: self.ROOTDRIVE = translated_disk if len(init) == 1: @@ -75,15 +77,16 @@ if not skip: self.HOSTVGDRIVE += "%s," % translated_disk else: - self.ROOTDRIVE = _functions.translate_multipath_device( - _functions.OVIRT_VARS["OVIRT_INIT"]) - self.HOSTVGDRIVE = _functions.translate_multipath_device( - _functions.OVIRT_VARS["OVIRT_INIT"]) + self.ROOTDRIVE = storage.Devices().translate_device_name( + _functions.OVIRT_VARS["OVIRT_INIT"]).path + self.HOSTVGDRIVE = storage.Devices().translate_device_name( + _functions.OVIRT_VARS["OVIRT_INIT"]).path if _functions.is_iscsi_install(): logger.info(self.BOOTDRIVE) logger.info(self.ROOTDRIVE) - self.BOOTDRIVE = _functions.translate_multipath_device( \ - self.ROOTDRIVE) + self.BOOTDRIVE = storage.Devices().translate_device_name( \ + self.ROOTDRIVE + ).path if "OVIRT_OVERCOMMIT" in OVIRT_VARS: self.overcommit = OVIRT_VARS["OVIRT_OVERCOMMIT"] if "OVIRT_VOL_SWAP_SIZE" in OVIRT_VARS: @@ -125,7 +128,7 @@ if "OVIRT_INIT_APP" in OVIRT_VARS: if self.SWAP2_SIZE != 0 or self.DATA2_SIZE != 0: for drv in _functions.OVIRT_VARS["OVIRT_INIT_APP"].split(","): - DRIVE = _functions.translate_multipath_device(drv) + DRIVE = storage.Devices().translate_device_name(drv).path self.APPVGDRIVE.append(DRIVE) else: if self.SWAP2_SIZE != 0 or self.DATA2_SIZE != 0: @@ -140,7 +143,7 @@ if self.ROOTDRIVE: hostvg_drives.append(self.ROOTDRIVE) # Translate to DM name as APPVG is using it - hostvg_drives = [_functions.translate_multipath_device(drv) + hostvg_drives = [storage.Devices().translate_device_name(drv).path for drv in hostvg_drives] return Storage._xcheck_vgs(hostvg_drives, self.APPVGDRIVE) @@ -389,7 +392,8 @@ if (not device.get_property("ID_CDROM") and not "/dev/dm-" in dev_name and not "/dev/loop" in dev_name and size_failed == 0): - dev_name = _functions.translate_multipath_device(dev_name) + dev_name = storage.Devices().translate_device_name( + dev_name).path busmap = { \ "usb": "USB Device ", \ "ata": "Local / FibreChannel", \ @@ -413,7 +417,7 @@ logger.info("Creating LVM partition") self.physical_vols = [] for drv in self.HOSTVGDRIVE.strip(",").split(","): - drv = _functions.translate_multipath_device(drv) + drv = storage.Devices().translate_device_name(drv).path if drv != "": if self.ROOTDRIVE == drv and not _functions.is_iscsi_install(): self.reread_partitions(self.ROOTDRIVE) @@ -823,8 +827,9 @@ str(partbootbackup) + "\"") _functions.system("ln -snf \"" + partbootbackup + "\" /dev/disk/by-label/BootBackup") - self.ISCSIDRIVE = _functions.translate_multipath_device( - _functions.OVIRT_VARS["OVIRT_ISCSI_INIT"]) + self.ISCSIDRIVE = storage.Devices().translate_device_name( + _functions.OVIRT_VARS["OVIRT_ISCSI_INIT"] + ).path logger.debug(self.ISCSIDRIVE) if self.create_iscsiroot(): logger.info("iSCSI Root Partitions Created") -- To view, visit http://gerrit.ovirt.org/19951 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I203d16f75fd9ed3b983cc240d8c9c34fd8189499 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-node Gerrit-Branch: master Gerrit-Owner: Ryan Barry <[email protected]> _______________________________________________ node-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/node-patches
