7178513 slim_source unit tests can hose /system/volatile
authorGinnie Wray<virginia.wray@oracle.com>
Fri, 29 Jun 2012 00:42:35 -0600
changeset 1737 c20116627c69
parent 1736 f46c1e74f99e
child 1738 ad410601d71a
7178513 slim_source unit tests can hose /system/volatile
usr/src/cmd/auto-install/test/test_auto_install_manifest.py
usr/src/cmd/text-install/test/test_disk_select.py
usr/src/lib/install_doc/data_object/__init__.py
usr/src/lib/install_engine/test/engine_test_utils.py
usr/src/lib/install_logging_pymod/test/test_logger.py
usr/src/tools/tests/tests.nose
--- a/usr/src/cmd/auto-install/test/test_auto_install_manifest.py	Fri Jun 29 10:15:59 2012 -0700
+++ b/usr/src/cmd/auto-install/test/test_auto_install_manifest.py	Fri Jun 29 00:42:35 2012 -0600
@@ -21,7 +21,7 @@
 #
 
 #
-# Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
 #
 '''
 Tests auto install to a specified XML Manifest
@@ -51,14 +51,7 @@
         Clean Up
         '''
         if self.AI is not None:
-            # Reset the Engine for next test
-            if self.AI.engine is not None:
-                reset_engine(self.AI.engine)
-
-            # Remove install log as test has succeeded
-            if os.path.isfile(self.AI.INSTALL_LOG):
-                os.remove(self.AI.INSTALL_LOG)
-
+            reset_engine()
             self.AI = None
 
     def test_manifest_install_auto_reboot_true(self):
--- a/usr/src/cmd/text-install/test/test_disk_select.py	Fri Jun 29 10:15:59 2012 -0700
+++ b/usr/src/cmd/text-install/test/test_disk_select.py	Fri Jun 29 00:42:35 2012 -0600
@@ -19,7 +19,7 @@
 #
 # CDDL HEADER END
 #
-# Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
 #
 
 '''
@@ -47,7 +47,7 @@
 import terminalui
 from terminalui.base_screen import BaseScreen
 from solaris_install.engine.test.engine_test_utils import \
-    get_new_engine_instance
+    get_new_engine_instance, reset_engine
 from solaris_install.target.size import Size
 
 terminalui.init_logging("test")
@@ -56,17 +56,17 @@
 
 class MockCenterWin(object):
     '''Mocks an InnerWindow as used by a MainWindow'''
-    
+
     def add_paragraph(self, *args, **kwargs):
         pass
 
 
 class MockAll(object):
     '''Generic Mock object that 'never' raises an AttributeError'''
-    
+
     def __getattr__(self, name):
         return self
-    
+
     def __call__(self, *args, **kwargs):
         return None
 
@@ -80,31 +80,34 @@
 
 class DiskSelectTest(unittest.TestCase):
     '''Test the DiskScreen'''
-    
+
     def setUp(self):
         self.engine = get_new_engine_instance()
         self.screen = disk_selection.DiskScreen(MockAll(), MockTC())
         self.screen.disk_win = MockAll()
-    
+
+    def tearDown(self):
+        reset_engine()
+
     def test_size_line(self):
         '''Ensure that DiskScreen._size_line is created and is a string after
         calling get_size_line. Also verify that subsequent calls do not modify
         the _size_line
-        
+
         '''
         self.assertTrue(self.screen._size_line is None)
         self.screen.get_size_line()
         self.assertTrue(isinstance(self.screen._size_line, basestring))
-        
+
         obj = object()
         self.screen._size_line = obj
         self.screen.get_size_line()
         self.assertTrue(obj is self.screen._size_line)
-    
+
     def test_determine_size_data(self):
         '''Ensure that recommended_size and minimum_size are accessible after
         a call to determine_size_data(), and that they are numbers'''
-        
+
         self.assertTrue(self.screen._recommended_size is None)
         self.assertTrue(self.screen._minimum_size is None)
         self.screen.determine_size_data()
--- a/usr/src/lib/install_doc/data_object/__init__.py	Fri Jun 29 10:15:59 2012 -0700
+++ b/usr/src/lib/install_doc/data_object/__init__.py	Fri Jun 29 00:42:35 2012 -0600
@@ -121,10 +121,14 @@
         self.logger property if it's an object instance.
         '''
         if cls._DataObjectBase__logger is None:
-            cls._DataObjectBase__logger = \
-                 logging.getLogger(INSTALL_LOGGER_NAME)
+            cls._DataObjectBase__logger = logging.getLogger(
+	        INSTALL_LOGGER_NAME)
         return cls._DataObjectBase__logger
 
+    @classmethod
+    def reset_logger(cls):
+        cls._DataObjectBase__logger = None
+
     @property
     def logger(self):
         '''Instance accessor for the logger.
@@ -1069,7 +1073,7 @@
                 deleted_children = True
 
         if not deleted_children and not_found_is_err:
-            raise ObjectNotFoundError(\
+            raise ObjectNotFoundError(
                 "No matching objects found: name = '%s' "
                 "and class_type = %s" %
                 (str(name), str(class_type)))
--- a/usr/src/lib/install_engine/test/engine_test_utils.py	Fri Jun 29 10:15:59 2012 -0700
+++ b/usr/src/lib/install_engine/test/engine_test_utils.py	Fri Jun 29 00:42:35 2012 -0600
@@ -28,7 +28,6 @@
 '''Some convenience functions that can be used by other test suites that use
    the engine in their testing
 '''
-
 import logging
 import os
 import shutil
@@ -36,9 +35,15 @@
 import solaris_install.engine as engine
 
 from solaris_install.logger import InstallLogger
+from solaris_install.data_object import DataObjectBase
 
 DEBUG_ENGINE = (os.environ.get("DEBUG_ENGINE", "false").lower() == "true")
 
+TMP_DIR = "/tmp"
+TMP_PREFIX = "logging_"
+LOGFILE = "install_log"
+DEFAULT_LOG_PREFIX = TMP_DIR + "/" + TMP_PREFIX
+
 
 def get_new_engine_instance(doc_in_tmp=True, default_log=None):
     '''Returns a new install engine instance.  If an existing instance exists,
@@ -48,10 +53,8 @@
     reset_engine()
 
     if not default_log:
-        default_log_dir = tempfile.mkdtemp(dir="/tmp", prefix="logging_")
-        default_log = default_log_dir + "/install_log"
-
-    engine.InstallEngine._instance = None
+        default_log_dir = tempfile.mkdtemp(dir=TMP_DIR, prefix=TMP_PREFIX)
+        default_log = default_log_dir + "/" + LOGFILE
 
     new_engine = engine.InstallEngine(default_log)
 
@@ -81,11 +84,22 @@
     except:
         pass
 
+    # Reset the DOC logger to None
+    DataObjectBase.reset_logger()
+
     engine.InstallEngine._instance = None
 
+    # Make sure that the log file assigned to the logger uses the same
+    # tempfile directory prefix. If not, only remove the log file and
+    # not the directory that contains it.
     try:
-        shutil.rmtree(os.path.dirname(
-                      InstallLogger.DEFAULTFILEHANDLER.baseFilename))
+        if InstallLogger.DEFAULTFILEHANDLER.baseFilename.startswith(
+            DEFAULT_LOG_PREFIX):
+            shutil.rmtree(os.path.dirname(
+                InstallLogger.DEFAULTFILEHANDLER.baseFilename))
+        else:
+            if os.path.isfile(InstallLogger.DEFAULTFILEHANDLER.baseFilename):
+                os.remove(InstallLogger.DEFAULTFILEHANDLER.baseFilename)
     except:
         pass
 
--- a/usr/src/lib/install_logging_pymod/test/test_logger.py	Fri Jun 29 10:15:59 2012 -0700
+++ b/usr/src/lib/install_logging_pymod/test/test_logger.py	Fri Jun 29 00:42:35 2012 -0600
@@ -146,6 +146,12 @@
         logging.setLoggerClass(logging.Logger)
         logging._defaultFormatter = logging.Formatter()
 
+        try:
+            shutil.rmtree(self.log_tmp_dir)
+        except:
+            # File doesn't exist
+            pass
+
     def test_no_default_logfile(self):
         '''Test that the logger does not fail with no default log'''
         logging.setLoggerClass(InstallLogger)
@@ -158,7 +164,6 @@
         LOGGER = InstallLogger.manager.getLogger(INSTALL_LOGGER_NAME)
         self.log_tmp_dir = tempfile.mkdtemp(dir="/tmp", prefix="logging_")
         self.logfile = os.path.join(self.log_tmp_dir, TEST_LOG)
-
         fh = logging.FileHandler(self.logfile)
         LOGGER.addHandler(fh)
         LOGGER.info('This is from the logger')
@@ -177,12 +182,13 @@
         self.log_tmp_dir = tempfile.mkdtemp(dir="/tmp", prefix="logging_")
         self.logfile = os.path.join(self.log_tmp_dir, TEST_LOG)
         self.pid = str(os.getpid())
-        self.eng = get_new_engine_instance(default_log=self.logfile)
+        self.eng = TestInstallEngine(self.logfile)
         self.test_logger = logging.getLogger(INSTALL_LOGGER_NAME)
         self.list = []
 
     def tearDown(self):
         self.eng = None
+        TestInstallEngine._instance = None
         InstallLogger.DEFAULTFILEHANDLER = None
         logging.Logger.manager.loggerDict = {}
         logging.setLoggerClass(logging.Logger)
--- a/usr/src/tools/tests/tests.nose	Fri Jun 29 10:15:59 2012 -0700
+++ b/usr/src/tools/tests/tests.nose	Fri Jun 29 00:42:35 2012 -0600
@@ -30,4 +30,4 @@
 # the files in that directory should begin with "test_". Files
 # containing in-line doc-tests should be added explicitly.
 
-tests=lib/install_common/test/,lib/liberrsvc_pymod/test/,cmd/ai-webserver/test/,cmd/text-install/test/,cmd/installadm/test/,cmd/installadm/installadm_common.py,lib/install_utils/test/,lib/install_logging_pymod/test,lib/install_doc/test,lib/install_engine/test,lib/install_manifest/test/,lib/install_transfer/test,cmd/distro_const/checkpoints/test,cmd/js2ai/modules/test,lib/terminalui/test,cmd/system-config/profile/test/,cmd/system-config/test/,lib/install_manifest_input/test,lib/install_target/test/,lib/install_ict/test,lib/install_boot/test,lib/netif/test
+tests=lib/install_common/test/,lib/liberrsvc_pymod/test/,cmd/ai-webserver/test/,cmd/text-install/test/,cmd/installadm/test/,cmd/installadm/installadm_common.py,lib/install_utils/test/,lib/install_logging_pymod/test,lib/install_doc/test,lib/install_engine/test,lib/install_manifest/test/,lib/install_transfer/test,cmd/distro_const/checkpoints/test,cmd/js2ai/modules/test,lib/terminalui/test,cmd/system-config/profile/test/,cmd/system-config/test/,cmd/auto-install/test,lib/install_manifest_input/test,lib/install_target/test/,lib/install_ict/test,lib/install_boot/test,lib/netif/test/