Add service/endpoint discover to verify_tempest_config

This commit adds a check to verify_tempest_config for which services
are available. This is used to do 2 things:

1. Verify that the entries in the service_availble group are set correctly
2. Use for filtering which checks inside the script are valid to perform

Partially implements bp config-verification

Change-Id: Ib0e55f21b83d0746994e7e7e1f9666524e1bb3b7
diff --git a/tools/verify_tempest_config.py b/tools/verify_tempest_config.py
index 79e1fe3..aa92c0b 100755
--- a/tools/verify_tempest_config.py
+++ b/tools/verify_tempest_config.py
@@ -138,21 +138,63 @@
                           "enabled extensions" % (service, extension))
 
 
-def check_service_availability(service):
-    if service == 'nova_v3':
-        service = 'nova'
-    return getattr(CONF.service_available, service)
+def check_service_availability(os):
+    services = []
+    avail_services = []
+    codename_match = {
+        'volume': 'cinder',
+        'network': 'neutron',
+        'image': 'glance',
+        'object_storage': 'swift',
+        'compute': 'nova',
+        'orchestration': 'heat',
+        'metering': 'ceilometer',
+        'telemetry': 'ceilometer',
+        'data_processing': 'savanna',
+        'baremetal': 'ironic',
+        'identity': 'keystone'
+
+    }
+    # Get catalog list for endpoints to use for validation
+    __, endpoints = os.endpoints_client.list_endpoints()
+    for endpoint in endpoints:
+        __, service = os.service_client.get_service(endpoint['service_id'])
+        services.append(service['type'])
+    # Pull all catalog types from config file and compare against endpoint list
+    for cfgname in dir(CONF._config):
+        cfg = getattr(CONF, cfgname)
+        catalog_type = getattr(cfg, 'catalog_type', None)
+        if not catalog_type:
+            continue
+        else:
+            if cfgname == 'identity':
+                # Keystone is a required service for tempest
+                continue
+            if catalog_type not in services:
+                if getattr(CONF.service_available, codename_match[cfgname]):
+                    print('Endpoint type %s not found either disable service '
+                          '%s or fix the catalog_type in the config file' % (
+                          catalog_type, codename_match[cfgname]))
+            else:
+                if not getattr(CONF.service_available,
+                               codename_match[cfgname]):
+                    print('Endpoint type %s is available, service %s should be'
+                          ' set as available in the config file.' % (
+                          catalog_type, codename_match[cfgname]))
+                else:
+                    avail_services.append(codename_match[cfgname])
+    return avail_services
 
 
 def main(argv):
     print('Running config verification...')
     os = clients.ComputeAdminManager(interface='json')
+    services = check_service_availability(os)
     results = {}
     for service in ['nova', 'nova_v3', 'cinder', 'neutron', 'swift']:
-        # TODO(mtreinish) make this a keystone endpoint check for available
-        # services
-        if not check_service_availability(service):
-            print("%s is not available" % service)
+        if service == 'nova_v3' and 'nova' not in services:
+            continue
+        elif service not in services:
             continue
         results = verify_extensions(os, service, results)
     verify_glance_api_versions(os)