Merge "Verify "create a server" API response attributes"
diff --git a/tempest/api_schema/compute/v2/servers.py b/tempest/api_schema/compute/v2/servers.py
new file mode 100644
index 0000000..7f06ca6
--- /dev/null
+++ b/tempest/api_schema/compute/v2/servers.py
@@ -0,0 +1,53 @@
+# Copyright 2014 NEC 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.
+
+create_server = {
+    'status_code': [202],
+    'response_body': {
+        'type': 'object',
+        'properties': {
+            'server': {
+                'type': 'object',
+                'properties': {
+                    # NOTE: Now the type of 'id' is uuid, but here allows
+                    # 'integer' also because old OpenStack uses 'integer'
+                    # as a server id.
+                    'id': {'type': ['integer', 'string']},
+                    'security_groups': {'type': 'array'},
+                    'links': {
+                        'type': 'array',
+                        'items': {
+                            'type': 'object',
+                            'properties': {
+                                'href': {
+                                    'type': 'string',
+                                    'format': 'uri'
+                                },
+                                'rel': {'type': 'string'}
+                            },
+                            'required': ['href', 'rel']
+                        }
+                    },
+                    'adminPass': {'type': 'string'},
+                    'OS-DCF:diskConfig': {'type': 'string'}
+                },
+                # NOTE: OS-DCF:diskConfig is API extension, and some
+                # environments return a response without the attribute.
+                # So it is not 'required'.
+                'required': ['id', 'security_groups', 'links', 'adminPass']
+            }
+        },
+        'required': ['server']
+    }
+}
diff --git a/tempest/api_schema/compute/v3/__init__.py b/tempest/api_schema/compute/v3/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tempest/api_schema/compute/v3/__init__.py
diff --git a/tempest/api_schema/compute/v3/servers.py b/tempest/api_schema/compute/v3/servers.py
new file mode 100644
index 0000000..e69b25f
--- /dev/null
+++ b/tempest/api_schema/compute/v3/servers.py
@@ -0,0 +1,55 @@
+# Copyright 2014 NEC 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.
+
+create_server = {
+    'status_code': [202],
+    'response_body': {
+        'type': 'object',
+        'properties': {
+            'server': {
+                'type': 'object',
+                'properties': {
+                    # NOTE: Now the type of 'id' is uuid, but here allows
+                    # 'integer' also because old OpenStack uses 'integer'
+                    # as a server id.
+                    'id': {'type': ['integer', 'string']},
+                    'os-security-groups:security_groups': {'type': 'array'},
+                    'links': {
+                        'type': 'array',
+                        'items': {
+                            'type': 'object',
+                            'properties': {
+                                'href': {
+                                    'type': 'string',
+                                    'format': 'uri'
+                                },
+                                'rel': {'type': 'string'}
+                            },
+                            'required': ['href', 'rel']
+                        }
+                    },
+                    'admin_password': {'type': 'string'},
+                    'os-access-ips:access_ip_v4': {'type': 'string'},
+                    'os-access-ips:access_ip_v6': {'type': 'string'}
+                },
+                # NOTE: os-access-ips:access_ip_v4/v6 are API extension,
+                # and some environments return a response without these
+                # attributes. So they are not 'required'.
+                'required': ['id', 'os-security-groups:security_groups',
+                             'links', 'admin_password']
+            }
+        },
+        'required': ['server']
+    }
+}
diff --git a/tempest/services/compute/json/servers_client.py b/tempest/services/compute/json/servers_client.py
index ca0f114..4eba2b4 100644
--- a/tempest/services/compute/json/servers_client.py
+++ b/tempest/services/compute/json/servers_client.py
@@ -18,6 +18,7 @@
 import time
 import urllib
 
+from tempest.api_schema.compute.v2 import servers as schema
 from tempest.common import rest_client
 from tempest.common import waiters
 from tempest import config
@@ -85,6 +86,7 @@
         # with return reservation id set True
         if 'reservation_id' in body:
             return resp, body
+        self.validate_response(schema.create_server, resp, body)
         return resp, body['server']
 
     def update_server(self, server_id, name=None, meta=None, accessIPv4=None,
diff --git a/tempest/services/compute/v3/json/servers_client.py b/tempest/services/compute/v3/json/servers_client.py
index 92eb09b..6f492d0 100644
--- a/tempest/services/compute/v3/json/servers_client.py
+++ b/tempest/services/compute/v3/json/servers_client.py
@@ -19,6 +19,7 @@
 import time
 import urllib
 
+from tempest.api_schema.compute.v3 import servers as schema
 from tempest.common import rest_client
 from tempest.common import waiters
 from tempest import config
@@ -91,6 +92,7 @@
         # with return reservation id set True
         if 'servers_reservation' in body:
             return resp, body['servers_reservation']
+        self.validate_response(schema.create_server, resp, body)
         return resp, body['server']
 
     def update_server(self, server_id, name=None, meta=None, access_ip_v4=None,