From cadf8afdcf4c1d56892b6d708003066e11711c5f Mon Sep 17 00:00:00 2001 From: Stephen Hindle Date: Tue, 7 Jun 2016 09:07:34 -0700 Subject: [PATCH] Read GPT label using sgdisk rather than udev The Ceph osd bootstrap/startup logic depends upon reading/writing partition names. Some older versions of udev have trouble reading these (/dev/disk/by-label is missing). To work around this, we shell out to sgdisk and scrape the partition name data directly. Co-authored-by: Paul Bourke Closes-Bug: 1585185 Change-Id: I362b3f8e91de79687fc84e256996fbcaf303b6af --- ansible/roles/ceph/tasks/bootstrap_osds.yml | 4 +-- ansible/roles/ceph/tasks/do_reconfigure.yml | 2 +- ansible/roles/ceph/tasks/start_osds.yml | 2 +- ansible/roles/swift/tasks/start.yml | 2 +- docker/kolla-toolbox/Dockerfile.j2 | 5 ++++ docker/kolla-toolbox/ansible_sudoers | 1 + docker/kolla-toolbox/find_disks.py | 29 +++++++++++++++++++-- 7 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 docker/kolla-toolbox/ansible_sudoers diff --git a/ansible/roles/ceph/tasks/bootstrap_osds.yml b/ansible/roles/ceph/tasks/bootstrap_osds.yml index 47a9459c87..014d2dcd47 100644 --- a/ansible/roles/ceph/tasks/bootstrap_osds.yml +++ b/ansible/roles/ceph/tasks/bootstrap_osds.yml @@ -1,6 +1,6 @@ --- - name: Looking up disks to bootstrap for Ceph OSDs - command: docker exec -t kolla_toolbox /usr/bin/ansible localhost + command: docker exec -t kolla_toolbox sudo -E /usr/bin/ansible localhost -m find_disks -a "partition_name='KOLLA_CEPH_OSD_BOOTSTRAP' match_mode='prefix'" register: osd_lookup @@ -12,7 +12,7 @@ osds_bootstrap: "{{ (osd_lookup.stdout.split('localhost | SUCCESS => ')[1]|from_json).disks|from_json }}" - name: Looking up disks to bootstrap for Ceph Cache OSDs - command: docker exec -t kolla_toolbox /usr/bin/ansible localhost + command: docker exec -t kolla_toolbox sudo -E /usr/bin/ansible localhost -m find_disks -a "partition_name='KOLLA_CEPH_OSD_CACHE_BOOTSTRAP' match_mode='prefix'" register: osd_cache_lookup diff --git a/ansible/roles/ceph/tasks/do_reconfigure.yml b/ansible/roles/ceph/tasks/do_reconfigure.yml index 0406c3bf95..e1c7999523 100644 --- a/ansible/roles/ceph/tasks/do_reconfigure.yml +++ b/ansible/roles/ceph/tasks/do_reconfigure.yml @@ -10,7 +10,7 @@ - { name: ceph_mon, group: ceph-mon } - name: Looking up OSDs for Ceph - command: docker exec -t kolla_toolbox /usr/bin/ansible localhost + command: docker exec -t kolla_toolbox sudo -E /usr/bin/ansible localhost -m find_disks -a "partition_name='KOLLA_CEPH_DATA' match_mode='prefix'" register: osd_lookup diff --git a/ansible/roles/ceph/tasks/start_osds.yml b/ansible/roles/ceph/tasks/start_osds.yml index 0f4a9a76ef..c615cd6059 100644 --- a/ansible/roles/ceph/tasks/start_osds.yml +++ b/ansible/roles/ceph/tasks/start_osds.yml @@ -1,6 +1,6 @@ --- - name: Looking up OSDs for Ceph - command: docker exec -t kolla_toolbox /usr/bin/ansible localhost + command: docker exec -t kolla_toolbox sudo -E /usr/bin/ansible localhost -m find_disks -a "partition_name='KOLLA_CEPH_DATA' match_mode='prefix'" register: osd_lookup diff --git a/ansible/roles/swift/tasks/start.yml b/ansible/roles/swift/tasks/start.yml index 2f6db1f70b..9a2c6bbd7b 100644 --- a/ansible/roles/swift/tasks/start.yml +++ b/ansible/roles/swift/tasks/start.yml @@ -1,6 +1,6 @@ --- - name: Looking up disks for Swift - command: docker exec -t kolla_toolbox /usr/bin/ansible localhost + command: docker exec -t kolla_toolbox sudo -E /usr/bin/ansible localhost -m find_disks -a "name={{ swift_devices_name }} match_mode={{ swift_devices_match_mode }}" diff --git a/docker/kolla-toolbox/Dockerfile.j2 b/docker/kolla-toolbox/Dockerfile.j2 index 351ba07f79..cdaf950504 100644 --- a/docker/kolla-toolbox/Dockerfile.j2 +++ b/docker/kolla-toolbox/Dockerfile.j2 @@ -7,6 +7,7 @@ MAINTAINER {{ maintainer }} RUN yum -y install \ gcc \ + gdisk \ git \ libffi-devel \ libxml2-devel \ @@ -23,6 +24,7 @@ RUN yum -y install \ RUN apt-get -y --no-install-recommends install \ build-essential \ ca-certificates \ + gdisk \ git \ libffi-dev \ libmariadbclient-dev \ @@ -56,6 +58,9 @@ RUN useradd -m --user-group ansible --groups kolla \ COPY find_disks.py kolla_keystone_service.py kolla_keystone_user.py kolla_sanity.py kolla_zookeeper.py /usr/share/ansible/ COPY ansible.cfg /home/ansible/.ansible.cfg +COPY ansible_sudoers /etc/sudoers.d/ansible_sudoers +RUN chmod 440 /etc/sudoers.d/ansible_sudoers + CMD ["/bin/sleep", "infinity"] {{ include_footer }} diff --git a/docker/kolla-toolbox/ansible_sudoers b/docker/kolla-toolbox/ansible_sudoers new file mode 100644 index 0000000000..2f486cef99 --- /dev/null +++ b/docker/kolla-toolbox/ansible_sudoers @@ -0,0 +1 @@ +ansible ALL=(root) NOPASSWD: /usr/bin/ansible localhost -m find_disks -a * diff --git a/docker/kolla-toolbox/find_disks.py b/docker/kolla-toolbox/find_disks.py index dcb6e812b4..d1a6055f06 100644 --- a/docker/kolla-toolbox/find_disks.py +++ b/docker/kolla-toolbox/find_disks.py @@ -67,11 +67,36 @@ EXAMPLES = ''' import json import pyudev import re +import subprocess + + +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: + 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 + out = subprocess.Popen(['/usr/sbin/sgdisk', '-i', part, parent], + stdout=subprocess.PIPE).communicate() + match = re.search(r'Partition name: \'(\w+)\'', out[0]) + if match: + dev_name = match.group(1) + else: + dev_name = '' + return dev_name def is_dev_matched_by_name(dev, name, mode): if dev.get('DEVTYPE', '') == 'partition': - dev_name = dev.get('ID_PART_ENTRY_NAME', '') + dev_name = get_id_part_entry_name(dev) else: dev_name = dev.get('ID_FS_LABEL', '') @@ -107,7 +132,7 @@ def extract_disk_info(ct, dev, name): kwargs['journal_num'] = 2 else: kwargs['external_journal'] = True - journal_name = dev.get('ID_PART_ENTRY_NAME', '') + '_J' + journal_name = get_id_part_entry_name(dev) + '_J' for journal in find_disk(ct, journal_name, 'strict'): kwargs['journal'] = journal.device_node kwargs['journal_device'] = \