Quellcode durchsuchen

Merge pull request #6908 from tzumainn/fix-cinder-mount

Automatic merge from submit-queue.

add cinder mountpoint to inventory

Although the heat templates specify /dev/sdb as a mountpoint for cinder volumes, openstack does not always respect that setting. This PR updates inventory.py to figure out the correct mountpoint from the openstack API; and passes that information into the docker-storage-setup.
OpenShift Merge Robot vor 7 Jahren
Ursprung
Commit
0e77fc1ca0

+ 38 - 10
playbooks/openstack/inventory.py

@@ -15,18 +15,10 @@ import json
 import shade
 
 
-def build_inventory():
-    '''Build the dynamic inventory.'''
-    cloud = shade.openstack_cloud()
-
+def base_openshift_inventory(cluster_hosts):
+    '''Set the base openshift inventory.'''
     inventory = {}
 
-    # TODO(shadower): filter the servers based on the `OPENSHIFT_CLUSTER`
-    # environment variable.
-    cluster_hosts = [
-        server for server in cloud.list_servers()
-        if 'metadata' in server and 'clusterid' in server.metadata]
-
     masters = [server.name for server in cluster_hosts
                if server.metadata['host-type'] == 'master']
 
@@ -67,6 +59,34 @@ def build_inventory():
     inventory['dns'] = {'hosts': dns}
     inventory['lb'] = {'hosts': load_balancers}
 
+    return inventory
+
+
+def get_docker_storage_mountpoints(volumes):
+    '''Check volumes to see if they're being used for docker storage'''
+    docker_storage_mountpoints = {}
+    for volume in volumes:
+        if volume.metadata.get('purpose') == "openshift_docker_storage":
+            for attachment in volume.attachments:
+                if attachment.server_id in docker_storage_mountpoints:
+                    docker_storage_mountpoints[attachment.server_id].append(attachment.device)
+                else:
+                    docker_storage_mountpoints[attachment.server_id] = [attachment.device]
+    return docker_storage_mountpoints
+
+
+def build_inventory():
+    '''Build the dynamic inventory.'''
+    cloud = shade.openstack_cloud()
+
+    # TODO(shadower): filter the servers based on the `OPENSHIFT_CLUSTER`
+    # environment variable.
+    cluster_hosts = [
+        server for server in cloud.list_servers()
+        if 'metadata' in server and 'clusterid' in server.metadata]
+
+    inventory = base_openshift_inventory(cluster_hosts)
+
     for server in cluster_hosts:
         if 'group' in server.metadata:
             group = server.metadata.group
@@ -76,6 +96,9 @@ def build_inventory():
 
     inventory['_meta'] = {'hostvars': {}}
 
+    # cinder volumes used for docker storage
+    docker_storage_mountpoints = get_docker_storage_mountpoints(cloud.list_volumes())
+
     for server in cluster_hosts:
         ssh_ip_address = server.public_v4 or server.private_v4
         hostvars = {
@@ -111,6 +134,11 @@ def build_inventory():
         if node_labels:
             hostvars['openshift_node_labels'] = node_labels
 
+        # check for attached docker storage volumes
+        if 'os-extended-volumes:volumes_attached' in server:
+            if server.id in docker_storage_mountpoints:
+                hostvars['docker_storage_mountpoints'] = ' '.join(docker_storage_mountpoints[server.id])
+
         inventory['_meta']['hostvars'][server.name] = hostvars
     return inventory
 

+ 4 - 0
roles/openshift_openstack/templates/docker-storage-setup-dm.j2

@@ -1,4 +1,8 @@
+{% if docker_storage_mountpoints is defined %}
+DEVS="{{ docker_storage_mountpoints }}"
+{% else %}
 DEVS="{{ openshift_openstack_container_storage_setup.docker_dev }}"
+{% endif %}
 VG="{{ openshift_openstack_container_storage_setup.docker_vg }}"
 DATA_SIZE="{{ openshift_openstack_container_storage_setup.docker_data_size }}"
 EXTRA_DOCKER_STORAGE_OPTIONS="--storage-opt dm.basesize={{ openshift_openstack_container_storage_setup.docker_dm_basesize }}"

+ 4 - 0
roles/openshift_openstack/templates/docker-storage-setup-overlayfs.j2

@@ -1,4 +1,8 @@
+{% if docker_storage_mountpoints is defined %}
+DEVS="{{ docker_storage_mountpoints }}"
+{% else %}
 DEVS="{{ openshift_openstack_container_storage_setup.docker_dev }}"
+{% endif %}
 VG="{{ openshift_openstack_container_storage_setup.docker_vg }}"
 DATA_SIZE="{{ openshift_openstack_container_storage_setup.docker_data_size }}"
 STORAGE_DRIVER=overlay2

+ 2 - 1
roles/openshift_openstack/templates/heat_stack_server.yaml.j2

@@ -261,11 +261,12 @@ resources:
     properties:
       size: { get_param: volume_size }
       availability_zone: { get_param: availability_zone }
+      metadata:
+        purpose: openshift_docker_storage
 
   volume_attachment:
     type: OS::Cinder::VolumeAttachment
     properties:
       volume_id: { get_resource: cinder_volume }
       instance_uuid: { get_resource: server }
-      mountpoint: /dev/sdb
 {% endif %}