Merge "Add testcases for volume"
This commit is contained in:
@@ -109,6 +109,65 @@ class VolumesTestJSON(base.BaseV2ComputeTest):
|
||||
', '.join(m_vol['displayName']
|
||||
for m_vol in missing_volumes))
|
||||
|
||||
@attr(type='gate')
|
||||
def test_volume_list_param_limit(self):
|
||||
# Return the list of volumes based on limit set
|
||||
params = {'limit': 2}
|
||||
resp, fetched_vol_list = self.client.list_volumes(params=params)
|
||||
self.assertEqual(200, resp.status)
|
||||
|
||||
self.assertEqual(len(fetched_vol_list), params['limit'],
|
||||
"Failed to list volumes by limit set")
|
||||
|
||||
@attr(type='gate')
|
||||
def test_volume_list_with_detail_param_limit(self):
|
||||
# Return the list of volumes with details based on limit set.
|
||||
params = {'limit': 2}
|
||||
resp, fetched_vol_list = \
|
||||
self.client.list_volumes_with_detail(params=params)
|
||||
self.assertEqual(200, resp.status)
|
||||
|
||||
self.assertEqual(len(fetched_vol_list), params['limit'],
|
||||
"Failed to list volume details by limit set")
|
||||
|
||||
@attr(type='gate')
|
||||
def test_volume_list_param_offset_and_limit(self):
|
||||
# Return the list of volumes based on offset and limit set.
|
||||
# get all volumes list
|
||||
response, all_vol_list = self.client.list_volumes()
|
||||
params = {'offset': 1, 'limit': 1}
|
||||
resp, fetched_vol_list = self.client.list_volumes(params=params)
|
||||
self.assertEqual(200, resp.status)
|
||||
|
||||
# Validating length of the fetched volumes
|
||||
self.assertEqual(len(fetched_vol_list), params['limit'],
|
||||
"Failed to list volumes by offset and limit")
|
||||
# Validating offset of fetched volume
|
||||
for index, volume in enumerate(fetched_vol_list):
|
||||
self.assertEqual(volume['id'],
|
||||
all_vol_list[index + params['offset']]['id'],
|
||||
"Failed to list volumes by offset and limit")
|
||||
|
||||
@attr(type='gate')
|
||||
def test_volume_list_with_detail_param_offset_and_limit(self):
|
||||
# Return the list of volumes details based on offset and limit set.
|
||||
# get all volumes list
|
||||
response, all_vol_list = self.client.list_volumes_with_detail()
|
||||
params = {'offset': 1, 'limit': 1}
|
||||
resp, fetched_vol_list = \
|
||||
self.client.list_volumes_with_detail(params=params)
|
||||
self.assertEqual(200, resp.status)
|
||||
|
||||
# Validating length of the fetched volumes
|
||||
self.assertEqual(len(fetched_vol_list), params['limit'],
|
||||
"Failed to list volume details by offset and limit")
|
||||
# Validating offset of fetched volume
|
||||
for index, volume in enumerate(fetched_vol_list):
|
||||
self.assertEqual(volume['id'],
|
||||
all_vol_list[index + params['offset']]['id'],
|
||||
"Failed to list volume details by "
|
||||
"offset and limit")
|
||||
|
||||
|
||||
class VolumesTestXML(VolumesTestJSON):
|
||||
_interface = 'xml'
|
||||
|
||||
@@ -57,13 +57,13 @@ class VolumesListTest(base.BaseVolumeTest):
|
||||
# Create 3 test volumes
|
||||
cls.volume_list = []
|
||||
cls.volume_id_list = []
|
||||
cls.metadata = {'Type': 'work'}
|
||||
for i in range(3):
|
||||
v_name = data_utils.rand_name('volume')
|
||||
metadata = {'Type': 'work'}
|
||||
try:
|
||||
resp, volume = cls.client.create_volume(size=1,
|
||||
display_name=v_name,
|
||||
metadata=metadata)
|
||||
metadata=cls.metadata)
|
||||
cls.client.wait_for_volume_status(volume['id'], 'available')
|
||||
resp, volume = cls.client.get_volume(volume['id'])
|
||||
cls.volume_list.append(volume)
|
||||
@@ -88,6 +88,25 @@ class VolumesListTest(base.BaseVolumeTest):
|
||||
cls.client.wait_for_resource_deletion(volid)
|
||||
super(VolumesListTest, cls).tearDownClass()
|
||||
|
||||
def _list_by_param_value_and_assert(self, params, with_detail=False):
|
||||
"""
|
||||
Perform list or list_details action with given params
|
||||
and validates result.
|
||||
"""
|
||||
if with_detail:
|
||||
resp, fetched_vol_list = \
|
||||
self.client.list_volumes_with_detail(params=params)
|
||||
else:
|
||||
resp, fetched_vol_list = self.client.list_volumes(params=params)
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
# Validating params of fetched volumes
|
||||
for volume in fetched_vol_list:
|
||||
for key in params:
|
||||
msg = "Failed to list volumes %s by %s" % \
|
||||
('details' if with_detail else '', key)
|
||||
self.assertEqual(params[key], volume[key], msg)
|
||||
|
||||
@attr(type='smoke')
|
||||
def test_volume_list(self):
|
||||
# Get a list of Volumes
|
||||
@@ -164,6 +183,34 @@ class VolumesListTest(base.BaseVolumeTest):
|
||||
self.assertEqual(zone, volume['availability_zone'])
|
||||
self.assertVolumesIn(fetched_list, self.volume_list)
|
||||
|
||||
@attr(type='gate')
|
||||
def test_volume_list_with_param_metadata(self):
|
||||
# Test to list volumes when metadata param is given
|
||||
params = {'metadata': self.metadata}
|
||||
self._list_by_param_value_and_assert(params)
|
||||
|
||||
@attr(type='gate')
|
||||
def test_volume_list_with_detail_param_metadata(self):
|
||||
# Test to list volumes details when metadata param is given
|
||||
params = {'metadata': self.metadata}
|
||||
self._list_by_param_value_and_assert(params, with_detail=True)
|
||||
|
||||
@attr(type='gate')
|
||||
def test_volume_list_param_display_name_and_status(self):
|
||||
# Test to list volume when display name and status param is given
|
||||
volume = self.volume_list[data_utils.rand_int_id(0, 2)]
|
||||
params = {'display_name': volume['display_name'],
|
||||
'status': 'available'}
|
||||
self._list_by_param_value_and_assert(params)
|
||||
|
||||
@attr(type='gate')
|
||||
def test_volume_list_with_detail_param_display_name_and_status(self):
|
||||
# Test to list volume when name and status param is given
|
||||
volume = self.volume_list[data_utils.rand_int_id(0, 2)]
|
||||
params = {'display_name': volume['display_name'],
|
||||
'status': 'available'}
|
||||
self._list_by_param_value_and_assert(params, with_detail=True)
|
||||
|
||||
|
||||
class VolumeListTestXML(VolumesListTest):
|
||||
_interface = 'xml'
|
||||
|
||||
@@ -37,6 +37,27 @@ class VolumesSnapshotTest(base.BaseVolumeTest):
|
||||
def tearDownClass(cls):
|
||||
super(VolumesSnapshotTest, cls).tearDownClass()
|
||||
|
||||
def _list_by_param_values_and_assert(self, params, with_detail=False):
|
||||
"""
|
||||
Perform list or list_details action with given params
|
||||
and validates result.
|
||||
"""
|
||||
if with_detail:
|
||||
resp, fetched_snap_list = \
|
||||
self.snapshots_client.\
|
||||
list_snapshots_with_detail(params=params)
|
||||
else:
|
||||
resp, fetched_snap_list = \
|
||||
self.snapshots_client.list_snapshots(params=params)
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
# Validating params of fetched snapshots
|
||||
for snap in fetched_snap_list:
|
||||
for key in params:
|
||||
msg = "Failed to list snapshots %s by %s" % \
|
||||
('details' if with_detail else '', key)
|
||||
self.assertEqual(params[key], snap[key], msg)
|
||||
|
||||
@attr(type='gate')
|
||||
def test_snapshot_create_get_list_update_delete(self):
|
||||
# Create a snapshot
|
||||
@@ -82,6 +103,46 @@ class VolumesSnapshotTest(base.BaseVolumeTest):
|
||||
self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
|
||||
self.snapshots.remove(snapshot)
|
||||
|
||||
@attr(type='gate')
|
||||
def test_snapshots_list_with_params(self):
|
||||
"""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)
|
||||
|
||||
# Verify list snapshots by display_name filter
|
||||
params = {'display_name': snapshot['display_name']}
|
||||
self._list_by_param_values_and_assert(params)
|
||||
|
||||
# Verify list snapshots by status filter
|
||||
params = {'status': 'available'}
|
||||
self._list_by_param_values_and_assert(params)
|
||||
|
||||
# Verify list snapshots by status and display name filter
|
||||
params = {'status': 'available',
|
||||
'display_name': snapshot['display_name']}
|
||||
self._list_by_param_values_and_assert(params)
|
||||
|
||||
@attr(type='gate')
|
||||
def test_snapshots_list_details_with_params(self):
|
||||
"""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)
|
||||
|
||||
# Verify list snapshot details by display_name filter
|
||||
params = {'display_name': snapshot['display_name']}
|
||||
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._list_by_param_values_and_assert(params, with_detail=True)
|
||||
|
||||
@attr(type='gate')
|
||||
def test_volume_from_snapshot(self):
|
||||
# Create a temporary snap using wrapper method from base, then
|
||||
|
||||
@@ -44,7 +44,7 @@ class SnapshotsClientJSON(RestClient):
|
||||
body = json.loads(body)
|
||||
return resp, body['snapshots']
|
||||
|
||||
def list_snapshot_with_detail(self, params=None):
|
||||
def list_snapshots_with_detail(self, params=None):
|
||||
"""List the details of all snapshots."""
|
||||
url = 'snapshots/detail'
|
||||
if params:
|
||||
|
||||
Reference in New Issue
Block a user