Merge "Added flavor filter tests: lp899979, lp899980, lp899982 * Modified flavor service to return results in line with other services * Added bug flag to tests that are failing due to known issues"
diff --git a/tempest/common/rest_client.py b/tempest/common/rest_client.py
index ea09cc0..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)
@@ -115,7 +120,12 @@
 
         if resp.status == 413:
             body = json.loads(body)
-            raise exceptions.OverLimit(body['overLimit']['message'])
+            if 'overLimit' in body:
+                raise exceptions.OverLimit(body['overLimit']['message'])
+            else:
+                raise exceptions.RateLimitExceeded(
+                    message=body['overLimitFault']['message'],
+                    details=body['overLimitFault']['details'])
 
         if resp.status in (500, 501):
             body = json.loads(body)
diff --git a/tempest/exceptions.py b/tempest/exceptions.py
index f1becda..a3fabe3 100644
--- a/tempest/exceptions.py
+++ b/tempest/exceptions.py
@@ -52,6 +52,11 @@
     message = "Endpoint not found"
 
 
+class RateLimitExceeded(TempestException):
+    message = ("Rate limit exceeded.\nMessage: %(message)s\n"
+               "Details: %(details)s")
+
+
 class OverLimit(TempestException):
     message = "Quota exceeded"