Merge "Modify limits fields according to microversion"
diff --git a/doc/source/microversion_testing.rst b/doc/source/microversion_testing.rst
index 6dd00d3..ce9bbb5 100644
--- a/doc/source/microversion_testing.rst
+++ b/doc/source/microversion_testing.rst
@@ -338,10 +338,18 @@
 
   .. _2.32: https://docs.openstack.org/nova/latest/reference/api-microversion-history.html#id29
 
+  * `2.36`_
+
+  .. _2.36: https://docs.openstack.org/nova/latest/reference/api-microversion-history.html#microversion
+
   * `2.37`_
 
   .. _2.37: https://docs.openstack.org/nova/latest/reference/api-microversion-history.html#id34
 
+  * `2.39`_
+
+  .. _2.39: https://docs.openstack.org/nova/latest/reference/api-microversion-history.html#id35
+
   * `2.42`_
 
   .. _2.42: https://docs.openstack.org/nova/latest/reference/api-microversion-history.html#maximum-in-ocata
diff --git a/tempest/api/compute/limits/test_absolute_limits.py b/tempest/api/compute/limits/test_absolute_limits.py
index 0585fec..8c2202e 100644
--- a/tempest/api/compute/limits/test_absolute_limits.py
+++ b/tempest/api/compute/limits/test_absolute_limits.py
@@ -18,6 +18,7 @@
 
 
 class AbsoluteLimitsTestJSON(base.BaseV2ComputeTest):
+    max_microversion = '2.56'
 
     @classmethod
     def setup_clients(cls):
@@ -26,22 +27,14 @@
 
     @decorators.idempotent_id('b54c66af-6ab6-4cf0-a9e5-a0cb58d75e0b')
     def test_absLimits_get(self):
-        # To check if all limits are present in the response
-        limits = self.client.show_limits()['limits']
-        absolute_limits = limits['absolute']
-        expected_elements = ['maxImageMeta', 'maxPersonality',
-                             'maxPersonalitySize',
-                             'maxServerMeta', 'maxTotalCores',
-                             'maxTotalFloatingIps', 'maxSecurityGroups',
-                             'maxSecurityGroupRules', 'maxTotalInstances',
-                             'maxTotalKeypairs', 'maxTotalRAMSize',
-                             'maxServerGroups', 'maxServerGroupMembers',
-                             'totalCoresUsed', 'totalFloatingIpsUsed',
-                             'totalSecurityGroupsUsed', 'totalInstancesUsed',
-                             'totalRAMUsed', 'totalServerGroupsUsed']
-        # check whether all expected elements exist
-        missing_elements =\
-            [ele for ele in expected_elements if ele not in absolute_limits]
-        self.assertEmpty(missing_elements,
-                         "Failed to find element %s in absolute limits list"
-                         % ', '.join(ele for ele in missing_elements))
+        # To check if all limits are present in the response (will be checked
+        # by schema)
+        self.client.show_limits()
+
+
+class AbsoluteLimitsV257TestJSON(base.BaseV2ComputeTest):
+    min_microversion = '2.57'
+    max_microversion = 'latest'
+
+    # NOTE(felipemonteiro): This class tests the Absolute Limits APIs
+    # response schema for the 2.57 microversion.
diff --git a/tempest/api/compute/limits/test_absolute_limits_negative.py b/tempest/api/compute/limits/test_absolute_limits_negative.py
index bef4eb5..500638a 100644
--- a/tempest/api/compute/limits/test_absolute_limits_negative.py
+++ b/tempest/api/compute/limits/test_absolute_limits_negative.py
@@ -33,15 +33,15 @@
 
     @decorators.attr(type=['negative'])
     @decorators.idempotent_id('215cd465-d8ae-49c9-bf33-9c911913a5c8')
-    def test_max_image_meta_exceed_limit(self):
-        # We should not create vm with image meta over maxImageMeta limit
+    def test_max_metadata_exceed_limit(self):
+        # We should not create vm with metadata over maxServerMeta limit
         # Get max limit value
         limits = self.client.show_limits()['limits']
-        max_meta = limits['absolute']['maxImageMeta']
+        max_meta = limits['absolute']['maxServerMeta']
 
         # No point in running this test if there is no limit.
         if max_meta == -1:
-            raise self.skipException('no limit for maxImageMeta')
+            raise self.skipException('no limit for maxServerMeta')
 
         # Create server should fail, since we are passing > metadata Limit!
         max_meta_data = max_meta + 1
diff --git a/tempest/lib/api_schema/response/compute/v2_36/__init__.py b/tempest/lib/api_schema/response/compute/v2_36/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tempest/lib/api_schema/response/compute/v2_36/__init__.py
diff --git a/tempest/lib/api_schema/response/compute/v2_36/limits.py b/tempest/lib/api_schema/response/compute/v2_36/limits.py
new file mode 100644
index 0000000..8e94690
--- /dev/null
+++ b/tempest/lib/api_schema/response/compute/v2_36/limits.py
@@ -0,0 +1,35 @@
+# Copyright 2018 ZTE Corporation.  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 copy
+
+from tempest.lib.api_schema.response.compute.v2_1 import limits as limitv21
+
+# Compute microversion 2.36:
+# remove attributes in get_limit:
+#    'maxSecurityGroupRules',
+#    'maxSecurityGroups',
+#    'maxTotalFloatingIps',
+#    'totalFloatingIpsUsed',
+#    'totalSecurityGroupsUsed'
+
+get_limit = copy.deepcopy(limitv21.get_limit)
+
+for item in ['maxSecurityGroupRules', 'maxSecurityGroups',
+             'maxTotalFloatingIps', 'totalFloatingIpsUsed',
+             'totalSecurityGroupsUsed']:
+    get_limit['response_body']['properties']['limits']['properties'][
+        'absolute']['properties'].pop(item)
+    get_limit['response_body']['properties']['limits']['properties'][
+        'absolute']['required'].remove(item)
diff --git a/tempest/lib/api_schema/response/compute/v2_39/__init__.py b/tempest/lib/api_schema/response/compute/v2_39/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tempest/lib/api_schema/response/compute/v2_39/__init__.py
diff --git a/tempest/lib/api_schema/response/compute/v2_39/limits.py b/tempest/lib/api_schema/response/compute/v2_39/limits.py
new file mode 100644
index 0000000..3df6616
--- /dev/null
+++ b/tempest/lib/api_schema/response/compute/v2_39/limits.py
@@ -0,0 +1,29 @@
+# Copyright 2018 ZTE Corporation.  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 copy
+
+from tempest.lib.api_schema.response.compute.v2_36 import limits as limitv236
+
+# Compute microversion 2.39:
+# remove attributes in get_limit:
+#    'maxImageMeta'
+
+get_limit = copy.deepcopy(limitv236.get_limit)
+
+get_limit['response_body']['properties']['limits']['properties']['absolute'][
+    'properties'].pop('maxImageMeta')
+
+get_limit['response_body']['properties']['limits']['properties']['absolute'][
+    'required'].remove('maxImageMeta')
diff --git a/tempest/lib/api_schema/response/compute/v2_57/limits.py b/tempest/lib/api_schema/response/compute/v2_57/limits.py
new file mode 100644
index 0000000..dcb8b3d
--- /dev/null
+++ b/tempest/lib/api_schema/response/compute/v2_57/limits.py
@@ -0,0 +1,30 @@
+# Copyright 2018 ZTE Corporation.  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 copy
+
+from tempest.lib.api_schema.response.compute.v2_39 import limits as limitv239
+
+# Compute microversion 2.57:
+# remove attributes in get_limit:
+#    'maxPersonality',
+#    'maxPersonalitySize'
+
+get_limit = copy.deepcopy(limitv239.get_limit)
+
+for item in ['maxPersonality', 'maxPersonalitySize']:
+    get_limit['response_body']['properties']['limits']['properties'][
+        'absolute']['properties'].pop(item)
+    get_limit['response_body']['properties']['limits']['properties'][
+        'absolute']['required'].remove(item)
diff --git a/tempest/lib/services/compute/limits_client.py b/tempest/lib/services/compute/limits_client.py
index efe9889..9af80c4 100644
--- a/tempest/lib/services/compute/limits_client.py
+++ b/tempest/lib/services/compute/limits_client.py
@@ -15,15 +15,25 @@
 
 from oslo_serialization import jsonutils as json
 
-from tempest.lib.api_schema.response.compute.v2_1 import limits as schema
+from tempest.lib.api_schema.response.compute.v2_1 import limits as schemav21
+from tempest.lib.api_schema.response.compute.v2_36 import limits as schemav236
+from tempest.lib.api_schema.response.compute.v2_39 import limits as schemav239
+from tempest.lib.api_schema.response.compute.v2_57 import limits as schemav257
 from tempest.lib.common import rest_client
 from tempest.lib.services.compute import base_compute_client
 
 
 class LimitsClient(base_compute_client.BaseComputeClient):
 
+    schema_versions_info = [
+        {'min': None, 'max': '2.35', 'schema': schemav21},
+        {'min': '2.36', 'max': '2.38', 'schema': schemav236},
+        {'min': '2.39', 'max': '2.56', 'schema': schemav239},
+        {'min': '2.57', 'max': None, 'schema': schemav257}]
+
     def show_limits(self):
         resp, body = self.get("limits")
         body = json.loads(body)
+        schema = self.get_schema(self.schema_versions_info)
         self.validate_response(schema.get_limit, resp, body)
         return rest_client.ResponseBody(resp, body)