Merge "Updated from global requirements"
diff --git a/releasenotes/notes/add-list-glance-api-versions-ec5fc8081fc8a0ae.yaml b/releasenotes/notes/add-list-glance-api-versions-ec5fc8081fc8a0ae.yaml
new file mode 100644
index 0000000..acc7a41
--- /dev/null
+++ b/releasenotes/notes/add-list-glance-api-versions-ec5fc8081fc8a0ae.yaml
@@ -0,0 +1,6 @@
+---
+features:
+  - |
+    Add versions_client module for image service.
+    This new module provides list_versions() method which shows API versions
+    from Image service.
diff --git a/tempest/api/image/base.py b/tempest/api/image/base.py
index 69294fa..c586960 100644
--- a/tempest/api/image/base.py
+++ b/tempest/api/image/base.py
@@ -145,6 +145,7 @@
         cls.namespace_objects_client = cls.os.namespace_objects_client
         cls.namespace_tags_client = cls.os.namespace_tags_client
         cls.schemas_client = cls.os.schemas_client
+        cls.versions_client = cls.os.image_versions_client
 
     def create_namespace(cls, namespace_name=None, visibility='public',
                          description='Tempest', protected=False,
diff --git a/tempest/api/image/v2/test_versions.py b/tempest/api/image/v2/test_versions.py
new file mode 100644
index 0000000..24f104c
--- /dev/null
+++ b/tempest/api/image/v2/test_versions.py
@@ -0,0 +1,30 @@
+# Copyright 2017 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.
+
+from tempest.api.image import base
+from tempest.lib import decorators
+from tempest import test
+
+
+class VersionsTest(base.BaseV2ImageTest):
+
+    @decorators.idempotent_id('659ea30a-a17c-4317-832c-0f68ed23c31d')
+    @test.attr(type='smoke')
+    def test_list_versions(self):
+        versions = self.versions_client.list_versions()['versions']
+        expected_resources = ('id', 'links', 'status')
+
+        for version in versions:
+            for res in expected_resources:
+                self.assertIn(res, version)
diff --git a/tempest/clients.py b/tempest/clients.py
index 9cb918a..e75fa79 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -125,6 +125,8 @@
                 self.image_v2.NamespacePropertiesClient()
             self.namespace_tags_client = \
                 self.image_v2.NamespaceTagsClient()
+            self.image_versions_client = \
+                self.image_v2.VersionsClient()
 
     def _set_compute_clients(self):
         self.agents_client = self.compute.AgentsClient()
diff --git a/tempest/lib/services/image/v2/__init__.py b/tempest/lib/services/image/v2/__init__.py
index 7d973e5..99a5321 100644
--- a/tempest/lib/services/image/v2/__init__.py
+++ b/tempest/lib/services/image/v2/__init__.py
@@ -25,7 +25,9 @@
 from tempest.lib.services.image.v2.resource_types_client import \
     ResourceTypesClient
 from tempest.lib.services.image.v2.schemas_client import SchemasClient
+from tempest.lib.services.image.v2.versions_client import VersionsClient
 
 __all__ = ['ImageMembersClient', 'ImagesClient', 'NamespaceObjectsClient',
            'NamespacePropertiesClient', 'NamespaceTagsClient',
-           'NamespacesClient', 'ResourceTypesClient', 'SchemasClient']
+           'NamespacesClient', 'ResourceTypesClient', 'SchemasClient',
+           'VersionsClient']
diff --git a/tempest/lib/services/image/v2/versions_client.py b/tempest/lib/services/image/v2/versions_client.py
new file mode 100644
index 0000000..1adc466
--- /dev/null
+++ b/tempest/lib/services/image/v2/versions_client.py
@@ -0,0 +1,38 @@
+# Copyright 2017 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.
+
+import time
+
+from oslo_serialization import jsonutils as json
+
+from tempest.lib.common import rest_client
+
+
+class VersionsClient(rest_client.RestClient):
+    api_version = "v2"
+
+    def list_versions(self):
+        """List API versions"""
+        version_url = self._get_base_version_url()
+
+        start = time.time()
+        resp, body = self.raw_request(version_url, 'GET')
+        end = time.time()
+        self._log_request('GET', version_url, resp, secs=(end - start),
+                          resp_body=body)
+        self._error_checker(resp, body)
+
+        self.expected_success(300, resp.status)
+        body = json.loads(body)
+        return rest_client.ResponseBody(resp, body)
diff --git a/tempest/tests/lib/services/image/v2/test_versions_client.py b/tempest/tests/lib/services/image/v2/test_versions_client.py
new file mode 100644
index 0000000..6234b06
--- /dev/null
+++ b/tempest/tests/lib/services/image/v2/test_versions_client.py
@@ -0,0 +1,94 @@
+# Copyright 2017 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.
+
+from tempest.lib.services.image.v2 import versions_client
+from tempest.tests.lib import fake_auth_provider
+from tempest.tests.lib.services import base
+
+
+class TestVersionsClient(base.BaseServiceTest):
+
+    FAKE_VERSIONS_INFO = {
+        "versions": [
+            {
+                "status": "CURRENT", "id": "v2.5",
+                "links": [
+                    {"href": "https://10.220.1.21:9292/v2/", "rel": "self"}
+                ]
+            },
+            {
+                "status": "SUPPORTED", "id": "v2.4",
+                "links": [
+                    {"href": "https://10.220.1.21:9292/v2/", "rel": "self"}
+                ]
+            },
+            {
+                "status": "SUPPORTED", "id": "v2.3",
+                "links": [
+                    {"href": "https://10.220.1.21:9292/v2/", "rel": "self"}
+                ]
+            },
+            {
+                "status": "SUPPORTED", "id": "v2.2",
+                "links": [
+                    {"href": "https://10.220.1.21:9292/v2/", "rel": "self"}
+                ]
+            },
+            {
+                "status": "SUPPORTED", "id": "v2.1",
+                "links": [
+                    {"href": "https://10.220.1.21:9292/v2/", "rel": "self"}
+                ]
+            },
+            {
+                "status": "SUPPORTED", "id": "v2.0",
+                "links": [
+                    {"href": "https://10.220.1.21:9292/v2/", "rel": "self"}
+                ]
+            },
+            {
+                "status": "DEPRECATED", "id": "v1.1",
+                "links": [
+                    {"href": "https://10.220.1.21:9292/v1/", "rel": "self"}
+                ]
+            },
+            {
+                "status": "DEPRECATED", "id": "v1.0",
+                "links": [
+                    {"href": "https://10.220.1.21:9292/v1/", "rel": "self"}
+                ]
+            }
+        ]
+    }
+
+    def setUp(self):
+        super(TestVersionsClient, self).setUp()
+        fake_auth = fake_auth_provider.FakeAuthProvider()
+        self.client = versions_client.VersionsClient(fake_auth,
+                                                     'image',
+                                                     'regionOne')
+
+    def _test_list_versions(self, bytes_body=False):
+        self.check_service_client_function(
+            self.client.list_versions,
+            'tempest.lib.common.rest_client.RestClient.raw_request',
+            self.FAKE_VERSIONS_INFO,
+            bytes_body,
+            300)
+
+    def test_list_versions_with_str_body(self):
+        self._test_list_versions()
+
+    def test_list_versions_with_bytes_body(self):
+        self._test_list_versions(bytes_body=True)