Browse Source

kuryr: fix linting tests

Change-Id: Ie90428e79d1ca97719300c64226d12c5a762244f
Signed-off-by: Antoni Segura Puimedon <antonisp@celebdor.com>
Antoni Segura Puimedon 7 years ago
parent
commit
a80f5e7d74

+ 48 - 42
playbooks/openstack/inventory.py

@@ -77,6 +77,49 @@ def get_docker_storage_mountpoints(volumes):
     return docker_storage_mountpoints
 
 
+def _get_hostvars(server, docker_storage_mountpoints):
+    ssh_ip_address = server.public_v4 or server.private_v4
+    hostvars = {
+        'ansible_host': ssh_ip_address
+    }
+
+    public_v4 = server.public_v4 or server.private_v4
+    if public_v4:
+        hostvars['public_v4'] = server.public_v4
+        hostvars['openshift_public_ip'] = server.public_v4
+    # TODO(shadower): what about multiple networks?
+    if server.private_v4:
+        hostvars['private_v4'] = server.private_v4
+        hostvars['openshift_ip'] = server.private_v4
+
+        # NOTE(shadower): Yes, we set both hostname and IP to the private
+        # IP address for each node. OpenStack doesn't resolve nodes by
+        # name at all, so using a hostname here would require an internal
+        # DNS which would complicate the setup and potentially introduce
+        # performance issues.
+        hostvars['openshift_hostname'] = server.metadata.get(
+            'openshift_hostname', server.private_v4)
+    hostvars['openshift_public_hostname'] = server.name
+
+    if server.metadata['host-type'] == 'cns':
+        hostvars['glusterfs_devices'] = ['/dev/nvme0n1']
+
+    node_labels = server.metadata.get('node_labels')
+    # NOTE(shadower): the node_labels value must be a dict not string
+    if not isinstance(node_labels, Mapping):
+        node_labels = json.loads(node_labels)
+
+    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])
+    return hostvars
+
+
 def build_inventory():
     '''Build the dynamic inventory.'''
     cloud = shade.openstack_cloud()
@@ -99,49 +142,12 @@ def build_inventory():
     inventory['_meta'] = {'hostvars': {}}
 
     # cinder volumes used for docker storage
-    docker_storage_mountpoints = get_docker_storage_mountpoints(cloud.list_volumes())
-
+    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 = {
-            'ansible_host': ssh_ip_address
-        }
-
-        public_v4 = server.public_v4 or server.private_v4
-        if public_v4:
-            hostvars['public_v4'] = server.public_v4
-            hostvars['openshift_public_ip'] = server.public_v4
-        # TODO(shadower): what about multiple networks?
-        if server.private_v4:
-            hostvars['private_v4'] = server.private_v4
-            hostvars['openshift_ip'] = server.private_v4
-
-            # NOTE(shadower): Yes, we set both hostname and IP to the private
-            # IP address for each node. OpenStack doesn't resolve nodes by
-            # name at all, so using a hostname here would require an internal
-            # DNS which would complicate the setup and potentially introduce
-            # performance issues.
-            hostvars['openshift_hostname'] = server.metadata.get(
-                'openshift_hostname', server.private_v4)
-        hostvars['openshift_public_hostname'] = server.name
-
-        if server.metadata['host-type'] == 'cns':
-            hostvars['glusterfs_devices'] = ['/dev/nvme0n1']
-
-        node_labels = server.metadata.get('node_labels')
-        # NOTE(shadower): the node_labels value must be a dict not string
-        if not isinstance(node_labels, Mapping):
-            node_labels = json.loads(node_labels)
-
-        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
+        inventory['_meta']['hostvars'][server.name] = _get_hostvars(
+            server,
+            docker_storage_mountpoints)
 
     stout = _get_stack_outputs(cloud)
     if stout is not None:

+ 5 - 1
roles/openshift_openstack/library/os_network_extensions.py

@@ -20,9 +20,9 @@
 # pylint: disable=unused-wildcard-import,wildcard-import,unused-import,redefined-builtin
 
 ''' os_network_extensions '''
+import keystoneauth1
 
 from ansible.module_utils.basic import AnsibleModule
-import keystoneauth1
 
 try:
     import shade
@@ -65,6 +65,7 @@ def main():
 
     try:
         cloud = shade.openstack_cloud()
+    # pylint: disable=broad-except
     except Exception:
         module.fail_json(msg='Failed to connect to the cloud')
 
@@ -75,12 +76,14 @@ def main():
             interface=cloud.cloud_config.get_interface('network'),
             endpoint_override=cloud.cloud_config.get_endpoint('network'),
             version=cloud.cloud_config.get_api_version('network'))
+    # pylint: disable=broad-except
     except Exception:
         module.fail_json(msg='Failed to get an adapter to talk to the Neutron '
                              'API')
 
     try:
         response = adapter.get('/extensions.json')
+    # pylint: disable=broad-except
     except Exception:
         module.fail_json(msg='Failed to retrieve Neutron extensions')
 
@@ -88,6 +91,7 @@ def main():
     try:
         for ext_record in response.json()['extensions']:
             extensions.append(ext_record['alias'])
+    # pylint: disable=broad-except
     except Exception:
         module.fail_json(msg='Failed to process cloud networking '
                          'extensions')