Add test for Nova list-versions API

This commit adds a test that does a GET on the raw endpoint to
ensure that the nova version GET does the right thing.

Co-Authored-By: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>

Related-Bug: #1491579
Change-Id: I5ee09891cd1b62a87d25284be961c2027cdbd82a
diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py
index a25a2af..2624fca 100644
--- a/tempest/api/compute/base.py
+++ b/tempest/api/compute/base.py
@@ -89,6 +89,7 @@
         cls.migrations_client = cls.os.migrations_client
         cls.security_group_default_rules_client = (
             cls.os.security_group_default_rules_client)
+        cls.versions_client = cls.os.compute_versions_client
 
     @classmethod
     def resource_setup(cls):
diff --git a/tempest/api/compute/test_versions.py b/tempest/api/compute/test_versions.py
new file mode 100644
index 0000000..369cf31
--- /dev/null
+++ b/tempest/api/compute/test_versions.py
@@ -0,0 +1,24 @@
+# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
+#
+# 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.
+
+from tempest.api.compute import base
+from tempest import test
+
+
+class TestVersions(base.BaseComputeTest):
+
+    @test.idempotent_id('6c0a0990-43b6-4529-9b61-5fd8daf7c55c')
+    def test_list_api_versions(self):
+        result = self.versions_client.list_versions()
+        self.assertIsNotNone(result)
diff --git a/tempest/api_schema/response/compute/v2_1/versions.py b/tempest/api_schema/response/compute/v2_1/versions.py
new file mode 100644
index 0000000..a01dd41
--- /dev/null
+++ b/tempest/api_schema/response/compute/v2_1/versions.py
@@ -0,0 +1,54 @@
+# Copyright 2015 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.
+
+list_versions = {
+    'status_code': [200],
+    'response_body': {
+        'type': 'object',
+        'properties': {
+            'versions': {
+                'type': 'array',
+                'items': {
+                    'type': 'object',
+                    'properties': {
+                        'id': {'type': 'string'},
+                        'links': {
+                            'type': 'array',
+                            'items': {
+                                'type': 'object',
+                                'properties': {
+                                    'href': {'type': 'string',
+                                             'format': 'uri'},
+                                    'rel': {'type': 'string'},
+                                },
+                                'required': ['href', 'rel'],
+                                'additionalProperties': False
+                            }
+                        },
+                        'status': {'type': 'string'},
+                        'updated': {'type': 'string', 'format': 'date-time'},
+                        'version': {'type': 'string'},
+                        'min_version': {'type': 'string'}
+                    },
+                    # NOTE: version and min_version have been added since Kilo,
+                    # so they should not be required.
+                    'required': ['id', 'links', 'status', 'updated'],
+                    'additionalProperties': False
+                }
+            }
+        },
+        'required': ['versions'],
+        'additionalProperties': False
+    }
+}
diff --git a/tempest/clients.py b/tempest/clients.py
index b9f7991..c0d4585 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -77,6 +77,7 @@
     TenantNetworksClient
 from tempest.services.compute.json.tenant_usages_client import \
     TenantUsagesClient
+from tempest.services.compute.json.versions_client import VersionsClient
 from tempest.services.compute.json.volumes_extensions_client import \
     VolumesExtensionsClient
 from tempest.services.data_processing.v1_1.data_processing_client import \
@@ -322,6 +323,8 @@
         })
         self.volumes_extensions_client = VolumesExtensionsClient(
             self.auth_provider, **params_volume)
+        self.compute_versions_client = VersionsClient(self.auth_provider,
+                                                      **params_volume)
 
     def _set_database_clients(self):
         self.database_flavors_client = DatabaseFlavorsClient(
diff --git a/tempest/services/compute/json/versions_client.py b/tempest/services/compute/json/versions_client.py
new file mode 100644
index 0000000..cbad02c
--- /dev/null
+++ b/tempest/services/compute/json/versions_client.py
@@ -0,0 +1,37 @@
+# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
+#
+# 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.
+
+from oslo_serialization import jsonutils as json
+from six.moves import urllib
+
+from tempest.api_schema.response.compute.v2_1 import versions as schema
+from tempest.common import service_client
+
+
+class VersionsClient(service_client.ServiceClient):
+
+    def list_versions(self):
+        # NOTE: The URL which is gotten from keystone's catalog contains
+        # API version and project-id like "v2/{project-id}", but we need
+        # to access the URL which doesn't contain them for getting API
+        # versions. For that, here should use raw_request() instead of
+        # get().
+        endpoint = self.base_url
+        url = urllib.parse.urlparse(endpoint)
+        version_url = '%s://%s/' % (url.scheme, url.netloc)
+
+        resp, body = self.raw_request(version_url, 'GET')
+        body = json.loads(body)
+        self.validate_response(schema.list_versions, resp, body)
+        return service_client.ResponseBody(resp, body)