]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Replace tearDown with addCleanup
authorJulia Varlamova <jvarlamova@mirantis.com>
Wed, 12 Feb 2014 14:52:45 +0000 (18:52 +0400)
committerJulia Varlamova <jvarlamova@mirantis.com>
Tue, 25 Feb 2014 11:02:02 +0000 (15:02 +0400)
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

cinder/tests/api/contrib/test_admin_actions.py
cinder/tests/api/contrib/test_backups.py
cinder/tests/api/contrib/test_qos_specs_manage.py
cinder/tests/api/contrib/test_services.py
cinder/tests/api/contrib/test_types_extra_specs.py
cinder/tests/api/contrib/test_types_manage.py
cinder/tests/api/contrib/test_volume_actions.py
cinder/tests/api/contrib/test_volume_encryption_metadata.py
cinder/tests/api/contrib/test_volume_transfer.py
cinder/tests/api/contrib/test_volume_type_encryption.py
cinder/tests/api/v2/test_limits.py

index 097e1176b29a51ad38647c6c205e6efde1f93dcb..0a506c48ebec96b24b9ddf0fa8c7837bc18360be 100644 (file)
@@ -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)
index a0474f33773a50ad5a02c050a04836ebb52c0dd1..c0ec7270212fcebefca9364fca3fc13e8205cdfa 100644 (file)
@@ -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',
index 0c3afd7f2c0a0f199adc26bb92b2903a1a2c1654..f63dfe5963a29737b4b7ff19f9fdfa0b4df3c6d1 100644 (file)
@@ -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',
index 420fcd8545561bdf5a0075820238fafb06b4acd1..9b10d1b378648a06a860f906cda1218b50a5e601 100644 (file)
@@ -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)
index 33ee7a138e9e5b532950b8905bff8c26c09d9fbe..c7474dad070e2e60ab2abfcaa2609accf52e5d5d 100644 (file)
@@ -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',
index 6be714f22626c8ae1f06bdee55bd20d37b171386..74f9ae8addd45931de26a88ce06bff95fe5d01bf 100644 (file)
@@ -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',
index c0f6ded6005fff3972bab49d616963100860f809..15613a53ba6fca3c60a8a9a4699d06f5f31d5665 100644 (file)
@@ -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'
index 5d321435b063f98c7d73ba51c7ca71559c175bfd..ff8a6c58c64ef1cbb1510e59d6b68e819376b3d3 100644 (file)
@@ -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)
index 21d53f47923411bc6b17815dd965787d59fcd682..93affbeb74a388f5be3d7cccafaacf4f4b9a7d69 100644 (file)
@@ -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'):
index 8cd7b50bf5bbff76e933d86f27398f2c62865787..ea83a13fe8b26005e2be221a5950de202b0f59a0 100644 (file)
@@ -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',
index 6c2316cd186da6b38c56aa5d3fbddf20f97ba4cf..e00da70fad17313b0b5332c2a67b66cf427d4bbd 100644 (file)
@@ -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):