diff options
author | Jenkins <jenkins@review.openstack.org> | 2015-08-26 16:00:31 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2015-08-26 16:00:31 +0000 |
commit | 1d71a6d138b8b45eef8c14ffa954077e2dfd8584 (patch) | |
tree | 3ef37058fbda2b22139f7bb2ec29f514c2bc1445 | |
parent | 8b4a5bf6f4b712eacb1f828d401931d4e6af31c1 (diff) | |
parent | f805f5ac19e68469c88beef5aaddb9315546ec3f (diff) | |
download | python-cinderclient-1d71a6d138b8b45eef8c14ffa954077e2dfd8584.tar.gz |
Merge "Add functional tests for python-cinderclient"
-rw-r--r-- | cinderclient/tests/functional/base.py | 66 | ||||
-rw-r--r-- | cinderclient/tests/functional/test_cli.py | 14 |
2 files changed, 76 insertions, 4 deletions
diff --git a/cinderclient/tests/functional/base.py b/cinderclient/tests/functional/base.py index e2b1b67..11e3072 100644 --- a/cinderclient/tests/functional/base.py +++ b/cinderclient/tests/functional/base.py @@ -97,7 +97,7 @@ class ClientTestBase(base.ClientTestBase): for field in field_names: self.assertIn(field, item) - def assert_volume_details_rows(self, items): + def assert_volume_details(self, items): """Check presence of common volume properties. :param items: volume properties @@ -134,7 +134,6 @@ class ClientTestBase(base.ClientTestBase): def check_volume_deleted(self, volume_id, timeout=60): """Check that volume deleted successfully. - :param timeout: :param volume_id: uuid4 id of given volume :param timeout: timeout in seconds """ @@ -179,3 +178,66 @@ class ClientTestBase(base.ClientTestBase): for item in items: obj[item['Property']] = six.text_type(item['Value']) 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) diff --git a/cinderclient/tests/functional/test_cli.py b/cinderclient/tests/functional/test_cli.py index b4beae5..4767d9c 100644 --- a/cinderclient/tests/functional/test_cli.py +++ b/cinderclient/tests/functional/test_cli.py @@ -22,7 +22,7 @@ class CinderClientTests(base.ClientTestBase): def test_volume_create_delete_id(self): """Create and delete a volume by ID.""" 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.check_volume_deleted(volume['id']) @@ -39,7 +39,7 @@ class CinderClientTests(base.ClientTestBase): output = self.cinder('show', params='TestVolumeShow') volume = self._get_property_from_output(output) self.assertEqual('TestVolumeShow', volume['name']) - self.assert_volume_details_rows(volume.keys()) + self.assert_volume_details(volume.keys()) self.volume_delete(volume['id']) self.check_volume_deleted(volume['id']) @@ -55,3 +55,13 @@ class CinderClientTests(base.ClientTestBase): self.volume_delete(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']) |