From: Julia Varlamova Date: Wed, 12 Feb 2014 14:52:45 +0000 (+0400) Subject: Replace tearDown with addCleanup X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=48d2b1cb01b6f5e3be82207460dce6b42587e81b;p=openstack-build%2Fcinder-build.git Replace tearDown with addCleanup Infra team has indicated that tearDown should not be used and should be replaced with addCleanup in all places. This patch replaces tearDown with addCleanup methods in cinder/tests/api. Implements blueprint replace-teardown-with-addcleanup Change-Id: I640c1985bf7fce6f2fbd4de8e56448b6c9af51ca --- diff --git a/cinder/tests/api/contrib/test_admin_actions.py b/cinder/tests/api/contrib/test_admin_actions.py index 097e1176b..0a506c48e 100644 --- a/cinder/tests/api/contrib/test_admin_actions.py +++ b/cinder/tests/api/contrib/test_admin_actions.py @@ -12,8 +12,6 @@ import ast import os -import shutil -import tempfile import webob from oslo.config import cfg @@ -45,16 +43,9 @@ class AdminActionsTest(test.TestCase): def setUp(self): super(AdminActionsTest, self).setUp() - self.tempdir = tempfile.mkdtemp() - self.flags(rpc_backend='cinder.openstack.common.rpc.impl_fake') - self.flags(lock_path=self.tempdir) self.volume_api = volume_api.API() self.stubs.Set(brick_lvm.LVM, '_vg_exists', lambda x: True) - def tearDown(self): - shutil.rmtree(self.tempdir) - super(AdminActionsTest, self).tearDown() - def test_reset_status_as_admin(self): # admin context ctx = context.RequestContext('admin', 'fake', True) diff --git a/cinder/tests/api/contrib/test_backups.py b/cinder/tests/api/contrib/test_backups.py index a0474f337..c0ec72702 100644 --- a/cinder/tests/api/contrib/test_backups.py +++ b/cinder/tests/api/contrib/test_backups.py @@ -50,9 +50,6 @@ class BackupsAPITestCase(test.TestCase): self.context.project_id = 'fake' self.context.user_id = 'fake' - def tearDown(self): - super(BackupsAPITestCase, self).tearDown() - @staticmethod def _create_backup(volume_id=1, display_name='test_backup', diff --git a/cinder/tests/api/contrib/test_qos_specs_manage.py b/cinder/tests/api/contrib/test_qos_specs_manage.py index 0c3afd7f2..f63dfe596 100644 --- a/cinder/tests/api/contrib/test_qos_specs_manage.py +++ b/cinder/tests/api/contrib/test_qos_specs_manage.py @@ -147,10 +147,7 @@ class QoSSpecManageApiTest(test.TestCase): #reset notifier drivers left over from other api/contrib tests notifier_api._reset_drivers() test_notifier.NOTIFICATIONS = [] - - def tearDown(self): - notifier_api._reset_drivers() - super(QoSSpecManageApiTest, self).tearDown() + self.addCleanup(notifier_api._reset_drivers) def test_index(self): self.stubs.Set(qos_specs, 'get_all_specs', diff --git a/cinder/tests/api/contrib/test_services.py b/cinder/tests/api/contrib/test_services.py index 420fcd854..9b10d1b37 100644 --- a/cinder/tests/api/contrib/test_services.py +++ b/cinder/tests/api/contrib/test_services.py @@ -140,9 +140,6 @@ class ServicesTest(test.TestCase): self.context = context.get_admin_context() self.controller = services.ServiceController() - def tearDown(self): - super(ServicesTest, self).tearDown() - def test_services_list(self): req = FakeRequest() res_dict = self.controller.index(req) diff --git a/cinder/tests/api/contrib/test_types_extra_specs.py b/cinder/tests/api/contrib/test_types_extra_specs.py index 33ee7a138..c7474dad0 100644 --- a/cinder/tests/api/contrib/test_types_extra_specs.py +++ b/cinder/tests/api/contrib/test_types_extra_specs.py @@ -75,10 +75,7 @@ class VolumeTypesExtraSpecsTest(test.TestCase): """to reset notifier drivers left over from other api/contrib tests""" notifier_api._reset_drivers() test_notifier.NOTIFICATIONS = [] - - def tearDown(self): - notifier_api._reset_drivers() - super(VolumeTypesExtraSpecsTest, self).tearDown() + self.addCleanup(notifier_api._reset_drivers) def test_index(self): self.stubs.Set(cinder.db, 'volume_type_extra_specs_get', diff --git a/cinder/tests/api/contrib/test_types_manage.py b/cinder/tests/api/contrib/test_types_manage.py index 6be714f22..74f9ae8ad 100644 --- a/cinder/tests/api/contrib/test_types_manage.py +++ b/cinder/tests/api/contrib/test_types_manage.py @@ -70,10 +70,7 @@ class VolumeTypesManageApiTest(test.TestCase): """to reset notifier drivers left over from other api/contrib tests""" notifier_api._reset_drivers() test_notifier.NOTIFICATIONS = [] - - def tearDown(self): - notifier_api._reset_drivers() - super(VolumeTypesManageApiTest, self).tearDown() + self.addCleanup(notifier_api._reset_drivers) def test_volume_types_delete(self): self.stubs.Set(volume_types, 'get_volume_type', diff --git a/cinder/tests/api/contrib/test_volume_actions.py b/cinder/tests/api/contrib/test_volume_actions.py index c0f6ded60..15613a53b 100644 --- a/cinder/tests/api/contrib/test_volume_actions.py +++ b/cinder/tests/api/contrib/test_volume_actions.py @@ -43,26 +43,22 @@ class VolumeActionsTest(test.TestCase): for _meth in self._methods: self.api_patchers[_meth] = mock.patch('cinder.volume.API.' + _meth) self.api_patchers[_meth].start() + self.addCleanup(self.api_patchers[_meth].stop) self.api_patchers[_meth].return_value = True vol = {'id': 'fake', 'host': 'fake', 'status': 'available', 'size': 1, 'migration_status': None, 'volume_type_id': 'fake'} self.get_patcher = mock.patch('cinder.volume.API.get') self.mock_volume_get = self.get_patcher.start() + self.addCleanup(self.get_patcher.stop) self.mock_volume_get.return_value = vol self.update_patcher = mock.patch('cinder.volume.API.update') self.mock_volume_update = self.update_patcher.start() + self.addCleanup(self.update_patcher.stop) self.mock_volume_update.return_value = vol self.flags(rpc_backend='cinder.openstack.common.rpc.impl_fake') - def tearDown(self): - for patcher in self.api_patchers: - self.api_patchers[patcher].stop() - self.update_patcher.stop() - self.get_patcher.stop() - super(VolumeActionsTest, self).tearDown() - def test_simple_api_actions(self): app = fakes.wsgi_app() for _action in self._actions: @@ -310,6 +306,7 @@ class VolumeRetypeActionsTest(VolumeActionsTest): name = path.split('.')[-1] self.retype_patchers[name] = mock.patch(path) self.retype_mocks[name] = self.retype_patchers[name].start() + self.addCleanup(self.retype_patchers[name].stop) self.retype_mocks['get_volume_type'].side_effect = get_vol_type self.retype_mocks['get_volume_type_by_name'].side_effect = get_vol_type @@ -318,11 +315,6 @@ class VolumeRetypeActionsTest(VolumeActionsTest): super(VolumeRetypeActionsTest, self).setUp() - def tearDown(self): - for name, patcher in self.retype_patchers.iteritems(): - patcher.stop() - super(VolumeRetypeActionsTest, self).tearDown() - def _retype_volume_exec(self, expected_status, new_type='foo'): req = webob.Request.blank('/v2/fake/volumes/1/action') req.method = 'POST' diff --git a/cinder/tests/api/contrib/test_volume_encryption_metadata.py b/cinder/tests/api/contrib/test_volume_encryption_metadata.py index 5d321435b..ff8a6c58c 100644 --- a/cinder/tests/api/contrib/test_volume_encryption_metadata.py +++ b/cinder/tests/api/contrib/test_volume_encryption_metadata.py @@ -72,10 +72,8 @@ class VolumeEncryptionMetadataTest(test.TestCase): self.ctxt = context.RequestContext('fake', 'fake') self.volume_id = self._create_volume(self.ctxt) - - def tearDown(self): - db.volume_destroy(self.ctxt.elevated(), self.volume_id) - super(VolumeEncryptionMetadataTest, self).tearDown() + self.addCleanup(db.volume_destroy, self.ctxt.elevated(), + self.volume_id) def test_index(self): self.stubs.Set(volume_types, 'is_encrypted', lambda *a, **kw: True) diff --git a/cinder/tests/api/contrib/test_volume_transfer.py b/cinder/tests/api/contrib/test_volume_transfer.py index 21d53f479..93affbeb7 100644 --- a/cinder/tests/api/contrib/test_volume_transfer.py +++ b/cinder/tests/api/contrib/test_volume_transfer.py @@ -42,9 +42,6 @@ class VolumeTransferAPITestCase(test.TestCase): def setUp(self): super(VolumeTransferAPITestCase, self).setUp() - def tearDown(self): - super(VolumeTransferAPITestCase, self).tearDown() - @staticmethod def _create_transfer(volume_id=1, display_name='test_transfer'): diff --git a/cinder/tests/api/contrib/test_volume_type_encryption.py b/cinder/tests/api/contrib/test_volume_type_encryption.py index 8cd7b50bf..ea83a13fe 100644 --- a/cinder/tests/api/contrib/test_volume_type_encryption.py +++ b/cinder/tests/api/contrib/test_volume_type_encryption.py @@ -58,10 +58,7 @@ class VolumeTypeEncryptionTest(test.TestCase): """to reset notifier drivers left over from other api/contrib tests""" notifier_api._reset_drivers() test_notifier.NOTIFICATIONS = [] - - def tearDown(self): - notifier_api._reset_drivers() - super(VolumeTypeEncryptionTest, self).tearDown() + self.addCleanup(notifier_api._reset_drivers) def _get_response(self, volume_type, admin=True, url='/v2/fake/types/%s/encryption', diff --git a/cinder/tests/api/v2/test_limits.py b/cinder/tests/api/v2/test_limits.py index 6c2316cd1..e00da70fa 100644 --- a/cinder/tests/api/v2/test_limits.py +++ b/cinder/tests/api/v2/test_limits.py @@ -732,9 +732,14 @@ class WsgiLimiterProxyTest(BaseLimitTestSuite): """ super(WsgiLimiterProxyTest, self).setUp() self.app = limits.WsgiLimiter(TEST_LIMITS) - self.oldHTTPConnection = ( + oldHTTPConnection = ( wire_HTTPConnection_to_WSGI("169.254.0.1:80", self.app)) self.proxy = limits.WsgiLimiterProxy("169.254.0.1:80") + self.addCleanup(self._restore, oldHTTPConnection) + + def _restore(self, oldHTTPConnection): + # restore original HTTPConnection object + httplib.HTTPConnection = oldHTTPConnection def test_200(self): """Successful request test.""" @@ -754,11 +759,6 @@ class WsgiLimiterProxyTest(BaseLimitTestSuite): self.assertEqual((delay, error), expected) - def tearDown(self): - # restore original HTTPConnection object - httplib.HTTPConnection = self.oldHTTPConnection - super(WsgiLimiterProxyTest, self).tearDown() - class LimitsViewBuilderTest(test.TestCase): def setUp(self):