Esempio n. 1
0
 def test_find_mpath_members(self):
     """find_mpath_members enumerates kernel block devs of a mpath_id."""
     mp_id = 'mpatha'
     paths = ['device=bar multipath=mpatha', 'device=wark multipath=mpatha']
     self.m_subp.return_value = ("\n".join(paths), "")
     self.assertEqual(sorted(['/dev/bar', '/dev/wark']),
                      sorted(multipath.find_mpath_members(mp_id)))
Esempio n. 2
0
    def test_find_mpath_members_empty(self):
        """find_mpath_members returns empty list if mpath_id not found."""
        mp_id = self.random_string()
        paths = ['device=bar multipath=mpatha', 'device=wark multipath=mpatha']
        self.m_subp.return_value = ("\n".join(paths), "")

        self.assertEqual([], multipath.find_mpath_members(mp_id))
Esempio n. 3
0
def lookup_disk(serial):
    """
    Search for a disk by its serial number using /dev/disk/by-id/
    """
    # Get all volumes in /dev/disk/by-id/ containing the serial string. The
    # string specified can be either in the short or long serial format
    # hack, some serials have spaces, udev usually converts ' ' -> '_'
    serial_udev = serial.replace(' ', '_')
    LOG.info('Processing serial %s via udev to %s', serial, serial_udev)

    disks = list(
        filter(lambda x: serial_udev in x, os.listdir("/dev/disk/by-id/")))
    if not disks or len(disks) < 1:
        raise ValueError("no disk with serial '%s' found" % serial_udev)

    # Sort by length and take the shortest path name, as the longer path names
    # will be the partitions on the disk. Then use os.path.realpath to
    # determine the path to the block device in /dev/
    disks.sort(key=lambda x: len(x))
    LOG.debug('lookup_disks found: %s', disks)
    path = os.path.realpath("/dev/disk/by-id/%s" % disks[0])
    LOG.debug('lookup_disks realpath(%s)=%s', disks[0], path)
    if multipath.is_mpath_device(path):
        LOG.debug('Detected multipath device, finding a members')
        info = udevadm_info(path)
        mpath_members = sorted(multipath.find_mpath_members(info['DM_NAME']))
        LOG.debug('mpath members: %s', mpath_members)
        if len(mpath_members):
            path = mpath_members[0]

    if not os.path.exists(path):
        raise ValueError("path '%s' to block device for disk with serial '%s' \
            does not exist" % (path, serial_udev))
    return path