Merge "Add functional tests for python-cinderclient"
This commit is contained in:
@@ -97,7 +97,7 @@ class ClientTestBase(base.ClientTestBase):
|
|||||||
for field in field_names:
|
for field in field_names:
|
||||||
self.assertIn(field, item)
|
self.assertIn(field, item)
|
||||||
|
|
||||||
def assert_volume_details_rows(self, items):
|
def assert_volume_details(self, items):
|
||||||
"""Check presence of common volume properties.
|
"""Check presence of common volume properties.
|
||||||
|
|
||||||
:param items: volume properties
|
:param items: volume properties
|
||||||
@@ -134,7 +134,6 @@ class ClientTestBase(base.ClientTestBase):
|
|||||||
def check_volume_deleted(self, volume_id, timeout=60):
|
def check_volume_deleted(self, volume_id, timeout=60):
|
||||||
"""Check that volume deleted successfully.
|
"""Check that volume deleted successfully.
|
||||||
|
|
||||||
:param timeout:
|
|
||||||
:param volume_id: uuid4 id of given volume
|
:param volume_id: uuid4 id of given volume
|
||||||
:param timeout: timeout in seconds
|
:param timeout: timeout in seconds
|
||||||
"""
|
"""
|
||||||
@@ -179,3 +178,66 @@ class ClientTestBase(base.ClientTestBase):
|
|||||||
for item in items:
|
for item in items:
|
||||||
obj[item['Property']] = six.text_type(item['Value'])
|
obj[item['Property']] = six.text_type(item['Value'])
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
def wait_for_snapshot_status(self, snapshot_id, status, timeout=60):
|
||||||
|
"""Wait until snapshot reaches given status.
|
||||||
|
|
||||||
|
:param snapshot_id: uuid4 id of given volume
|
||||||
|
:param status: expected snapshot's status
|
||||||
|
:param timeout: timeout in seconds
|
||||||
|
"""
|
||||||
|
start_time = time.time()
|
||||||
|
while time.time() - start_time < timeout:
|
||||||
|
if status in self.cinder('snapshot-show', params=snapshot_id):
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
self.fail("Snapshot %s did not reach status %s after %d seconds."
|
||||||
|
% (snapshot_id, status, timeout))
|
||||||
|
|
||||||
|
def check_snapshot_deleted(self, snapshot_id, timeout=60):
|
||||||
|
"""Check that snapshot deleted successfully.
|
||||||
|
|
||||||
|
:param snapshot_id: the given snapshot id
|
||||||
|
:param timeout: timeout in seconds
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
start_time = time.time()
|
||||||
|
while time.time() - start_time < timeout:
|
||||||
|
if snapshot_id not in self.cinder('snapshot-show',
|
||||||
|
params=snapshot_id):
|
||||||
|
break
|
||||||
|
except exceptions.CommandFailed:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.fail("Snapshot %s has not deleted after %d seconds."
|
||||||
|
% (snapshot_id, timeout))
|
||||||
|
|
||||||
|
def assert_snapshot_details(self, items):
|
||||||
|
"""Check presence of common volume snapshot properties.
|
||||||
|
|
||||||
|
:param items: volume snapshot properties
|
||||||
|
"""
|
||||||
|
values = ('created_at', 'description', 'id', 'metadata', 'name',
|
||||||
|
'size', 'status', 'volume_id')
|
||||||
|
|
||||||
|
for value in values:
|
||||||
|
self.assertIn(value, items)
|
||||||
|
|
||||||
|
def snapshot_create(self, volume_id):
|
||||||
|
"""Create a volume snapshot from the volume id.
|
||||||
|
|
||||||
|
:param volume_id: the given volume id to create a snapshot
|
||||||
|
"""
|
||||||
|
output = self.cinder('snapshot-create', params=volume_id)
|
||||||
|
snapshot = self._get_property_from_output(output)
|
||||||
|
self.addCleanup(self.snapshot_delete, snapshot['id'])
|
||||||
|
self.wait_for_snapshot_status(snapshot['id'], 'available')
|
||||||
|
return snapshot
|
||||||
|
|
||||||
|
def snapshot_delete(self, snapshot_id):
|
||||||
|
"""Delete specified snapshot by ID.
|
||||||
|
|
||||||
|
:param snapshot_id: the given snapshot id
|
||||||
|
"""
|
||||||
|
if snapshot_id in self.cinder('snapshot-list'):
|
||||||
|
self.cinder('snapshot-delete', params=snapshot_id)
|
||||||
|
@@ -22,7 +22,7 @@ class CinderClientTests(base.ClientTestBase):
|
|||||||
def test_volume_create_delete_id(self):
|
def test_volume_create_delete_id(self):
|
||||||
"""Create and delete a volume by ID."""
|
"""Create and delete a volume by ID."""
|
||||||
volume = self.volume_create(params='1')
|
volume = self.volume_create(params='1')
|
||||||
self.assert_volume_details_rows(volume.keys())
|
self.assert_volume_details(volume.keys())
|
||||||
self.volume_delete(volume['id'])
|
self.volume_delete(volume['id'])
|
||||||
self.check_volume_deleted(volume['id'])
|
self.check_volume_deleted(volume['id'])
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ class CinderClientTests(base.ClientTestBase):
|
|||||||
output = self.cinder('show', params='TestVolumeShow')
|
output = self.cinder('show', params='TestVolumeShow')
|
||||||
volume = self._get_property_from_output(output)
|
volume = self._get_property_from_output(output)
|
||||||
self.assertEqual('TestVolumeShow', volume['name'])
|
self.assertEqual('TestVolumeShow', volume['name'])
|
||||||
self.assert_volume_details_rows(volume.keys())
|
self.assert_volume_details(volume.keys())
|
||||||
|
|
||||||
self.volume_delete(volume['id'])
|
self.volume_delete(volume['id'])
|
||||||
self.check_volume_deleted(volume['id'])
|
self.check_volume_deleted(volume['id'])
|
||||||
@@ -55,3 +55,13 @@ class CinderClientTests(base.ClientTestBase):
|
|||||||
|
|
||||||
self.volume_delete(volume['id'])
|
self.volume_delete(volume['id'])
|
||||||
self.check_volume_deleted(volume['id'])
|
self.check_volume_deleted(volume['id'])
|
||||||
|
|
||||||
|
def test_snapshot_create_and_delete(self):
|
||||||
|
"""Create a volume snapshot and then delete."""
|
||||||
|
volume = self.volume_create(params='1')
|
||||||
|
snapshot = self.snapshot_create(volume['id'])
|
||||||
|
self.assert_snapshot_details(snapshot.keys())
|
||||||
|
self.snapshot_delete(snapshot['id'])
|
||||||
|
self.check_snapshot_deleted(snapshot['id'])
|
||||||
|
self.volume_delete(volume['id'])
|
||||||
|
self.check_volume_deleted(volume['id'])
|
||||||
|
Reference in New Issue
Block a user