usr/src/lib/install_engine/test/engine_test_utils.py
changeset 1717 10cb4d15a248
parent 1202 4b52b212aa41
child 1737 c20116627c69
--- a/usr/src/lib/install_engine/test/engine_test_utils.py	Tue Jun 19 02:42:18 2012 -0600
+++ b/usr/src/lib/install_engine/test/engine_test_utils.py	Tue Jun 19 12:18:37 2012 -0600
@@ -22,16 +22,17 @@
 #
 
 #
-# Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
 #
 
 '''Some convenience functions that can be used by other test suites that use
    the engine in their testing
 '''
 
+import logging
 import os
-import logging
 import shutil
+import tempfile
 import solaris_install.engine as engine
 
 from solaris_install.logger import InstallLogger
@@ -39,16 +40,20 @@
 DEBUG_ENGINE = (os.environ.get("DEBUG_ENGINE", "false").lower() == "true")
 
 
-def get_new_engine_instance(doc_in_tmp=True):
+def get_new_engine_instance(doc_in_tmp=True, default_log=None):
     '''Returns a new install engine instance.  If an existing instance exists,
        it will be cleaned up.
     '''
 
     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
 
-    new_engine = engine.InstallEngine()
+    new_engine = engine.InstallEngine(default_log)
 
     new_engine.debug = DEBUG_ENGINE
 
@@ -62,8 +67,7 @@
 
 
 def reset_engine(old_engine=None):
-
-    ''' Clean up the engine for the tests ''' 
+    ''' Clean up the engine for the tests '''
 
     try:
         if old_engine is None:
@@ -79,6 +83,12 @@
 
     engine.InstallEngine._instance = None
 
+    try:
+        shutil.rmtree(os.path.dirname(
+                      InstallLogger.DEFAULTFILEHANDLER.baseFilename))
+    except:
+        pass
+
     logging.Logger.manager.loggerDict = {}
 
     InstallLogger.DEFAULTFILEHANDLER = None