Remove old v3 volume services library and use lib/service for v3

Moving volume v3 folders to /lib/services/volumes
Remove old left overs from service/volumes.

The patch removes services/volume api code
Tempest volume api will run from /lib/service

Change-Id: I76fec9c42ecb7038f01a186f3eb51bb471b1679d
diff --git a/releasenotes/notes/move-cinder-v3-to-lib-service-be3ba0c20753b594.yaml b/releasenotes/notes/move-cinder-v3-to-lib-service-be3ba0c20753b594.yaml
new file mode 100644
index 0000000..9223ba5
--- /dev/null
+++ b/releasenotes/notes/move-cinder-v3-to-lib-service-be3ba0c20753b594.yaml
@@ -0,0 +1,7 @@
+features:
+  - |
+    Define the Volume v3 service clients as library interfaces,
+    allowing other projects to use these modules as stable
+    libraries without maintenance changes.
+
+    * messages_client(v3)
diff --git a/tempest/api/volume/api_microversion_fixture.py b/tempest/api/volume/api_microversion_fixture.py
index 6817eaa..64bc537 100644
--- a/tempest/api/volume/api_microversion_fixture.py
+++ b/tempest/api/volume/api_microversion_fixture.py
@@ -13,7 +13,7 @@
 
 import fixtures
 
-from tempest.services.volume.base import base_v3_client
+from tempest.lib.services.volume.v3 import base_client
 
 
 class APIMicroversionFixture(fixtures.Fixture):
@@ -23,8 +23,8 @@
 
     def _setUp(self):
         super(APIMicroversionFixture, self)._setUp()
-        base_v3_client.VOLUME_MICROVERSION = self.volume_microversion
+        base_client.VOLUME_MICROVERSION = self.volume_microversion
         self.addCleanup(self._reset_volume_microversion)
 
     def _reset_volume_microversion(self):
-        base_v3_client.VOLUME_MICROVERSION = None
+        base_client.VOLUME_MICROVERSION = None
diff --git a/tempest/clients.py b/tempest/clients.py
index 53f3775..b3290ac 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -25,7 +25,6 @@
 from tempest.services import identity
 from tempest.services import object_storage
 from tempest.services import orchestration
-from tempest.services import volume
 
 CONF = config.CONF
 LOG = logging.getLogger(__name__)
@@ -275,8 +274,6 @@
                 raise lib_exc.InvalidConfiguration(msg)
 
     def _set_volume_clients(self):
-        # Mandatory parameters (always defined)
-        params = self.parameters['volume']
 
         self.volume_qos_client = self.volume_v1.QosSpecsClient()
         self.volume_qos_v2_client = self.volume_v2.QosSpecsClient()
@@ -291,8 +288,7 @@
         self.snapshots_v2_client = self.volume_v2.SnapshotsClient()
         self.volumes_client = self.volume_v1.VolumesClient()
         self.volumes_v2_client = self.volume_v2.VolumesClient()
-        self.volume_v3_messages_client = volume.v3.MessagesClient(
-            self.auth_provider, **params)
+        self.volume_v3_messages_client = self.volume_v3.MessagesClient()
         self.volume_types_client = self.volume_v1.TypesClient()
         self.volume_types_v2_client = self.volume_v2.TypesClient()
         self.volume_hosts_client = self.volume_v1.HostsClient()
diff --git a/tempest/lib/services/clients.py b/tempest/lib/services/clients.py
index 9e58872..0e8e3c6 100644
--- a/tempest/lib/services/clients.py
+++ b/tempest/lib/services/clients.py
@@ -45,7 +45,8 @@
         'image.v2': image.v2,
         'network': network,
         'volume.v1': volume.v1,
-        'volume.v2': volume.v2
+        'volume.v2': volume.v2,
+        'volume.v3': volume.v3
     }
 
 
@@ -54,7 +55,7 @@
     # NOTE(andreaf) This list will exists only as long the remain clients
     # are migrated to tempest.lib, and it will then be deleted without
     # deprecation or advance notice
-    return set(['identity.v3', 'object-storage', 'volume.v3'])
+    return set(['identity.v3', 'object-storage'])
 
 
 def available_modules():
diff --git a/tempest/lib/services/volume/__init__.py b/tempest/lib/services/volume/__init__.py
index 11da06c..6855d8e 100644
--- a/tempest/lib/services/volume/__init__.py
+++ b/tempest/lib/services/volume/__init__.py
@@ -14,5 +14,6 @@
 
 from tempest.lib.services.volume import v1
 from tempest.lib.services.volume import v2
+from tempest.lib.services.volume import v3
 
-__all__ = ['v1', 'v2']
+__all__ = ['v1', 'v2', 'v3']
diff --git a/tempest/services/volume/__init__.py b/tempest/lib/services/volume/v3/__init__.py
similarity index 77%
rename from tempest/services/volume/__init__.py
rename to tempest/lib/services/volume/v3/__init__.py
index c62dd53..a4600a8 100644
--- a/tempest/services/volume/__init__.py
+++ b/tempest/lib/services/volume/v3/__init__.py
@@ -12,6 +12,7 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-from tempest.services.volume import v3
+from tempest.lib.services.volume.v3.base_client import BaseClient
+from tempest.lib.services.volume.v3.messages_client import MessagesClient
 
-__all__ = ['v3']
+__all__ = ['MessagesClient', 'BaseClient']
diff --git a/tempest/services/volume/base/base_v3_client.py b/tempest/lib/services/volume/v3/base_client.py
similarity index 90%
rename from tempest/services/volume/base/base_v3_client.py
rename to tempest/lib/services/volume/v3/base_client.py
index ad6f760..958212a 100644
--- a/tempest/services/volume/base/base_v3_client.py
+++ b/tempest/lib/services/volume/v3/base_client.py
@@ -19,13 +19,13 @@
 VOLUME_MICROVERSION = None
 
 
-class BaseV3Client(rest_client.RestClient):
+class BaseClient(rest_client.RestClient):
     """Base class to handle Cinder v3 client microversion support."""
     api_version = 'v3'
     api_microversion_header_name = 'Openstack-Api-Version'
 
     def get_headers(self, accept_type=None, send_type=None):
-        headers = super(BaseV3Client, self).get_headers(
+        headers = super(BaseClient, self).get_headers(
             accept_type=accept_type, send_type=send_type)
         if VOLUME_MICROVERSION:
             headers[self.api_microversion_header_name] = ('volume %s' %
@@ -35,7 +35,7 @@
     def request(self, method, url, extra_headers=False, headers=None,
                 body=None, chunked=False):
 
-        resp, resp_body = super(BaseV3Client, self).request(
+        resp, resp_body = super(BaseClient, self).request(
             method, url, extra_headers, headers, body, chunked)
         if (VOLUME_MICROVERSION and
             VOLUME_MICROVERSION != api_version_utils.LATEST_MICROVERSION):
diff --git a/tempest/services/volume/v3/json/messages_client.py b/tempest/lib/services/volume/v3/messages_client.py
similarity index 94%
rename from tempest/services/volume/v3/json/messages_client.py
rename to tempest/lib/services/volume/v3/messages_client.py
index 6be6d59..8a01864 100644
--- a/tempest/services/volume/v3/json/messages_client.py
+++ b/tempest/lib/services/volume/v3/messages_client.py
@@ -17,10 +17,10 @@
 
 from tempest.lib.common import rest_client
 from tempest.lib import exceptions as lib_exc
-from tempest.services.volume.base import base_v3_client
+from tempest.lib.services.volume.v3 import base_client
 
 
-class MessagesClient(base_v3_client.BaseV3Client):
+class MessagesClient(base_client.BaseClient):
     """Client class to send user messages API requests."""
 
     def show_message(self, message_id):
diff --git a/tempest/services/volume/v3/__init__.py b/tempest/services/volume/v3/__init__.py
deleted file mode 100644
index d50098c..0000000
--- a/tempest/services/volume/v3/__init__.py
+++ /dev/null
@@ -1,17 +0,0 @@
-# Copyright (c) 2016 Hewlett-Packard Enterprise 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.services.volume.v3.json.messages_client import MessagesClient
-
-__all__ = ['MessagesClient']
diff --git a/tempest/services/volume/v3/json/__init__.py b/tempest/services/volume/v3/json/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/tempest/services/volume/v3/json/__init__.py
+++ /dev/null
diff --git a/tempest/services/volume/base/__init__.py b/tempest/tests/lib/services/volume/v3/__init__.py
similarity index 100%
rename from tempest/services/volume/base/__init__.py
rename to tempest/tests/lib/services/volume/v3/__init__.py
diff --git a/tempest/tests/lib/services/volume/v3/test_user_messages.py b/tempest/tests/lib/services/volume/v3/test_user_messages.py
new file mode 100644
index 0000000..4aeed5f
--- /dev/null
+++ b/tempest/tests/lib/services/volume/v3/test_user_messages.py
@@ -0,0 +1,92 @@
+# Copyright 2016 Red Hat.  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.volume.v3 import messages_client
+from tempest.tests.lib import fake_auth_provider
+from tempest.tests.lib.services import base
+
+
+class TestUserMessagesClient(base.BaseServiceTest):
+    USER_MESSAGE_INFO = {
+        "created_at": "2016-11-21T06:16:34.000000",
+        "guaranteed_until": "2016-12-21T06:16:34.000000",
+        "user_message": "No storage could be allocated for this volume "
+                        "request. You may be able to try another size or"
+                        " volume type.",
+        "resource_uuid": "c570b406-bf0b-4067-9398-f0bb09a7d9d7",
+        "request_id": "req-8f68681e-9b6b-4009-b94c-ac0811595451",
+        "message_level": "ERROR",
+        "id": "9a7dafbd-a156-4540-8996-50e71b5dcadf",
+        "resource_type": "VOLUME",
+        "links": [
+            {"href": "http://192.168.100.230:8776/v3/"
+                     "a678cb65f701462ea2257245cd640829/messages/"
+                     "9a7dafbd-a156-4540-8996-50e71b5dcadf",
+             "rel": "self"},
+            {"href": "http://192.168.100.230:8776/"
+                     "a678cb65f701462ea2257245cd640829/messages/"
+                     "9a7dafbd-a156-4540-8996-50e71b5dcadf",
+             "rel": "bookmark"}]
+        }
+    FAKE_SHOW_USER_MESSAGE = {
+        "message": dict(event_id="000002", **USER_MESSAGE_INFO)}
+
+    FAKE_LIST_USER_MESSAGES = {
+        "messages": [
+            dict(event_id="000003", **USER_MESSAGE_INFO),
+            dict(event_id="000004", **USER_MESSAGE_INFO)
+        ]
+    }
+
+    def setUp(self):
+        super(TestUserMessagesClient, self).setUp()
+        fake_auth = fake_auth_provider.FakeAuthProvider()
+        self.client = messages_client.MessagesClient(fake_auth,
+                                                     'volume',
+                                                     'regionOne')
+
+    def _test_show_user_message(self, bytes_body=False):
+        self.check_service_client_function(
+            self.client.show_message,
+            'tempest.lib.common.rest_client.RestClient.get',
+            self.FAKE_SHOW_USER_MESSAGE,
+            bytes_body,
+            message_id="9a7dafbd-a156-4540-8996-50e71b5dcadf")
+
+    def _test_list_user_message(self, bytes_body=False):
+        self.check_service_client_function(
+            self.client.list_messages,
+            'tempest.lib.common.rest_client.RestClient.get',
+            self.FAKE_LIST_USER_MESSAGES,
+            bytes_body)
+
+    def test_list_user_message_with_str_body(self):
+        self._test_list_user_message()
+
+    def test_list_user_message_with_bytes_body(self):
+        self._test_list_user_message(bytes_body=True)
+
+    def test_show_user_message_with_str_body(self):
+        self._test_show_user_message()
+
+    def test_show_user_message_with_bytes_body(self):
+        self._test_show_user_message(bytes_body=True)
+
+    def test_delete_user_message(self):
+        self.check_service_client_function(
+            self.client.delete_message,
+            'tempest.lib.common.rest_client.RestClient.delete',
+            {},
+            message_id="9a7dafbd-a156-4540-8996-50e71b5dcadf",
+            status=204)