Added Trove (database) version API tests

Added a new file "test_versions.py" to verify the current
version of the Database API.  Required supporting
functions are added in a new client file "versions_client.py"
under the JSON interface.
Modified api/base.py, etc/tempest.conf.sample, clients.py and
config.py files

Partially implements blueprint: trove-tempest

Change-Id: I3dbe4e40b8b2a1ec3c69573dd40c3c8a643d73d6
diff --git a/etc/tempest.conf.sample b/etc/tempest.conf.sample
index 4a567e7..a1abe7f 100644
--- a/etc/tempest.conf.sample
+++ b/etc/tempest.conf.sample
@@ -442,6 +442,10 @@
 # value)
 #db_flavor_ref=1
 
+# Current database version to use in database tests. (string
+# value)
+#db_current_version=v1.0
+
 
 [debug]
 
diff --git a/tempest/api/database/base.py b/tempest/api/database/base.py
index 8add9ba..cf70d11 100644
--- a/tempest/api/database/base.py
+++ b/tempest/api/database/base.py
@@ -36,7 +36,9 @@
 
         cls.catalog_type = CONF.database.catalog_type
         cls.db_flavor_ref = CONF.database.db_flavor_ref
+        cls.db_current_version = CONF.database.db_current_version
 
         os = cls.get_client_manager()
         cls.os = os
         cls.database_flavors_client = cls.os.database_flavors_client
+        cls.database_versions_client = cls.os.database_versions_client
diff --git a/tempest/api/database/versions/__init__.py b/tempest/api/database/versions/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tempest/api/database/versions/__init__.py
diff --git a/tempest/api/database/versions/test_versions.py b/tempest/api/database/versions/test_versions.py
new file mode 100644
index 0000000..6101f47
--- /dev/null
+++ b/tempest/api/database/versions/test_versions.py
@@ -0,0 +1,40 @@
+# Copyright 2014 OpenStack Foundation
+# 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.database import base
+from tempest import test
+
+
+class DatabaseVersionsTest(base.BaseDatabaseTest):
+    _interface = 'json'
+
+    @classmethod
+    def setUpClass(cls):
+        super(DatabaseVersionsTest, cls).setUpClass()
+        cls.client = cls.database_versions_client
+
+    @test.attr(type='smoke')
+    def test_list_db_versions(self):
+        resp, versions = self.client.list_db_versions()
+        self.assertEqual(200, resp.status)
+        self.assertTrue(len(versions) > 0, "No database versions found")
+        # List of all versions should contain the current version, and there
+        # should only be one 'current' version
+        current_versions = list()
+        for version in versions:
+            if 'CURRENT' == version['status']:
+                current_versions.append(version['id'])
+        self.assertEqual(1, len(current_versions))
+        self.assertIn(self.db_current_version, current_versions)
diff --git a/tempest/clients.py b/tempest/clients.py
index 646a2d9..3ec442f 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -116,6 +116,8 @@
 from tempest.services.data_processing.v1_1.client import DataProcessingClient
 from tempest.services.database.json.flavors_client import \
     DatabaseFlavorsClientJSON
+from tempest.services.database.json.versions_client import \
+    DatabaseVersionsClientJSON
 from tempest.services.identity.json.identity_client import IdentityClientJSON
 from tempest.services.identity.json.identity_client import TokenClientJSON
 from tempest.services.identity.v3.json.credentials_client import \
@@ -354,6 +356,8 @@
             self.hosts_v3_client = HostsV3ClientJSON(self.auth_provider)
             self.database_flavors_client = DatabaseFlavorsClientJSON(
                 self.auth_provider)
+            self.database_versions_client = DatabaseVersionsClientJSON(
+                self.auth_provider)
             self.queuing_client = QueuingClientJSON(self.auth_provider)
             if CONF.service_available.ceilometer:
                 self.telemetry_client = TelemetryClientJSON(
diff --git a/tempest/config.py b/tempest/config.py
index 7084768..f721ab8 100644
--- a/tempest/config.py
+++ b/tempest/config.py
@@ -542,6 +542,9 @@
     cfg.StrOpt('db_flavor_ref',
                default="1",
                help="Valid primary flavor to use in database tests."),
+    cfg.StrOpt('db_current_version',
+               default="v1.0",
+               help="Current database version to use in database tests."),
 ]
 
 orchestration_group = cfg.OptGroup(name='orchestration',
diff --git a/tempest/services/database/json/versions_client.py b/tempest/services/database/json/versions_client.py
new file mode 100644
index 0000000..0269c43
--- /dev/null
+++ b/tempest/services/database/json/versions_client.py
@@ -0,0 +1,38 @@
+# Copyright 2014 OpenStack Foundation
+# 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 urllib
+
+from tempest.common import rest_client
+from tempest import config
+
+CONF = config.CONF
+
+
+class DatabaseVersionsClientJSON(rest_client.RestClient):
+
+    def __init__(self, auth_provider):
+        super(DatabaseVersionsClientJSON, self).__init__(auth_provider)
+        self.skip_path()
+        self.service = CONF.database.catalog_type
+
+    def list_db_versions(self, params=None):
+        """List all versions."""
+        url = ''
+        if params:
+            url += '?%s' % urllib.urlencode(params)
+
+        resp, body = self.get(url)
+        return resp, self._parse_resp(body)