~charm-helpers/charm-helpers/devel

« back to all changes in this revision

Viewing changes to charmhelpers/contrib/storage/linux/utils.py

  • Committer: James Page
  • Date: 2016-04-20 12:04:21 UTC
  • mfrom: (535.2.2 c-h)
  • Revision ID: james.page@ubuntu.com-20160420120421-vpn364sxk2y3po55
Switch is_device_mounted to use lsblk

This will correct detect a wider range of 'is use' states compared
to parsing the output of /proc/mounts, including block devices that
are part of LVM volumes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
    :returns: boolean: True if the path represents a mounted device, False if
65
65
        it doesn't.
66
66
    '''
67
 
    is_partition = bool(re.search(r".*[0-9]+\b", device))
68
 
    out = check_output(['mount']).decode('UTF-8')
69
 
    if is_partition:
70
 
        return bool(re.search(device + r"\b", out))
71
 
    return bool(re.search(device + r"[0-9]*\b", out))
 
67
    try:
 
68
        out = check_output(['lsblk', '-P', device]).decode('UTF-8')
 
69
    except:
 
70
        return False
 
71
    return bool(re.search(r'MOUNTPOINT=".+"', out))