]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Use tempfile and cleanup in windows unit test
authorJohn Griffith <john.griffith@solidfire.com>
Tue, 3 Sep 2013 22:33:24 +0000 (22:33 +0000)
committerJohn Griffith <john.griffith@solidfire.com>
Tue, 3 Sep 2013 22:43:06 +0000 (22:43 +0000)
The unit test test_windows was setting and creating
a directory c://iSCSIVirtualDisks in the root path
and even worse wasn't deleting it on cleanup.

This patch converts that to use tempfile and also
adds an shutil.rmtree to the teardown method to clean
up all the junk it creates.

Fixes bug: 1219950

Change-Id: Ibd071c9c3ae9a02f26c85a09e8bc6619d8c73a37

cinder/tests/test_windows.py

index af969739547d5bd02fefd686bf5aa89c6956b11e..deca44bff77a41ed2c487844f672a07e315b660e 100644 (file)
@@ -21,6 +21,8 @@ Unit tests for Windows Server 2012 OpenStack Cinder volume driver
 
 
 import os
+import shutil
+import tempfile
 
 from oslo.config import cfg
 
@@ -47,11 +49,12 @@ class TestWindowsDriver(test.TestCase):
         super(TestWindowsDriver, self).__init__(method)
 
     def setUp(self):
+        self.lun_path_tempdir = tempfile.mkdtemp()
         super(TestWindowsDriver, self).setUp()
         self._mox = mox_lib.Mox()
         self.stubs = stubout.StubOutForTesting()
         self.flags(
-            windows_iscsi_lun_path='C:\iSCSIVirtualDisks',
+            windows_iscsi_lun_path=self.lun_path_tempdir,
         )
         self._setup_stubs()
         configuration = conf.Configuration(None)
@@ -63,6 +66,7 @@ class TestWindowsDriver(test.TestCase):
     def tearDown(self):
         self._mox.UnsetStubs()
         self.stubs.UnsetAll()
+        shutil.rmtree(self.lun_path_tempdir)
         super(TestWindowsDriver, self).tearDown()
 
     def _setup_stubs(self):