Merge "test_absolute_limits.py to check limits response"
diff --git a/tempest/services/compute/json/limits_client.py b/tempest/services/compute/json/limits_client.py
index f363bf7..945477a 100644
--- a/tempest/services/compute/json/limits_client.py
+++ b/tempest/services/compute/json/limits_client.py
@@ -26,19 +26,15 @@
                                                auth_url, tenant_name)
         self.service = self.config.compute.catalog_type
 
-    def get_limits(self):
+    def get_absolute_limits(self):
         resp, body = self.get("limits")
         body = json.loads(body)
-        return resp, body['limits']
+        return resp, body['limits']['absolute']
 
-    def get_max_server_meta(self):
-        resp, limits_dict = self.get_limits()
-        return resp, limits_dict['absolute']['maxServerMeta']
-
-    def get_personality_file_limit(self):
-        resp, limits_dict = self.get_limits()
-        return resp, limits_dict['absolute']['maxPersonality']
-
-    def get_personality_size_limit(self):
-        resp, limits_dict = self.get_limits()
-        return resp, limits_dict['absolute']['maxPersonalitySize']
+    def get_specific_absolute_limit(self, absolute_limit):
+        resp, body = self.get("limits")
+        body = json.loads(body)
+        if absolute_limit not in body['limits']['absolute']:
+            return None
+        else:
+            return body['limits']['absolute'][absolute_limit]
diff --git a/tempest/services/compute/xml/limits_client.py b/tempest/services/compute/xml/limits_client.py
index 75142a9..229dbee 100644
--- a/tempest/services/compute/xml/limits_client.py
+++ b/tempest/services/compute/xml/limits_client.py
@@ -29,7 +29,7 @@
                                               auth_url, tenant_name)
         self.service = self.config.compute.catalog_type
 
-    def get_limits(self):
+    def get_absolute_limits(self):
         resp, body = self.get("limits", self.headers)
         body = objectify.fromstring(body)
         lim = NS + 'absolute'
@@ -37,23 +37,19 @@
 
         for el in body[lim].iterchildren():
             attributes = el.attrib
-            if attributes['name'] == 'maxServerMeta':
-                ret['maxServerMeta'] = int(attributes['value'])
-            elif attributes['name'] == 'maxPersonality':
-                ret['maxPersonality'] = int(attributes['value'])
-            elif attributes['name'] == 'maxPersonalitySize':
-                ret['maxPersonalitySize'] = int(attributes['value'])
-
+            ret[attributes['name']] = attributes['value']
         return resp, ret
 
-    def get_max_server_meta(self):
-        resp, limits_dict = self.get_limits()
-        return resp, limits_dict['maxServerMeta']
+    def get_specific_absolute_limit(self, absolute_limit):
+        resp, body = self.get("limits", self.headers)
+        body = objectify.fromstring(body)
+        lim = NS + 'absolute'
+        ret = {}
 
-    def get_personality_file_limit(self):
-        resp, limits_dict = self.get_limits()
-        return resp, limits_dict['maxPersonality']
-
-    def get_personality_size_limit(self):
-        resp, limits_dict = self.get_limits()
-        return resp, limits_dict['maxPersonalitySize']
+        for el in body[lim].iterchildren():
+            attributes = el.attrib
+            ret[attributes['name']] = attributes['value']
+        if absolute_limit not in ret:
+            return None
+        else:
+            return ret[absolute_limit]
diff --git a/tempest/tests/compute/limits/__init__.py b/tempest/tests/compute/limits/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tempest/tests/compute/limits/__init__.py
diff --git a/tempest/tests/compute/limits/test_absolute_limits.py b/tempest/tests/compute/limits/test_absolute_limits.py
new file mode 100644
index 0000000..ede0dc2
--- /dev/null
+++ b/tempest/tests/compute/limits/test_absolute_limits.py
@@ -0,0 +1,68 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2012 OpenStack, LLC
+# All Rights Reserved.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+import unittest2 as unittest
+
+from tempest.tests.compute import base
+
+
+class AbsoluteLimitsTest(object):
+
+    @staticmethod
+    def setUpClass(cls):
+        cls.client = cls.limits_client
+
+    @unittest.skip("Skipped until the Bug #1025294 is resolved")
+    def test_absLimits_get(self):
+        """
+        To check if all limits are present in the response
+        """
+        resp, absolute_limits = self.client.get_absolute_limits()
+        expected_elements = ['maxImageMeta', 'maxPersonality',
+                             'maxPersonalitySize',
+                             'maxPersonalityFilePathSize',
+                             'maxServerMeta', 'maxTotalCores',
+                             'maxTotalFloatingIps', 'maxSecurityGroups',
+                             'maxSecurityGroupRules', 'maxTotalInstances',
+                             'maxTotalKeypairs', 'maxTotalRAMSize',
+                             'maxTotalVolumeGigabytes', 'maxTotalVolumes',
+                             'totalCoresUsed', 'totalFloatingIpsUsed',
+                             'totalSecurityGroupsUsed', 'totalInstancesUsed',
+                             'totalKeyPairsUsed', 'totalRAMUsed',
+                             'totalVolumeGigabytesUsed', 'totalVolumesUsed']
+        # check whether all expected elements exist
+        missing_elements =\
+            [ele for ele in expected_elements if ele not in absolute_limits]
+        self.assertEqual(0, len(missing_elements),
+                         "Failed to find element %s in absolute limits list"
+                         % ', '.join(ele for ele in missing_elements))
+
+
+class AbsoluteLimitsTestJSON(base.BaseComputeTestJSON,
+                             AbsoluteLimitsTest):
+    @classmethod
+    def setUpClass(cls):
+        super(AbsoluteLimitsTestJSON, cls).setUpClass()
+        AbsoluteLimitsTest.setUpClass(cls)
+
+
+class AbsoluteLimitsTestXML(base.BaseComputeTestXML,
+                            AbsoluteLimitsTest):
+    @classmethod
+    def setUpClass(cls):
+        super(AbsoluteLimitsTestXML, cls).setUpClass()
+        AbsoluteLimitsTest.setUpClass(cls)
diff --git a/tempest/tests/compute/servers/test_server_personality.py b/tempest/tests/compute/servers/test_server_personality.py
index a570aec..75457d1 100644
--- a/tempest/tests/compute/servers/test_server_personality.py
+++ b/tempest/tests/compute/servers/test_server_personality.py
@@ -34,8 +34,9 @@
         name = rand_name('server')
         file_contents = 'This is a test file.'
         personality = []
-        _, max_file_limit = self.user_client.get_personality_file_limit()
-        for i in range(0, max_file_limit + 1):
+        max_file_limit = \
+            self.user_client.get_specific_absolute_limit("maxPersonality")
+        for i in range(0, int(max_file_limit) + 1):
             path = 'etc/test' + str(i) + '.txt'
             personality.append({'path': path,
                                 'contents': base64.b64encode(file_contents)})
@@ -57,18 +58,16 @@
             name = rand_name('server')
             file_contents = 'This is a test file.'
 
-            cli_resp = self.user_client.get_personality_file_limit()
-            resp, max_file_limit = cli_resp
-            self.assertEqual(200, resp.status)
+            max_file_limit = \
+                self.user_client.get_specific_absolute_limit("maxPersonality")
 
             personality = []
-            for i in range(0, max_file_limit):
+            for i in range(0, int(max_file_limit)):
                 path = 'etc/test' + str(i) + '.txt'
                 personality.append({
                     'path': path,
                     'contents': base64.b64encode(file_contents),
                 })
-
             resp, server = self.client.create_server(name, self.image_ref,
                                                      self.flavor_ref,
                                                      personality=personality)