Merge "enable volumes v2 snapshot tests by sharing codes"

This commit is contained in:
Jenkins 2014-09-29 16:42:09 +00:00 committed by Gerrit Code Review
commit 46a03b3de5
9 changed files with 127 additions and 43 deletions

View File

@ -69,6 +69,7 @@ class BaseVolumeTest(tempest.test.BaseTestCase):
if not CONF.volume_feature_enabled.api_v2:
msg = "Volume API v2 is disabled"
raise cls.skipException(msg)
cls.snapshots_client = cls.os.snapshots_v2_client
cls.volumes_client = cls.os.volumes_v2_client
cls.volumes_extension_client = cls.os.volumes_v2_extension_client
cls.availability_zone_client = (

View File

@ -17,13 +17,12 @@ from tempest.api.volume import base
from tempest import test
class SnapshotMetadataTest(base.BaseVolumeV1Test):
_interface = "json"
class SnapshotV2MetadataTestJSON(base.BaseVolumeTest):
@classmethod
@test.safe_setup
def setUpClass(cls):
super(SnapshotMetadataTest, cls).setUpClass()
super(SnapshotV2MetadataTestJSON, cls).setUpClass()
cls.client = cls.snapshots_client
# Create a volume
cls.volume = cls.create_volume()
@ -34,7 +33,7 @@ class SnapshotMetadataTest(base.BaseVolumeV1Test):
def tearDown(self):
# Update the metadata to {}
self.client.update_snapshot_metadata(self.snapshot_id, {})
super(SnapshotMetadataTest, self).tearDown()
super(SnapshotV2MetadataTestJSON, self).tearDown()
@test.attr(type='gate')
def test_create_get_delete_snapshot_metadata(self):
@ -100,5 +99,13 @@ class SnapshotMetadataTest(base.BaseVolumeV1Test):
self.assertEqual(expect, body)
class SnapshotMetadataTestXML(SnapshotMetadataTest):
class SnapshotV2MetadataTestXML(SnapshotV2MetadataTestJSON):
_interface = "xml"
class SnapshotV1MetadataTestJSON(SnapshotV2MetadataTestJSON):
_api_version = 1
class SnapshotV1MetadataTestXML(SnapshotV1MetadataTestJSON):
_interface = "xml"

View File

@ -20,21 +20,19 @@ LOG = logging.getLogger(__name__)
CONF = config.CONF
class VolumesSnapshotTest(base.BaseVolumeV1Test):
_interface = "json"
class VolumesV2SnapshotTestJSON(base.BaseVolumeTest):
@classmethod
@test.safe_setup
def setUpClass(cls):
super(VolumesSnapshotTest, cls).setUpClass()
super(VolumesV2SnapshotTestJSON, cls).setUpClass()
cls.volume_origin = cls.create_volume()
if not CONF.volume_feature_enabled.snapshot:
raise cls.skipException("Cinder volume snapshots are disabled")
@classmethod
def tearDownClass(cls):
super(VolumesSnapshotTest, cls).tearDownClass()
cls.name_field = cls.special_fields['name_field']
cls.descrip_field = cls.special_fields['descrip_field']
def _detach(self, volume_id):
"""Detach volume."""
@ -90,8 +88,8 @@ class VolumesSnapshotTest(base.BaseVolumeV1Test):
def test_snapshot_create_get_list_update_delete(self):
# Create a snapshot
s_name = data_utils.rand_name('snap')
snapshot = self.create_snapshot(self.volume_origin['id'],
display_name=s_name)
params = {self.name_field: s_name}
snapshot = self.create_snapshot(self.volume_origin['id'], **params)
# Get the snap and check for some of its details
_, snap_get = self.snapshots_client.get_snapshot(snapshot['id'])
@ -100,26 +98,26 @@ class VolumesSnapshotTest(base.BaseVolumeV1Test):
"Referred volume origin mismatch")
# Compare also with the output from the list action
tracking_data = (snapshot['id'], snapshot['display_name'])
tracking_data = (snapshot['id'], snapshot[self.name_field])
_, snaps_list = self.snapshots_client.list_snapshots()
snaps_data = [(f['id'], f['display_name']) for f in snaps_list]
snaps_data = [(f['id'], f[self.name_field]) for f in snaps_list]
self.assertIn(tracking_data, snaps_data)
# Updates snapshot with new values
new_s_name = data_utils.rand_name('new-snap')
new_desc = 'This is the new description of snapshot.'
params = {self.name_field: new_s_name,
self.descrip_field: new_desc}
_, update_snapshot = \
self.snapshots_client.update_snapshot(snapshot['id'],
display_name=new_s_name,
display_description=new_desc)
self.snapshots_client.update_snapshot(snapshot['id'], **params)
# Assert response body for update_snapshot method
self.assertEqual(new_s_name, update_snapshot['display_name'])
self.assertEqual(new_desc, update_snapshot['display_description'])
self.assertEqual(new_s_name, update_snapshot[self.name_field])
self.assertEqual(new_desc, update_snapshot[self.descrip_field])
# Assert response body for get_snapshot method
_, updated_snapshot = \
self.snapshots_client.get_snapshot(snapshot['id'])
self.assertEqual(new_s_name, updated_snapshot['display_name'])
self.assertEqual(new_desc, updated_snapshot['display_description'])
self.assertEqual(new_s_name, updated_snapshot[self.name_field])
self.assertEqual(new_desc, updated_snapshot[self.descrip_field])
# Delete the snapshot
self.snapshots_client.delete_snapshot(snapshot['id'])
@ -131,11 +129,11 @@ class VolumesSnapshotTest(base.BaseVolumeV1Test):
"""list snapshots with params."""
# Create a snapshot
display_name = data_utils.rand_name('snap')
snapshot = self.create_snapshot(self.volume_origin['id'],
display_name=display_name)
params = {self.name_field: display_name}
snapshot = self.create_snapshot(self.volume_origin['id'], **params)
# Verify list snapshots by display_name filter
params = {'display_name': snapshot['display_name']}
params = {self.name_field: snapshot[self.name_field]}
self._list_by_param_values_and_assert(params)
# Verify list snapshots by status filter
@ -144,7 +142,7 @@ class VolumesSnapshotTest(base.BaseVolumeV1Test):
# Verify list snapshots by status and display name filter
params = {'status': 'available',
'display_name': snapshot['display_name']}
self.name_field: snapshot[self.name_field]}
self._list_by_param_values_and_assert(params)
@test.attr(type='gate')
@ -152,18 +150,18 @@ class VolumesSnapshotTest(base.BaseVolumeV1Test):
"""list snapshot details with params."""
# Create a snapshot
display_name = data_utils.rand_name('snap')
snapshot = self.create_snapshot(self.volume_origin['id'],
display_name=display_name)
params = {self.name_field: display_name}
snapshot = self.create_snapshot(self.volume_origin['id'], **params)
# Verify list snapshot details by display_name filter
params = {'display_name': snapshot['display_name']}
params = {self.name_field: snapshot[self.name_field]}
self._list_by_param_values_and_assert(params, with_detail=True)
# Verify list snapshot details by status filter
params = {'status': 'available'}
self._list_by_param_values_and_assert(params, with_detail=True)
# Verify list snapshot details by status and display name filter
params = {'status': 'available',
'display_name': snapshot['display_name']}
self.name_field: snapshot[self.name_field]}
self._list_by_param_values_and_assert(params, with_detail=True)
@test.attr(type='gate')
@ -181,5 +179,13 @@ class VolumesSnapshotTest(base.BaseVolumeV1Test):
self.clear_snapshots()
class VolumesSnapshotTestXML(VolumesSnapshotTest):
class VolumesV2SnapshotTestXML(VolumesV2SnapshotTestJSON):
_interface = "xml"
class VolumesV1SnapshotTestJSON(VolumesV2SnapshotTestJSON):
_api_version = 1
class VolumesV1SnapshotTestXML(VolumesV1SnapshotTestJSON):
_interface = "xml"

View File

@ -21,12 +21,11 @@ from tempest import test
CONF = config.CONF
class VolumesSnapshotNegativeTest(base.BaseVolumeV1Test):
_interface = "json"
class VolumesV2SnapshotNegativeTestJSON(base.BaseVolumeTest):
@classmethod
def setUpClass(cls):
super(VolumesSnapshotNegativeTest, cls).setUpClass()
super(VolumesV2SnapshotNegativeTestJSON, cls).setUpClass()
if not CONF.volume_feature_enabled.snapshot:
raise cls.skipException("Cinder volume snapshots are disabled")
@ -48,5 +47,13 @@ class VolumesSnapshotNegativeTest(base.BaseVolumeV1Test):
None, display_name=s_name)
class VolumesSnapshotNegativeTestXML(VolumesSnapshotNegativeTest):
class VolumesV2SnapshotNegativeTestXML(VolumesV2SnapshotNegativeTestJSON):
_interface = "xml"
class VolumesV1SnapshotNegativeTestJSON(VolumesV2SnapshotNegativeTestJSON):
_api_version = 1
class VolumesV1SnapshotNegativeTestXML(VolumesV1SnapshotNegativeTestJSON):
_interface = "xml"

View File

@ -189,11 +189,15 @@ from tempest.services.volume.v2.json.availability_zone_client import \
from tempest.services.volume.v2.json.extensions_client import \
ExtensionsV2ClientJSON as VolumeV2ExtensionClientJSON
from tempest.services.volume.v2.json.qos_client import QosSpecsV2ClientJSON
from tempest.services.volume.v2.json.snapshots_client import \
SnapshotsV2ClientJSON
from tempest.services.volume.v2.json.volumes_client import VolumesV2ClientJSON
from tempest.services.volume.v2.xml.availability_zone_client import \
VolumeV2AvailabilityZoneClientXML
from tempest.services.volume.v2.xml.extensions_client import \
ExtensionsV2ClientXML as VolumeV2ExtensionClientXML
from tempest.services.volume.v2.xml.snapshots_client import \
SnapshotsV2ClientXML
from tempest.services.volume.v2.xml.volumes_client import VolumesV2ClientXML
from tempest.services.volume.xml.admin.volume_hosts_client import \
VolumeHostsClientXML
@ -246,6 +250,7 @@ class Manager(manager.Manager):
self.auth_provider)
self.backups_client = BackupsClientXML(self.auth_provider)
self.snapshots_client = SnapshotsClientXML(self.auth_provider)
self.snapshots_v2_client = SnapshotsV2ClientXML(self.auth_provider)
self.volumes_client = VolumesClientXML(self.auth_provider)
self.volumes_v2_client = VolumesV2ClientXML(self.auth_provider)
self.volume_types_client = VolumeTypesClientXML(
@ -325,6 +330,8 @@ class Manager(manager.Manager):
self.auth_provider)
self.backups_client = BackupsClientJSON(self.auth_provider)
self.snapshots_client = SnapshotsClientJSON(self.auth_provider)
self.snapshots_v2_client = SnapshotsV2ClientJSON(
self.auth_provider)
self.volumes_client = VolumesClientJSON(self.auth_provider)
self.volumes_v2_client = VolumesV2ClientJSON(self.auth_provider)
self.volume_types_client = VolumeTypesClientJSON(

View File

@ -24,15 +24,16 @@ CONF = config.CONF
LOG = logging.getLogger(__name__)
class SnapshotsClientJSON(rest_client.RestClient):
"""Client class to send CRUD Volume API requests."""
class BaseSnapshotsClientJSON(rest_client.RestClient):
"""Base Client class to send CRUD Volume API requests."""
def __init__(self, auth_provider):
super(SnapshotsClientJSON, self).__init__(auth_provider)
super(BaseSnapshotsClientJSON, self).__init__(auth_provider)
self.service = CONF.volume.catalog_type
self.build_interval = CONF.volume.build_interval
self.build_timeout = CONF.volume.build_timeout
self.create_resp = 200
def list_snapshots(self, params=None):
"""List all the snapshot."""
@ -77,7 +78,7 @@ class SnapshotsClientJSON(rest_client.RestClient):
post_body = json.dumps({'snapshot': post_body})
resp, body = self.post('snapshots', post_body)
body = json.loads(body)
self.expected_success(200, resp.status)
self.expected_success(self.create_resp, resp.status)
return resp, body['snapshot']
def update_snapshot(self, snapshot_id, **kwargs):
@ -203,3 +204,7 @@ class SnapshotsClientJSON(rest_client.RestClient):
resp, body = self.post('snapshots/%s/action' % snapshot_id, post_body)
self.expected_success(202, resp.status)
return resp, body
class SnapshotsClientJSON(BaseSnapshotsClientJSON):
"""Client class to send CRUD Volume V1 API requests."""

View File

@ -0,0 +1,23 @@
# 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.json import snapshots_client
class SnapshotsV2ClientJSON(snapshots_client.BaseSnapshotsClientJSON):
"""Client class to send CRUD Volume V2 API requests."""
def __init__(self, auth_provider):
super(SnapshotsV2ClientJSON, self).__init__(auth_provider)
self.api_version = "v2"
self.create_resp = 202

View File

@ -0,0 +1,23 @@
# 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.xml import snapshots_client
class SnapshotsV2ClientXML(snapshots_client.BaseSnapshotsClientXML):
"""Client class to send CRUD Volume V2 API requests."""
def __init__(self, auth_provider):
super(SnapshotsV2ClientXML, self).__init__(auth_provider)
self.api_version = "v2"
self.create_resp = 202

View File

@ -26,16 +26,17 @@ CONF = config.CONF
LOG = logging.getLogger(__name__)
class SnapshotsClientXML(rest_client.RestClient):
"""Client class to send CRUD Volume API requests."""
class BaseSnapshotsClientXML(rest_client.RestClient):
"""Base Client class to send CRUD Volume API requests."""
TYPE = "xml"
def __init__(self, auth_provider):
super(SnapshotsClientXML, self).__init__(auth_provider)
super(BaseSnapshotsClientXML, self).__init__(auth_provider)
self.service = CONF.volume.catalog_type
self.build_interval = CONF.volume.build_interval
self.build_timeout = CONF.volume.build_timeout
self.create_resp = 200
def list_snapshots(self, params=None):
"""List all snapshot."""
@ -90,7 +91,7 @@ class SnapshotsClientXML(rest_client.RestClient):
resp, body = self.post('snapshots',
str(common.Document(snapshot)))
body = common.xml_to_json(etree.fromstring(body))
self.expected_success(200, resp.status)
self.expected_success(self.create_resp, resp.status)
return resp, body
def update_snapshot(self, snapshot_id, **kwargs):
@ -243,3 +244,7 @@ class SnapshotsClientXML(rest_client.RestClient):
body = common.xml_to_json(etree.fromstring(body))
self.expected_success(202, resp.status)
return resp, body
class SnapshotsClientXML(BaseSnapshotsClientXML):
"""Client class to send CRUD Volume V1 API requests."""