Replace tearDown with addCleanup in some cinder unit tests.
Infra team has indicated that tearDown should not be used and should
be replaced with addCleanup in all places.
Implements blueprint replace-teardown-with-addcleanup
Change-Id: I8469ffb5c896d40f9979cd6d1f8da81be763ec14
class VolumeApiTest(test.TestCase):
def setUp(self):
super(VolumeApiTest, self).setUp()
+ self.addCleanup(fake_notifier.reset)
self.ext_mgr = extensions.ExtensionManager()
self.ext_mgr.extensions = {}
fake_image.stub_out_image_service(self.stubs)
self.flags(host='fake',
notification_driver=[fake_notifier.__name__])
-
self.stubs.Set(db, 'volume_get_all', stubs.stub_volume_get_all)
self.stubs.Set(volume_api.API, 'delete', stubs.stub_volume_delete)
self.stubs.Set(db, 'service_get_all_by_topic',
stubs.stub_service_get_all_by_topic)
self.maxDiff = None
- def tearDown(self):
- super(VolumeApiTest, self).tearDown()
- fake_notifier.reset()
-
def test_volume_create(self):
self.stubs.Set(volume_api.API, 'get', stubs.stub_volume_get)
self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
self._create_volume_db_entry()
self.volume_file = tempfile.NamedTemporaryFile()
+ self.addCleanup(self.volume_file.close)
for i in xrange(0, 128):
self.volume_file.write(os.urandom(1024))
- def tearDown(self):
- self.volume_file.close()
- super(BackupSwiftTestCase, self).tearDown()
-
def test_backup_uncompressed(self):
self._create_backup_db_entry()
self.flags(backup_compression_algorithm='none')
fake_db())
task._cast_create_volume(self.ctxt, spec, props)
-
- def tearDown(self):
- self.stubs.UnsetAll()
- super(CreateVolumeFlowTestCase, self).tearDown()
self.data = EMCSMISCommonData()
self.tempdir = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, self.tempdir)
super(EMCSMISISCSIDriverTestCase, self).setUp()
self.config_file_path = None
self.create_fake_config_file()
+ self.addCleanup(os.remove, self.config_file_path)
configuration = mock.Mock()
configuration.cinder_emc_config_file = self.config_file_path
self.data.failed_extend_vol,
'10')
- def _cleanup(self):
- bExists = os.path.exists(self.config_file_path)
- if bExists:
- os.remove(self.config_file_path)
- shutil.rmtree(self.tempdir)
-
- def tearDown(self):
- self._cleanup()
- super(EMCSMISISCSIDriverTestCase, self).tearDown()
-
class EMCSMISFCDriverTestCase(test.TestCase):
def setUp(self):
super(HUSiSCSIDriverTest, self).setUp()
(handle, self.config_file) = tempfile.mkstemp('.xml')
+ self.addCleanup(os.remove, self.config_file)
os.write(handle, CONF)
os.close(handle)
SimulatedHusBackend.alloc_lun = []
self.configuration = mox.MockObject(conf.Configuration)
self.configuration.hds_cinder_config_file = self.config_file
self.driver = hds.HUSDriver(configuration=self.configuration)
-
- def tearDown(self):
- os.remove(self.config_file)
- self.mox.UnsetStubs()
- super(HUSiSCSIDriverTest, self).tearDown()
+ self.addCleanup(self.mox.UnsetStubs)
def test_get_volume_stats(self):
stats = self.driver.get_volume_stats(True)
self.fake_verify_backing_lun)
self.driver = driver.ISCSIDriver()
self.flags(iscsi_target_prefix='iqn.2011-09.org.foo.bar:')
+ self.persist_tempdir = tempfile.mkdtemp()
+ self.addCleanup(self._cleanup, self.persist_tempdir)
def fake_verify_backing_lun(obj, iqn, tid):
return True
self.run_commands()
self.verify()
+ def _cleanup(self, persist_tempdir):
+ try:
+ shutil.rmtree(persist_tempdir)
+ except OSError:
+ pass
+
class TgtAdmTestCase(test.TestCase, TargetAdminTestCase):
def setUp(self):
super(TgtAdmTestCase, self).setUp()
TargetAdminTestCase.setUp(self)
- self.persist_tempdir = tempfile.mkdtemp()
self.flags(iscsi_helper='tgtadm')
self.flags(volumes_dir=self.persist_tempdir)
self.script_template = "\n".join([
'--delete %(target_name)s',
'tgtadm --lld iscsi --op show --mode target'])
- def tearDown(self):
- try:
- shutil.rmtree(self.persist_tempdir)
- except OSError:
- pass
- super(TgtAdmTestCase, self).tearDown()
-
class IetAdmTestCase(test.TestCase, TargetAdminTestCase):
def setUp(self):
super(LioAdmTestCase, self).setUp()
TargetAdminTestCase.setUp(self)
- self.persist_tempdir = tempfile.mkdtemp()
self.flags(iscsi_helper='lioadm')
self.script_template = "\n".join([
'cinder-rtstool create '
def setUp(self):
super(UsageInfoTestCase, self).setUp()
+ self.addCleanup(fake_notifier.reset)
self.flags(host='fake', notification_driver=["test"])
self.volume = importutils.import_object(CONF.volume_manager)
self.user_id = 'fake'
self.volume_size = 0
self.context = context.RequestContext(self.user_id, self.project_id)
- def tearDown(self):
- super(UsageInfoTestCase, self).tearDown()
- fake_notifier.reset()
-
def _create_volume(self, params={}):
"""Create a test volume."""
vol = {}