aboutsummaryrefslogtreecommitdiff
path: root/docker/kolla-toolbox
diff options
context:
space:
mode:
authorPaul Bourke <paul.bourke@oracle.com>2016-11-16 14:12:38 +0000
committerPaul Bourke <paul.bourke@oracle.com>2016-11-16 14:15:57 +0000
commitdc0c07e0bf54cd461799716be438c708841d386e (patch)
tree2009df99d60104a06c7263a301282348de6b7bd6 /docker/kolla-toolbox
parent870616f8858556e4dc5abb3838259d12c14e0263 (diff)
downloadkolla-dc0c07e0bf54cd461799716be438c708841d386e.tar.gz
kolla-dc0c07e0bf54cd461799716be438c708841d386e.zip
Add a 'fallback mode' to disable udev in find_disks
As part of change I362b3f8e91de79687fc84e256996fbcaf303b6af a check was added to use udev to read GPT labels only if the version of udev installed supports that, otherwise fallback to sgdisk. Unfortunately the check for udev version is unreliable, as it is returning the version of the udev userspace tools installed within the container rather than on the host. As well as this, we're seeing the find_disks.py having trouble reading the UUID of a partition via udev. The test system is Oracle VM 3.4.2 which was released earlier this year, but has an old udev (derivative of RHEL 6). Even if we use Ansible to query the host's version of udev and pass that through to the container, querying the above disk attributes is a lottery on older systems without a reliable reference of which versions of udev support which operations. Hence we should give operators a reliable way to toggle it's usage. Partial-Bug: 1631949 Change-Id: I6ad7825cdb164498f3d02f2ae064c7c1c38e10d5
Diffstat (limited to 'docker/kolla-toolbox')
-rw-r--r--docker/kolla-toolbox/find_disks.py66
1 files changed, 42 insertions, 24 deletions
diff --git a/docker/kolla-toolbox/find_disks.py b/docker/kolla-toolbox/find_disks.py
index 3a7fa4602..332d30d86 100644
--- a/docker/kolla-toolbox/find_disks.py
+++ b/docker/kolla-toolbox/find_disks.py
@@ -38,6 +38,16 @@ options:
required: True
type: str
aliases: [ 'partition_name' ]
+ use_udev:
+ description:
+ - When True, use Linux udev to read disk info such as partition labels,
+ uuid, etc. Some older host operating systems have issues using udev to
+ get the info this module needs. Set to False to fall back to more low
+ level commands such as blkid to retrieve this information. Most users
+ should not need to change this.
+ default: True
+ required: False
+ type: bool
author: Sam Yaple
'''
@@ -70,23 +80,14 @@ import re
import subprocess # nosec
-def get_id_part_entry_name(dev):
- # NOTE(pbourke): Old versions of udev have trouble retrieving GPT partition
- # labels. In this case shell out to sgdisk.
- try:
- udev_version = pyudev.udev_version()
- except (ValueError, EnvironmentError, subprocess.CalledProcessError):
- udev_version = -1
-
- if udev_version >= 180:
+def get_id_part_entry_name(dev, use_udev):
+ if use_udev:
dev_name = dev.get('ID_PART_ENTRY_NAME', '')
else:
part = re.sub(r'.*[^\d]', '', dev.device_node)
parent = dev.find_parent('block').device_node
# NOTE(Mech422): Need to use -i as -p truncates the partition name
- # TODO(pbourke): Consider some form of validation to be performed on
- # part/parent [0]
- out = subprocess.Popen(['/usr/sbin/sgdisk', '-i', part, # nosec [0]
+ out = subprocess.Popen(['/usr/sbin/sgdisk', '-i', part, # nosec
parent],
stdout=subprocess.PIPE).communicate()
match = re.search(r'Partition name: \'(\w+)\'', out[0])
@@ -97,9 +98,24 @@ def get_id_part_entry_name(dev):
return dev_name
-def is_dev_matched_by_name(dev, name, mode):
+def get_id_fs_uuid(dev, use_udev):
+ if use_udev:
+ id_fs_uuid = dev.get('ID_FS_UUID', '')
+ else:
+ out = subprocess.Popen(['/usr/sbin/blkid', '-o', 'export', # nosec
+ dev.device_node],
+ stdout=subprocess.PIPE).communicate()
+ match = re.search(r'\nUUID=([\w-]+)', out[0])
+ if match:
+ id_fs_uuid = match.group(1)
+ else:
+ id_fs_uuid = ''
+ return id_fs_uuid
+
+
+def is_dev_matched_by_name(dev, name, mode, use_udev):
if dev.get('DEVTYPE', '') == 'partition':
- dev_name = get_id_part_entry_name(dev)
+ dev_name = get_id_part_entry_name(dev, use_udev)
else:
dev_name = dev.get('ID_FS_LABEL', '')
@@ -111,32 +127,32 @@ def is_dev_matched_by_name(dev, name, mode):
return False
-def find_disk(ct, name, match_mode):
+def find_disk(ct, name, match_mode, use_udev):
for dev in ct.list_devices(subsystem='block'):
- if is_dev_matched_by_name(dev, name, match_mode):
+ if is_dev_matched_by_name(dev, name, match_mode, use_udev):
yield dev
-def extract_disk_info(ct, dev, name):
+def extract_disk_info(ct, dev, name, use_udev):
if not dev:
return
kwargs = dict()
- kwargs['fs_uuid'] = dev.get('ID_FS_UUID', '')
+ kwargs['fs_uuid'] = get_id_fs_uuid(dev, use_udev)
kwargs['fs_label'] = dev.get('ID_FS_LABEL', '')
if dev.get('DEVTYPE', '') == 'partition':
kwargs['device'] = dev.find_parent('block').device_node
kwargs['partition'] = dev.device_node
kwargs['partition_num'] = \
re.sub(r'.*[^\d]', '', dev.device_node)
- if is_dev_matched_by_name(dev, name, 'strict'):
+ if is_dev_matched_by_name(dev, name, 'strict', use_udev):
kwargs['external_journal'] = False
kwargs['journal'] = dev.device_node[:-1] + '2'
kwargs['journal_device'] = kwargs['device']
kwargs['journal_num'] = 2
else:
kwargs['external_journal'] = True
- journal_name = get_id_part_entry_name(dev) + '_J'
- for journal in find_disk(ct, journal_name, 'strict'):
+ journal_name = get_id_part_entry_name(dev, use_udev) + '_J'
+ for journal in find_disk(ct, journal_name, 'strict', use_udev):
kwargs['journal'] = journal.device_node
kwargs['journal_device'] = \
journal.find_parent('block').device_node
@@ -155,17 +171,19 @@ def main():
argument_spec = dict(
match_mode=dict(required=False, choices=['strict', 'prefix'],
default='strict'),
- name=dict(aliases=['partition_name'], required=True, type='str')
+ name=dict(aliases=['partition_name'], required=True, type='str'),
+ use_udev=dict(required=False, default=True, type='bool')
)
module = AnsibleModule(argument_spec)
match_mode = module.params.get('match_mode')
name = module.params.get('name')
+ use_udev = module.params.get('use_udev')
try:
ret = list()
ct = pyudev.Context()
- for dev in find_disk(ct, name, match_mode):
- for info in extract_disk_info(ct, dev, name):
+ for dev in find_disk(ct, name, match_mode, use_udev):
+ for info in extract_disk_info(ct, dev, name, use_udev):
if info:
ret.append(info)