Verify "create a server" API response attributes

Now most attributes of Nova v2/v3 APIs are not checked in Tempest,
and this patch adds some tests which check these attributes to block
the backward incompatibility change in the future.

This patch adds the checks of "create a server" API responses.

The response body of v2 API is the following:
  {
    "server": {
      "id": "d099f759-021f-41ad-8ad3-7d9ddecaf07a",
      "security_groups": [{"name": "default"}],
      "links": [
        {"href": "http://[..]", "rel": "self"},
        {"href": "http://[..]", "rel": "bookmark"}
      ],
      "adminPass": "6GLunfZpNbB8",
      "OS-DCF:diskConfig": "MANUAL"
    }
  }

The one of v3 API is the following:
  {
    "server": {
      "id": "c2f2ebe8-5a25-442b-83d2-9f0926a7a88a",
      "os-security-groups:security_groups": [{"name": "default"}],
      "links": [
        {"href": "http://[..]", "rel": "self"},
        {"href": "http://[..]", "rel": "bookmark"}
      ],
      "admin_password": "7XW3fhZpe6iF",
      "os-access-ips:access_ip_v6": "",
      "os-access-ips:access_ip_v4": "",
    }
  }

Partially implements blueprint nova-api-attribute-test

Change-Id: I584c47df3de8be2dd593b39b5486c9ed38c9a7ed
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,