26 # |
26 # |
27 |
27 |
28 '''Some convenience functions that can be used by other test suites that use |
28 '''Some convenience functions that can be used by other test suites that use |
29 the engine in their testing |
29 the engine in their testing |
30 ''' |
30 ''' |
31 |
|
32 import logging |
31 import logging |
33 import os |
32 import os |
34 import shutil |
33 import shutil |
35 import tempfile |
34 import tempfile |
36 import solaris_install.engine as engine |
35 import solaris_install.engine as engine |
37 |
36 |
38 from solaris_install.logger import InstallLogger |
37 from solaris_install.logger import InstallLogger |
|
38 from solaris_install.data_object import DataObjectBase |
39 |
39 |
40 DEBUG_ENGINE = (os.environ.get("DEBUG_ENGINE", "false").lower() == "true") |
40 DEBUG_ENGINE = (os.environ.get("DEBUG_ENGINE", "false").lower() == "true") |
|
41 |
|
42 TMP_DIR = "/tmp" |
|
43 TMP_PREFIX = "logging_" |
|
44 LOGFILE = "install_log" |
|
45 DEFAULT_LOG_PREFIX = TMP_DIR + "/" + TMP_PREFIX |
41 |
46 |
42 |
47 |
43 def get_new_engine_instance(doc_in_tmp=True, default_log=None): |
48 def get_new_engine_instance(doc_in_tmp=True, default_log=None): |
44 '''Returns a new install engine instance. If an existing instance exists, |
49 '''Returns a new install engine instance. If an existing instance exists, |
45 it will be cleaned up. |
50 it will be cleaned up. |
46 ''' |
51 ''' |
47 |
52 |
48 reset_engine() |
53 reset_engine() |
49 |
54 |
50 if not default_log: |
55 if not default_log: |
51 default_log_dir = tempfile.mkdtemp(dir="/tmp", prefix="logging_") |
56 default_log_dir = tempfile.mkdtemp(dir=TMP_DIR, prefix=TMP_PREFIX) |
52 default_log = default_log_dir + "/install_log" |
57 default_log = default_log_dir + "/" + LOGFILE |
53 |
|
54 engine.InstallEngine._instance = None |
|
55 |
58 |
56 new_engine = engine.InstallEngine(default_log) |
59 new_engine = engine.InstallEngine(default_log) |
57 |
60 |
58 new_engine.debug = DEBUG_ENGINE |
61 new_engine.debug = DEBUG_ENGINE |
59 |
62 |
79 shutil.rmtree(old_engine._tmp_cache_path, ignore_errors=True) |
82 shutil.rmtree(old_engine._tmp_cache_path, ignore_errors=True) |
80 old_engine._tmp_cache_path = None |
83 old_engine._tmp_cache_path = None |
81 except: |
84 except: |
82 pass |
85 pass |
83 |
86 |
|
87 # Reset the DOC logger to None |
|
88 DataObjectBase.reset_logger() |
|
89 |
84 engine.InstallEngine._instance = None |
90 engine.InstallEngine._instance = None |
85 |
91 |
|
92 # Make sure that the log file assigned to the logger uses the same |
|
93 # tempfile directory prefix. If not, only remove the log file and |
|
94 # not the directory that contains it. |
86 try: |
95 try: |
87 shutil.rmtree(os.path.dirname( |
96 if InstallLogger.DEFAULTFILEHANDLER.baseFilename.startswith( |
88 InstallLogger.DEFAULTFILEHANDLER.baseFilename)) |
97 DEFAULT_LOG_PREFIX): |
|
98 shutil.rmtree(os.path.dirname( |
|
99 InstallLogger.DEFAULTFILEHANDLER.baseFilename)) |
|
100 else: |
|
101 if os.path.isfile(InstallLogger.DEFAULTFILEHANDLER.baseFilename): |
|
102 os.remove(InstallLogger.DEFAULTFILEHANDLER.baseFilename) |
89 except: |
103 except: |
90 pass |
104 pass |
91 |
105 |
92 logging.Logger.manager.loggerDict = {} |
106 logging.Logger.manager.loggerDict = {} |
93 |
107 |