From e280f66dc558901cf0bb2fd6ea4360c9d6089b34 Mon Sep 17 00:00:00 2001 From: "jeremy.zhang" Date: Fri, 30 Jun 2017 17:38:58 +0800 Subject: [PATCH] Add response assertions and remove unused variables in volume tests This patch adds response assertions where the response body is declared but never used in some volume api tests. And also some unused variables are removed to make code clean. Change-Id: I29e6e8f1dac42b33d2ac020f682f57db9218115a --- tempest/api/volume/admin/test_volume_quotas.py | 2 +- tempest/api/volume/test_snapshot_metadata.py | 7 +++++-- tempest/api/volume/test_volume_metadata.py | 3 +++ tempest/api/volume/test_volume_transfers.py | 2 ++ tempest/api/volume/test_volumes_actions.py | 4 ++-- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tempest/api/volume/admin/test_volume_quotas.py b/tempest/api/volume/admin/test_volume_quotas.py index ae4b579cde..f358d7f7d8 100644 --- a/tempest/api/volume/admin/test_volume_quotas.py +++ b/tempest/api/volume/admin/test_volume_quotas.py @@ -155,7 +155,7 @@ class BaseVolumeQuotasAdminTestJSON(base.BaseVolumeAdminTest): # Accepts a volume transfer self.alt_transfer_client.accept_volume_transfer( - transfer_id, auth_key=auth_key)['transfer'] + transfer_id, auth_key=auth_key) # Verify volume transferred is available waiters.wait_for_volume_resource_status( diff --git a/tempest/api/volume/test_snapshot_metadata.py b/tempest/api/volume/test_snapshot_metadata.py index 164ed378b8..e54cd65f44 100644 --- a/tempest/api/volume/test_snapshot_metadata.py +++ b/tempest/api/volume/test_snapshot_metadata.py @@ -55,6 +55,7 @@ class SnapshotMetadataTestJSON(base.BaseVolumeTest): # Create metadata body = self.snapshots_client.create_snapshot_metadata( self.snapshot['id'], metadata)['metadata'] + self.assertThat(body.items(), matchers.ContainsAll(metadata.items())) # Get the metadata of the snapshot body = self.snapshots_client.show_snapshot_metadata( @@ -65,6 +66,7 @@ class SnapshotMetadataTestJSON(base.BaseVolumeTest): # Update metadata body = self.snapshots_client.update_snapshot_metadata( self.snapshot['id'], metadata=update)['metadata'] + self.assertEqual(update, body) body = self.snapshots_client.show_snapshot_metadata( self.snapshot['id'])['metadata'] self.assertEqual(update, body, 'Update snapshot metadata failed') @@ -89,8 +91,8 @@ class SnapshotMetadataTestJSON(base.BaseVolumeTest): "key2": "value2", "key3": "value3_update"} # Create metadata for the snapshot - body = self.snapshots_client.create_snapshot_metadata( - self.snapshot['id'], metadata)['metadata'] + self.snapshots_client.create_snapshot_metadata( + self.snapshot['id'], metadata) # Get the metadata of the snapshot body = self.snapshots_client.show_snapshot_metadata( self.snapshot['id'])['metadata'] @@ -98,6 +100,7 @@ class SnapshotMetadataTestJSON(base.BaseVolumeTest): # Update metadata item body = self.snapshots_client.update_snapshot_metadata_item( self.snapshot['id'], "key3", meta=update_item)['meta'] + self.assertEqual(update_item, body) # Get the metadata of the snapshot body = self.snapshots_client.show_snapshot_metadata( self.snapshot['id'])['metadata'] diff --git a/tempest/api/volume/test_volume_metadata.py b/tempest/api/volume/test_volume_metadata.py index b4d22fe68f..5e9a956cc4 100644 --- a/tempest/api/volume/test_volume_metadata.py +++ b/tempest/api/volume/test_volume_metadata.py @@ -45,6 +45,7 @@ class VolumesMetadataTest(base.BaseVolumeTest): body = self.volumes_client.create_volume_metadata(self.volume['id'], metadata)['metadata'] + self.assertThat(body.items(), matchers.ContainsAll(metadata.items())) # Get the metadata of the volume body = self.volumes_client.show_volume_metadata( self.volume['id'])['metadata'] @@ -54,6 +55,7 @@ class VolumesMetadataTest(base.BaseVolumeTest): # Update metadata body = self.volumes_client.update_volume_metadata( self.volume['id'], update)['metadata'] + self.assertEqual(update, body) body = self.volumes_client.show_volume_metadata( self.volume['id'])['metadata'] self.assertEqual(update, body, 'Update metadata failed') @@ -85,6 +87,7 @@ class VolumesMetadataTest(base.BaseVolumeTest): # Update metadata item body = self.volumes_client.update_volume_metadata_item( self.volume['id'], "key3", update_item)['meta'] + self.assertEqual(update_item, body) # Get the metadata of the volume body = self.volumes_client.show_volume_metadata( self.volume['id'])['metadata'] diff --git a/tempest/api/volume/test_volume_transfers.py b/tempest/api/volume/test_volume_transfers.py index 2c13a3ced1..4108da5dde 100644 --- a/tempest/api/volume/test_volume_transfers.py +++ b/tempest/api/volume/test_volume_transfers.py @@ -59,6 +59,8 @@ class VolumesTransfersTest(base.BaseVolumeTest): # Accept a volume transfer by alt_tenant body = self.alt_client.accept_volume_transfer( transfer_id, auth_key=auth_key)['transfer'] + for key in ['id', 'name', 'links', 'volume_id']: + self.assertIn(key, body) waiters.wait_for_volume_resource_status(self.alt_volumes_client, volume['id'], 'available') accepted_volume = self.alt_volumes_client.show_volume( diff --git a/tempest/api/volume/test_volumes_actions.py b/tempest/api/volume/test_volumes_actions.py index 8541c6da96..c4d10c3d1a 100644 --- a/tempest/api/volume/test_volumes_actions.py +++ b/tempest/api/volume/test_volumes_actions.py @@ -115,12 +115,12 @@ class VolumesActionsTest(base.BaseVolumeTest): @decorators.idempotent_id('92c4ef64-51b2-40c0-9f7e-4749fbaaba33') def test_reserve_unreserve_volume(self): # Mark volume as reserved. - body = self.volumes_client.reserve_volume(self.volume['id']) + self.volumes_client.reserve_volume(self.volume['id']) # To get the volume info body = self.volumes_client.show_volume(self.volume['id'])['volume'] self.assertIn('attaching', body['status']) # Unmark volume as reserved. - body = self.volumes_client.unreserve_volume(self.volume['id']) + self.volumes_client.unreserve_volume(self.volume['id']) # To get the volume info body = self.volumes_client.show_volume(self.volume['id'])['volume'] self.assertIn('available', body['status'])