Merge "Use tempest-lib's agents_client"
diff --git a/tempest/api/volume/admin/test_volume_quotas_negative.py b/tempest/api/volume/admin/test_volume_quotas_negative.py
index d1a6db0..ec61cf3 100644
--- a/tempest/api/volume/admin/test_volume_quotas_negative.py
+++ b/tempest/api/volume/admin/test_volume_quotas_negative.py
@@ -16,8 +16,11 @@
 from tempest_lib import exceptions as lib_exc
 
 from tempest.api.volume import base
+from tempest import config
 from tempest import test
 
+CONF = config.CONF
+
 
 class BaseVolumeQuotasNegativeV2TestJSON(base.BaseVolumeAdminTest):
     force_tenant_isolation = True
@@ -31,8 +34,8 @@
     def resource_setup(cls):
         super(BaseVolumeQuotasNegativeV2TestJSON, cls).resource_setup()
         cls.default_volume_size = cls.volumes_client.default_volume_size
-        cls.shared_quota_set = {'gigabytes': 3 * cls.default_volume_size,
-                                'volumes': 1, 'snapshots': 1}
+        cls.shared_quota_set = {'gigabytes': 2 * cls.default_volume_size,
+                                'volumes': 1}
 
         # NOTE(gfidente): no need to restore original quota set
         # after the tests as they only work with tenant isolation.
@@ -43,7 +46,6 @@
         # NOTE(gfidente): no need to delete in tearDown as
         # they are created using utility wrapper methods.
         cls.volume = cls.create_volume()
-        cls.snapshot = cls.create_snapshot(cls.volume['id'])
 
     @test.attr(type='negative')
     @test.idempotent_id('bf544854-d62a-47f2-a681-90f7a47d86b6')
@@ -52,13 +54,6 @@
                           self.volumes_client.create_volume)
 
     @test.attr(type='negative')
-    @test.idempotent_id('02bbf63f-6c05-4357-9d98-2926a94064ff')
-    def test_quota_volume_snapshots(self):
-        self.assertRaises(lib_exc.OverLimit,
-                          self.snapshots_client.create_snapshot,
-                          self.volume['id'])
-
-    @test.attr(type='negative')
     @test.idempotent_id('2dc27eee-8659-4298-b900-169d71a91374')
     def test_quota_volume_gigabytes(self):
         # NOTE(gfidente): quota set needs to be changed for this test
@@ -67,8 +62,7 @@
         self.addCleanup(self.quotas_client.update_quota_set,
                         self.demo_tenant_id,
                         **self.shared_quota_set)
-
-        new_quota_set = {'gigabytes': 2 * self.default_volume_size,
+        new_quota_set = {'gigabytes': self.default_volume_size,
                          'volumes': 2, 'snapshots': 1}
         self.quotas_client.update_quota_set(
             self.demo_tenant_id,
@@ -76,15 +70,6 @@
         self.assertRaises(lib_exc.OverLimit,
                           self.volumes_client.create_volume)
 
-        new_quota_set = {'gigabytes': 2 * self.default_volume_size,
-                         'volumes': 1, 'snapshots': 2}
-        self.quotas_client.update_quota_set(
-            self.demo_tenant_id,
-            **self.shared_quota_set)
-        self.assertRaises(lib_exc.OverLimit,
-                          self.snapshots_client.create_snapshot,
-                          self.volume['id'])
-
 
 class VolumeQuotasNegativeV1TestJSON(BaseVolumeQuotasNegativeV2TestJSON):
     _api_version = 1
diff --git a/tempest/api/volume/admin/test_volume_snapshot_quotas_negative.py b/tempest/api/volume/admin/test_volume_snapshot_quotas_negative.py
new file mode 100644
index 0000000..ce0b618
--- /dev/null
+++ b/tempest/api/volume/admin/test_volume_snapshot_quotas_negative.py
@@ -0,0 +1,81 @@
+# 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_lib import exceptions as lib_exc
+
+from tempest.api.volume import base
+from tempest import config
+from tempest import test
+
+CONF = config.CONF
+
+
+class VolumeSnapshotQuotasNegativeV2TestJSON(base.BaseVolumeAdminTest):
+    force_tenant_isolation = True
+
+    @classmethod
+    def skip_checks(cls):
+        super(VolumeSnapshotQuotasNegativeV2TestJSON, cls).skip_checks()
+        if not CONF.volume_feature_enabled.snapshot:
+            raise cls.skipException('Cinder volume snapshots are disabled')
+
+    @classmethod
+    def setup_credentials(cls):
+        super(VolumeSnapshotQuotasNegativeV2TestJSON, cls).setup_credentials()
+        cls.demo_tenant_id = cls.os.credentials.tenant_id
+
+    @classmethod
+    def resource_setup(cls):
+        super(VolumeSnapshotQuotasNegativeV2TestJSON, cls).resource_setup()
+        cls.default_volume_size = cls.volumes_client.default_volume_size
+        cls.shared_quota_set = {'gigabytes': 3 * cls.default_volume_size,
+                                'volumes': 1, 'snapshots': 1}
+
+        # NOTE(gfidente): no need to restore original quota set
+        # after the tests as they only work with tenant isolation.
+        cls.quotas_client.update_quota_set(
+            cls.demo_tenant_id,
+            **cls.shared_quota_set)
+
+        # NOTE(gfidente): no need to delete in tearDown as
+        # they are created using utility wrapper methods.
+        cls.volume = cls.create_volume()
+        cls.snapshot = cls.create_snapshot(cls.volume['id'])
+
+    @test.attr(type='negative')
+    @test.idempotent_id('02bbf63f-6c05-4357-9d98-2926a94064ff')
+    def test_quota_volume_snapshots(self):
+        self.assertRaises(lib_exc.OverLimit,
+                          self.snapshots_client.create_snapshot,
+                          self.volume['id'])
+
+    @test.attr(type='negative')
+    @test.idempotent_id('c99a1ca9-6cdf-498d-9fdf-25832babef27')
+    def test_quota_volume_gigabytes_snapshots(self):
+        self.addCleanup(self.quotas_client.update_quota_set,
+                        self.demo_tenant_id,
+                        **self.shared_quota_set)
+        new_quota_set = {'gigabytes': 2 * self.default_volume_size,
+                         'volumes': 1, 'snapshots': 2}
+        self.quotas_client.update_quota_set(
+            self.demo_tenant_id,
+            **new_quota_set)
+        self.assertRaises(lib_exc.OverLimit,
+                          self.snapshots_client.create_snapshot,
+                          self.volume['id'])
+
+
+class VolumeSnapshotNegativeV1TestJSON(VolumeSnapshotQuotasNegativeV2TestJSON):
+    _api_version = 1
diff --git a/tempest/clients.py b/tempest/clients.py
index 563876c..cffdc3f 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -80,8 +80,8 @@
 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.compute.json.volumes_client import \
+    VolumesClient as ComputeVolumesClient
 from tempest.services.data_processing.v1_1.data_processing_client import \
     DataProcessingClient
 from tempest.services.database.json.flavors_client import \
@@ -333,7 +333,7 @@
             'build_interval': CONF.volume.build_interval,
             'build_timeout': CONF.volume.build_timeout
         })
-        self.volumes_extensions_client = VolumesExtensionsClient(
+        self.volumes_extensions_client = ComputeVolumesClient(
             self.auth_provider, **params_volume)
         self.compute_versions_client = VersionsClient(self.auth_provider,
                                                       **params_volume)
diff --git a/tempest/services/compute/json/volumes_extensions_client.py b/tempest/services/compute/json/volumes_client.py
similarity index 97%
rename from tempest/services/compute/json/volumes_extensions_client.py
rename to tempest/services/compute/json/volumes_client.py
index db92351..e799c29 100644
--- a/tempest/services/compute/json/volumes_extensions_client.py
+++ b/tempest/services/compute/json/volumes_client.py
@@ -21,7 +21,7 @@
 from tempest.common import service_client
 
 
-class VolumesExtensionsClient(service_client.ServiceClient):
+class VolumesClient(service_client.ServiceClient):
 
     def list_volumes(self, detail=False, **params):
         """List all the volumes created."""
diff --git a/tempest/tests/common/test_service_clients.py b/tempest/tests/common/test_service_clients.py
index 3f72340..e4228a7 100644
--- a/tempest/tests/common/test_service_clients.py
+++ b/tempest/tests/common/test_service_clients.py
@@ -45,8 +45,8 @@
 from tempest.services.compute.json import servers_client
 from tempest.services.compute.json import services_client
 from tempest.services.compute.json import tenant_usages_client
-from tempest.services.compute.json import volumes_extensions_client \
-    as compute_volumes_extensions_client
+from tempest.services.compute.json import volumes_client \
+    as compute_volumes_client
 from tempest.services.data_processing.v1_1 import data_processing_client
 from tempest.services.database.json import flavors_client as db_flavor_client
 from tempest.services.database.json import versions_client as db_version_client
@@ -135,7 +135,7 @@
             servers_client.ServersClient,
             services_client.ServicesClient,
             tenant_usages_client.TenantUsagesClient,
-            compute_volumes_extensions_client.VolumesExtensionsClient,
+            compute_volumes_client.VolumesClient,
             data_processing_client.DataProcessingClient,
             db_flavor_client.DatabaseFlavorsClient,
             db_version_client.DatabaseVersionsClient,
diff --git a/tempest/tests/services/compute/test_volumes_extensions_client.py b/tempest/tests/services/compute/test_volumes_client.py
similarity index 87%
rename from tempest/tests/services/compute/test_volumes_extensions_client.py
rename to tempest/tests/services/compute/test_volumes_client.py
index 2fe8497..33d4bad 100644
--- a/tempest/tests/services/compute/test_volumes_extensions_client.py
+++ b/tempest/tests/services/compute/test_volumes_client.py
@@ -17,12 +17,12 @@
 from oslotest import mockpatch
 from tempest_lib import exceptions as lib_exc
 
-from tempest.services.compute.json import volumes_extensions_client
+from tempest.services.compute.json import volumes_client
 from tempest.tests import fake_auth_provider
 from tempest.tests.services.compute import base
 
 
-class TestVolumesExtensionsClient(base.BaseComputeServiceTest):
+class TestVolumesClient(base.BaseComputeServiceTest):
 
     FAKE_VOLUME = {
         "id": "521752a6-acf6-4b2d-bc7a-119f9148cd8c",
@@ -43,9 +43,9 @@
     FAKE_VOLUMES = {"volumes": [FAKE_VOLUME]}
 
     def setUp(self):
-        super(TestVolumesExtensionsClient, self).setUp()
+        super(TestVolumesClient, self).setUp()
         fake_auth = fake_auth_provider.FakeAuthProvider()
-        self.client = volumes_extensions_client.VolumesExtensionsClient(
+        self.client = volumes_client.VolumesClient(
             fake_auth, 'compute', 'regionOne')
 
     def _test_list_volumes(self, bytes_body=False, **params):
@@ -100,15 +100,15 @@
             {}, status=202, volume_id=self.FAKE_VOLUME['id'])
 
     def test_is_resource_deleted_true(self):
-        module = ('tempest.services.compute.json.volumes_extensions_client.'
-                  'VolumesExtensionsClient.show_volume')
+        module = ('tempest.services.compute.json.volumes_client.'
+                  'VolumesClient.show_volume')
         self.useFixture(mockpatch.Patch(
             module, side_effect=lib_exc.NotFound))
         self.assertTrue(self.client.is_resource_deleted('fake-id'))
 
     def test_is_resource_deleted_false(self):
-        module = ('tempest.services.compute.json.volumes_extensions_client.'
-                  'VolumesExtensionsClient.show_volume')
+        module = ('tempest.services.compute.json.volumes_client.'
+                  'VolumesClient.show_volume')
         self.useFixture(mockpatch.Patch(
             module, return_value={}))
         self.assertFalse(self.client.is_resource_deleted('fake-id'))