Merge "Fixes LP#920812 - KeyError: 'overLimit' on 413 return"
diff --git a/tempest/common/rest_client.py b/tempest/common/rest_client.py
index a795e02..7fc368e 100644
--- a/tempest/common/rest_client.py
+++ b/tempest/common/rest_client.py
@@ -68,6 +68,11 @@
             for ep in auth_data['serviceCatalog']:
                 if ep["name"] == service:
                     mgmt_url = ep['endpoints'][0]['publicURL']
+                    # See LP#920817. The tenantId is *supposed*
+                    # to be returned for each endpoint accorsing to the
+                    # Keystone spec. But... it isn't, so we have to parse
+                    # the tenant ID out of hte public URL :(
+                    tenant_id = mgmt_url.split('/')[-1]
                     break
 
             if mgmt_url == None:
@@ -77,7 +82,7 @@
             #Need to join strings more cleanly
             temp = mgmt_url.rsplit('/')
             service_url = temp[0] + '//' + temp[2] + '/' + temp[3] + '/'
-            management_url = service_url + tenant_name
+            management_url = service_url + tenant_id
             return token, management_url
         elif resp.status == 401:
             raise exceptions.AuthenticationFailure(user=user, password=api_key)