Simplify volume test classes inheritance
* Enough to specify the interface in the leaf test classes
* Non-admin user are allowed to attempt admin operations in negative tests
Change-Id: Ibbb0ac1de20601272028e364348b9ae89bd0f808
diff --git a/tempest/clients.py b/tempest/clients.py
index 150cf67..8d9c216 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -57,6 +57,10 @@
from tempest.services.object_storage.account_client import AccountClient
from tempest.services.object_storage.container_client import ContainerClient
from tempest.services.object_storage.object_client import ObjectClient
+from tempest.services.volume.json.admin.volume_types_client import \
+ VolumeTypesClientJSON
+from tempest.services.volume.xml.admin.volume_types_client import \
+ VolumeTypesClientXML
from tempest.services.volume.json.snapshots_client import SnapshotsClientJSON
from tempest.services.volume.json.volumes_client import VolumesClientJSON
from tempest.services.volume.xml.snapshots_client import SnapshotsClientXML
@@ -123,6 +127,11 @@
"xml": VolumesClientXML,
}
+VOLUME_TYPES_CLIENTS = {
+ "json": VolumeTypesClientJSON,
+ "xml": VolumeTypesClientXML,
+}
+
IDENTITY_CLIENT = {
"json": IdentityClientJSON,
"xml": IdentityClientXML,
@@ -193,6 +202,8 @@
self.floating_ips_client = FLOAT_CLIENTS[interface](*client_args)
self.snapshots_client = SNAPSHOTS_CLIENTS[interface](*client_args)
self.volumes_client = VOLUMES_CLIENTS[interface](*client_args)
+ self.volume_types_client = \
+ VOLUME_TYPES_CLIENTS[interface](*client_args)
self.identity_client = IDENTITY_CLIENT[interface](*client_args)
self.token_client = TOKEN_CLIENT[interface](self.config)
self.security_groups_client = \
diff --git a/tempest/tests/volume/admin/base.py b/tempest/tests/volume/admin/base.py
deleted file mode 100644
index 21425be..0000000
--- a/tempest/tests/volume/admin/base.py
+++ /dev/null
@@ -1,65 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2012 OpenStack, LLC
-# 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 import config
-import tempest.services.volume.json.admin.volume_types_client \
- as volume_types_json_client
-import tempest.services.volume.xml.admin.volume_types_client \
- as volume_types_xml_client
-from tempest.tests.volume.base import BaseVolumeTest
-
-
-class BaseVolumeAdminTest(BaseVolumeTest):
- """Base test case class for all Volume Admin API tests."""
- @classmethod
- def setUpClass(cls):
- super(BaseVolumeAdminTest, cls).setUpClass()
- cls.config = config.TempestConfig()
- cls.adm_user = cls.config.identity.admin_username
- cls.adm_pass = cls.config.identity.admin_password
- cls.adm_tenant = cls.config.identity.admin_tenant_name
- cls.auth_url = cls.config.identity.uri
-
- if not cls.adm_user and cls.adm_pass and cls.adm_tenant:
- msg = ("Missing Volume Admin API credentials "
- "in configuration.")
- raise cls.skipException(msg)
-
- @classmethod
- def tearDownClass(cls):
- super(BaseVolumeAdminTest, cls).tearDownClass()
-
-
-class BaseVolumeAdminTestJSON(BaseVolumeAdminTest):
- @classmethod
- def setUpClass(cls):
- cls._interface = "json"
- super(BaseVolumeAdminTestJSON, cls).setUpClass()
- cls.client = volume_types_json_client.\
- VolumeTypesClientJSON(cls.config, cls.adm_user, cls.adm_pass,
- cls.auth_url, cls.adm_tenant)
-
-
-class BaseVolumeAdminTestXML(BaseVolumeAdminTest):
- @classmethod
- def setUpClass(cls):
- cls._interface = "xml"
- super(BaseVolumeAdminTestXML, cls).setUpClass()
- cls.client = volume_types_xml_client.\
- VolumeTypesClientXML(cls.config, cls.adm_user, cls.adm_pass,
- cls.auth_url, cls.adm_tenant)
diff --git a/tempest/tests/volume/admin/test_volume_types_extra_specs.py b/tempest/tests/volume/admin/test_volume_types_extra_specs.py
index c743567..98756db 100644
--- a/tempest/tests/volume/admin/test_volume_types_extra_specs.py
+++ b/tempest/tests/volume/admin/test_volume_types_extra_specs.py
@@ -16,28 +16,15 @@
# under the License.
from tempest.common.utils.data_utils import rand_name
-from tempest.services.volume.json.admin import volume_types_client
-from tempest.tests.volume.base import BaseVolumeTest
+from tempest.tests.volume import base
-class VolumeTypesExtraSpecsTest(BaseVolumeTest):
+class VolumeTypesExtraSpecsTest(base.BaseVolumeAdminTest):
_interface = "json"
@classmethod
def setUpClass(cls):
super(VolumeTypesExtraSpecsTest, cls).setUpClass()
-
- adm_user = cls.config.identity.admin_username
- adm_pass = cls.config.identity.admin_password
- adm_tenant = cls.config.identity.admin_tenant_name
- auth_url = cls.config.identity.uri
-
- cls.client = volume_types_client.VolumeTypesClientJSON(cls.config,
- adm_user,
- adm_pass,
- auth_url,
- adm_tenant)
-
vol_type_name = rand_name('Volume-type-')
cls.extra_spec = {"spec1": "val1"}
resp, cls.volume_type = cls.client.create_volume_type(vol_type_name)
diff --git a/tempest/tests/volume/admin/test_volume_types_extra_specs_negative.py b/tempest/tests/volume/admin/test_volume_types_extra_specs_negative.py
index 9aa8409..e201853 100644
--- a/tempest/tests/volume/admin/test_volume_types_extra_specs_negative.py
+++ b/tempest/tests/volume/admin/test_volume_types_extra_specs_negative.py
@@ -20,23 +20,24 @@
from tempest.common.utils.data_utils import rand_name
from tempest import exceptions
-from tempest.tests.volume.admin.base import BaseVolumeAdminTestJSON
-from tempest.tests.volume.admin.base import BaseVolumeAdminTestXML
+from tempest.tests.volume import base
-class ExtraSpecsNegativeTestBase():
+class ExtraSpecsNegativeTest(base.BaseVolumeAdminTest):
+ _interface = 'json'
- @staticmethod
+ @classmethod
def setUpClass(cls):
- cls.client = cls.client
+ super(ExtraSpecsNegativeTest, cls).setUpClass()
vol_type_name = rand_name('Volume-type-')
cls.extra_specs = {"spec1": "val1"}
resp, cls.volume_type = cls.client.create_volume_type(vol_type_name,
extra_specs=
cls.extra_specs)
- @staticmethod
+ @classmethod
def tearDownClass(cls):
+ super(ExtraSpecsNegativeTest, cls).tearDownClass()
cls.client.delete_volume_type(cls.volume_type['id'])
@testtools.skip('Until bug 1090320 is fixed')
@@ -122,29 +123,5 @@
self.volume_type['id'], str(uuid.uuid4()))
-class ExtraSpecsNegativeTestXML(BaseVolumeAdminTestXML,
- ExtraSpecsNegativeTestBase):
-
- @classmethod
- def setUpClass(cls):
- super(ExtraSpecsNegativeTestXML, cls).setUpClass()
- ExtraSpecsNegativeTestBase.setUpClass(cls)
-
- @classmethod
- def tearDownClass(cls):
- super(ExtraSpecsNegativeTestXML, cls).tearDownClass()
- ExtraSpecsNegativeTestBase.tearDownClass(cls)
-
-
-class ExtraSpecsNegativeTestJSON(BaseVolumeAdminTestJSON,
- ExtraSpecsNegativeTestBase):
-
- @classmethod
- def setUpClass(cls):
- super(ExtraSpecsNegativeTestJSON, cls).setUpClass()
- ExtraSpecsNegativeTestBase.setUpClass(cls)
-
- @classmethod
- def tearDownClass(cls):
- super(ExtraSpecsNegativeTestJSON, cls).tearDownClass()
- ExtraSpecsNegativeTestBase.tearDownClass(cls)
+class ExtraSpecsNegativeTestXML(ExtraSpecsNegativeTest):
+ _interface = 'xml'
diff --git a/tempest/tests/volume/admin/test_volume_types_negative.py b/tempest/tests/volume/admin/test_volume_types_negative.py
index 8e7fa23..c706f3d 100644
--- a/tempest/tests/volume/admin/test_volume_types_negative.py
+++ b/tempest/tests/volume/admin/test_volume_types_negative.py
@@ -19,15 +19,11 @@
import uuid
from tempest import exceptions
-from tempest.tests.volume.admin.base import BaseVolumeAdminTestJSON
-from tempest.tests.volume.admin.base import BaseVolumeAdminTestXML
+from tempest.tests.volume import base
-class VolumeTypesNegativeTestBase():
-
- @staticmethod
- def setUpClass(cls):
- cls.client = cls.client
+class VolumeTypesNegativeTest(base.BaseVolumeAdminTest):
+ _interface = 'json'
def test_create_with_nonexistent_volume_type(self):
# Should not be able to create volume with nonexistent volume_type.
@@ -53,17 +49,5 @@
str(uuid.uuid4()))
-class VolumesTypesNegativeTestXML(BaseVolumeAdminTestXML,
- VolumeTypesNegativeTestBase):
- @classmethod
- def setUpClass(cls):
- super(VolumesTypesNegativeTestXML, cls).setUpClass()
- VolumeTypesNegativeTestBase.setUpClass(cls)
-
-
-class VolumesTypesNegativeTestJSON(BaseVolumeAdminTestJSON,
- VolumeTypesNegativeTestBase):
- @classmethod
- def setUpClass(cls):
- super(VolumesTypesNegativeTestJSON, cls).setUpClass()
- VolumeTypesNegativeTestBase.setUpClass(cls)
+class VolumesTypesNegativeTestXML(VolumeTypesNegativeTest):
+ _interface = 'xml'
diff --git a/tempest/tests/volume/base.py b/tempest/tests/volume/base.py
index 6625180..480f125 100644
--- a/tempest/tests/volume/base.py
+++ b/tempest/tests/volume/base.py
@@ -193,15 +193,18 @@
time.sleep(self.build_interval)
-class BaseVolumeTestJSON(BaseVolumeTest):
+class BaseVolumeAdminTest(BaseVolumeTest):
+ """Base test case class for all Volume Admin API tests."""
@classmethod
def setUpClass(cls):
- cls._interface = "json"
- super(BaseVolumeTestJSON, cls).setUpClass()
+ super(BaseVolumeAdminTest, cls).setUpClass()
+ cls.adm_user = cls.config.identity.admin_username
+ cls.adm_pass = cls.config.identity.admin_password
+ cls.adm_tenant = cls.config.identity.admin_tenant_name
+ if not all((cls.adm_user, cls.adm_pass, cls.adm_tenant)):
+ msg = ("Missing Volume Admin API credentials "
+ "in configuration.")
+ raise cls.skipException(msg)
-
-class BaseVolumeTestXML(BaseVolumeTest):
- @classmethod
- def setUpClass(cls):
- cls._interface = "xml"
- super(BaseVolumeTestXML, cls).setUpClass()
+ cls.os_adm = clients.AdminManager(interface=cls._interface)
+ cls.client = cls.os_adm.volume_types_client
diff --git a/tempest/tests/volume/test_volumes_get.py b/tempest/tests/volume/test_volumes_get.py
index bd271ed..a246afe 100644
--- a/tempest/tests/volume/test_volumes_get.py
+++ b/tempest/tests/volume/test_volumes_get.py
@@ -20,7 +20,14 @@
from tempest.tests.volume import base
-class VolumesGetTestBase(object):
+class VolumesGetTest(base.BaseVolumeTest):
+
+ _interface = "json"
+
+ @classmethod
+ def setUpClass(cls):
+ super(VolumesGetTest, cls).setUpClass()
+ cls.client = cls.volumes_client
@attr(type='smoke')
def test_volume_create_get_delete(self):
@@ -94,17 +101,5 @@
self.client.wait_for_resource_deletion(volume['id'])
-class VolumesGetTestXML(base.BaseVolumeTestXML, VolumesGetTestBase):
- @classmethod
- def setUpClass(cls):
- cls._interface = "xml"
- super(VolumesGetTestXML, cls).setUpClass()
- cls.client = cls.volumes_client
-
-
-class VolumesGetTestJSON(base.BaseVolumeTestJSON, VolumesGetTestBase):
- @classmethod
- def setUpClass(cls):
- cls._interface = "json"
- super(VolumesGetTestJSON, cls).setUpClass()
- cls.client = cls.volumes_client
+class VolumesGetTestXML(VolumesGetTest):
+ _interface = "xml"
diff --git a/tempest/tests/volume/test_volumes_list.py b/tempest/tests/volume/test_volumes_list.py
index 64691d4..a8fedb9 100644
--- a/tempest/tests/volume/test_volumes_list.py
+++ b/tempest/tests/volume/test_volumes_list.py
@@ -20,7 +20,7 @@
from tempest.tests.volume import base
-class VolumesListTestBase(object):
+class VolumesListTest(base.BaseVolumeTest):
"""
This test creates a number of 1G volumes. To run successfully,
@@ -30,6 +30,52 @@
VOLUME_BACKING_FILE_SIZE is atleast 4G in your localrc
"""
+ _interface = 'json'
+
+ @classmethod
+ def setUpClass(cls):
+ super(VolumesListTest, cls).setUpClass()
+ cls.client = cls.volumes_client
+
+ # Create 3 test volumes
+ cls.volume_list = []
+ cls.volume_id_list = []
+ for i in range(3):
+ v_name = rand_name('volume')
+ metadata = {'Type': 'work'}
+ try:
+ resp, volume = cls.client.create_volume(size=1,
+ display_name=v_name,
+ metadata=metadata)
+ cls.client.wait_for_volume_status(volume['id'], 'available')
+ resp, volume = cls.client.get_volume(volume['id'])
+ cls.volume_list.append(volume)
+ cls.volume_id_list.append(volume['id'])
+ except Exception:
+ if cls.volume_list:
+ # We could not create all the volumes, though we were able
+ # to create *some* of the volumes. This is typically
+ # because the backing file size of the volume group is
+ # too small. So, here, we clean up whatever we did manage
+ # to create and raise a SkipTest
+ for volid in cls.volume_id_list:
+ cls.client.delete_volume(volid)
+ cls.client.wait_for_resource_deletion(volid)
+ msg = ("Failed to create ALL necessary volumes to run "
+ "test. This typically means that the backing file "
+ "size of the nova-volumes group is too small to "
+ "create the 3 volumes needed by this test case")
+ raise cls.skipException(msg)
+ raise
+
+ @classmethod
+ def tearDownClass(cls):
+ # Delete the created volumes
+ for volid in cls.volume_id_list:
+ resp, _ = cls.client.delete_volume(volid)
+ cls.client.wait_for_resource_deletion(volid)
+ super(VolumesListTest, cls).tearDownClass()
+
@attr(type='smoke')
def test_volume_list(self):
# Get a list of Volumes
@@ -57,95 +103,5 @@
for m_vol in missing_vols))
-class VolumeListTestXML(base.BaseVolumeTestXML, VolumesListTestBase):
- @classmethod
- def setUpClass(cls):
- cls._interface = 'xml'
- super(VolumeListTestXML, cls).setUpClass()
- cls.client = cls.volumes_client
-
- # Create 3 test volumes
- cls.volume_list = []
- cls.volume_id_list = []
- for i in range(3):
- v_name = rand_name('volume')
- metadata = {'Type': 'work'}
- try:
- resp, volume = cls.client.create_volume(size=1,
- display_name=v_name,
- metadata=metadata)
- cls.client.wait_for_volume_status(volume['id'], 'available')
- resp, volume = cls.client.get_volume(volume['id'])
- cls.volume_list.append(volume)
- cls.volume_id_list.append(volume['id'])
- except Exception:
- if cls.volume_list:
- # We could not create all the volumes, though we were able
- # to create *some* of the volumes. This is typically
- # because the backing file size of the volume group is
- # too small. So, here, we clean up whatever we did manage
- # to create and raise a SkipTest
- for volid in cls.volume_id_list:
- cls.client.delete_volume(volid)
- cls.client.wait_for_resource_deletion(volid)
- msg = ("Failed to create ALL necessary volumes to run "
- "test. This typically means that the backing file "
- "size of the nova-volumes group is too small to "
- "create the 3 volumes needed by this test case")
- raise cls.skipException(msg)
- raise
-
- @classmethod
- def tearDownClass(cls):
- # Delete the created volumes
- for volid in cls.volume_id_list:
- resp, _ = cls.client.delete_volume(volid)
- cls.client.wait_for_resource_deletion(volid)
- super(VolumeListTestXML, cls).tearDownClass()
-
-
-class VolumeListTestJSON(base.BaseVolumeTestJSON, VolumesListTestBase):
- @classmethod
- def setUpClass(cls):
- cls._interface = 'json'
- super(VolumeListTestJSON, cls).setUpClass()
- cls.client = cls.volumes_client
-
- # Create 3 test volumes
- cls.volume_list = []
- cls.volume_id_list = []
- for i in range(3):
- v_name = rand_name('volume')
- metadata = {'Type': 'work'}
- try:
- resp, volume = cls.client.create_volume(size=1,
- display_name=v_name,
- metadata=metadata)
- cls.client.wait_for_volume_status(volume['id'], 'available')
- resp, volume = cls.client.get_volume(volume['id'])
- cls.volume_list.append(volume)
- cls.volume_id_list.append(volume['id'])
- except Exception:
- if cls.volume_list:
- # We could not create all the volumes, though we were able
- # to create *some* of the volumes. This is typically
- # because the backing file size of the volume group is
- # too small. So, here, we clean up whatever we did manage
- # to create and raise a SkipTest
- for volid in cls.volume_id_list:
- cls.client.delete_volume(volid)
- cls.client.wait_for_resource_deletion(volid)
- msg = ("Failed to create ALL necessary volumes to run "
- "test. This typically means that the backing file "
- "size of the nova-volumes group is too small to "
- "create the 3 volumes needed by this test case")
- raise cls.skipException(msg)
- raise
-
- @classmethod
- def tearDownClass(cls):
- # Delete the created volumes
- for volid in cls.volume_id_list:
- resp, _ = cls.client.delete_volume(volid)
- cls.client.wait_for_resource_deletion(volid)
- super(VolumeListTestJSON, cls).tearDownClass()
+class VolumeListTestXML(VolumesListTest):
+ _interface = 'xml'
diff --git a/tempest/tests/volume/test_volumes_negative.py b/tempest/tests/volume/test_volumes_negative.py
index dc1fad0..c7d4374 100644
--- a/tempest/tests/volume/test_volumes_negative.py
+++ b/tempest/tests/volume/test_volumes_negative.py
@@ -20,7 +20,13 @@
from tempest.tests.volume import base
-class VolumesNegativeTestBase(object):
+class VolumesNegativeTest(base.BaseVolumeTest):
+ _interface = 'json'
+
+ @classmethod
+ def setUpClass(cls):
+ super(VolumesNegativeTest, cls).setUpClass()
+ cls.client = cls.volumes_client
def test_volume_get_nonexistant_volume_id(self):
# Should not be able to get a nonexistant volume
@@ -94,16 +100,5 @@
self.assertRaises(exceptions.NotFound, self.client.delete_volume, '')
-class VolumesNegativeTestXML(base.BaseVolumeTestXML, VolumesNegativeTestBase):
- @classmethod
- def setUpClass(cls):
- super(VolumesNegativeTestXML, cls).setUpClass()
- cls.client = cls.volumes_client
-
-
-class VolumesNegativeTestJSON(base.BaseVolumeTestJSON,
- VolumesNegativeTestBase):
- @classmethod
- def setUpClass(cls):
- super(VolumesNegativeTestJSON, cls).setUpClass()
- cls.client = cls.volumes_client
+class VolumesNegativeTestXML(VolumesNegativeTest):
+ _interface = 'xml'
diff --git a/tempest/tests/volume/test_volumes_snapshots.py b/tempest/tests/volume/test_volumes_snapshots.py
index 3acc5f6..e7fa97d 100644
--- a/tempest/tests/volume/test_volumes_snapshots.py
+++ b/tempest/tests/volume/test_volumes_snapshots.py
@@ -15,7 +15,8 @@
from tempest.tests.volume import base
-class VolumesSnapshotTestBase(object):
+class VolumesSnapshotTest(base.BaseVolumeTest):
+ _interface = "json"
def test_volume_from_snapshot(self):
volume_origin = self.create_volume(size=1)
@@ -24,29 +25,15 @@
snapshot_id=
snapshot['id'])
self.snapshots_client.delete_snapshot(snapshot['id'])
- self.client.delete_volume(volume_snap['id'])
+ self.volumes_client.delete_volume(volume_snap['id'])
self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
self.snapshots.remove(snapshot)
- self.client.delete_volume(volume_origin['id'])
- self.client.wait_for_resource_deletion(volume_snap['id'])
+ self.volumes_client.delete_volume(volume_origin['id'])
+ self.volumes_client.wait_for_resource_deletion(volume_snap['id'])
self.volumes.remove(volume_snap)
- self.client.wait_for_resource_deletion(volume_origin['id'])
+ self.volumes_client.wait_for_resource_deletion(volume_origin['id'])
self.volumes.remove(volume_origin)
-class VolumesSnapshotTestXML(base.BaseVolumeTestXML,
- VolumesSnapshotTestBase):
- @classmethod
- def setUpClass(cls):
- cls._interface = "xml"
- super(VolumesSnapshotTestXML, cls).setUpClass()
- cls.client = cls.volumes_client
-
-
-class VolumesSnapshotTestJSON(base.BaseVolumeTestJSON,
- VolumesSnapshotTestBase):
- @classmethod
- def setUpClass(cls):
- cls._interface = "json"
- super(VolumesSnapshotTestJSON, cls).setUpClass()
- cls.client = cls.volumes_client
+class VolumesSnapshotTestXML(VolumesSnapshotTest):
+ _interface = "xml"