Cleanup try/except/finally blocks in several tests
There are several tests that have large try/except blocks which catch
Exception and then log their own error message but don't include the
original exception message. Some of these also have finally blocks doing
cleanup which could be performed with a call to self.addCleanup in the
test itself. Since this patch removes the useless self.fail with a
custom message masking the original exception, I also refactored the
finally blocks to use addCleanup instead.
Fixes bug 1207893
Change-Id: I6e9532e5067bbc0458ed3dc3faac58151aa696a0
diff --git a/tempest/api/compute/admin/test_quotas.py b/tempest/api/compute/admin/test_quotas.py
index 4e42dd0..156274d 100644
--- a/tempest/api/compute/admin/test_quotas.py
+++ b/tempest/api/compute/admin/test_quotas.py
@@ -84,24 +84,14 @@
'key_pairs': 200, 'injected_file_path_bytes': 512,
'instances': 20, 'security_group_rules': 20,
'cores': 2, 'security_groups': 20}
- try:
- # Update limits for all quota resources
- resp, quota_set = self.adm_client.update_quota_set(
- self.demo_tenant_id,
- **new_quota_set)
- self.addCleanup(self.adm_client.update_quota_set,
- self.demo_tenant_id, **self.default_quota_set)
- self.assertEqual(200, resp.status)
- self.assertEqual(new_quota_set, quota_set)
- except Exception:
- self.fail("Admin could not update quota set for the tenant")
- finally:
- # Reset quota resource limits to default values
- resp, quota_set = self.adm_client.update_quota_set(
- self.demo_tenant_id,
- **self.default_quota_set)
- self.assertEqual(200, resp.status, "Failed to reset quota "
- "defaults")
+ # Update limits for all quota resources
+ resp, quota_set = self.adm_client.update_quota_set(
+ self.demo_tenant_id,
+ **new_quota_set)
+ self.addCleanup(self.adm_client.update_quota_set,
+ self.demo_tenant_id, **self.default_quota_set)
+ self.assertEqual(200, resp.status)
+ self.assertEqual(new_quota_set, quota_set)
# TODO(afazekas): merge these test cases
@attr(type='gate')