Enhance the log isolation among multiple sessions

Change-Id: Ib9355c4f7599aa7d6e28f2c3cb3c1db4d237a4d5
This commit is contained in:
Yichen Wang 2015-12-04 11:10:08 -08:00
parent 9d09061d96
commit 5393e5928c
3 changed files with 15 additions and 24 deletions

View File

@ -92,21 +92,6 @@ class ConfigController(object):
def hypervisor_list(self, *args):
session_id = args[0]
kb_session = KBSessionManager.get(session_id)
kb_config = kb_session.kb_config
if not kb_session.kloudbuster:
try:
kb_session.kloudbuster = KloudBuster(
kb_config.cred_tested, kb_config.cred_testing,
kb_config.server_cfg, kb_config.client_cfg,
kb_config.topo_cfg, kb_config.tenants_list)
except Exception:
LOG.warn(traceback.format_exc())
kb_session.kb_status = 'ERROR'
response.status = 400
response.text = u"Cannot get the hypervisor list."
return response.text
kloudbuster = kb_session.kloudbuster
ret_dict = {}
ret_dict['server'] = kloudbuster.get_hypervisor_list(kloudbuster.server_cred)
@ -165,13 +150,26 @@ class ConfigController(object):
response.text = u"Error while parsing configurations: \n%s" % (traceback.format_exc())
return response.text
logging.setup("kloudbuster", logfile="/tmp/kb_log_%s" % session_id)
logfile_name = "/tmp/kb_log_%s" % session_id
logging.setup("kloudbuster", logfile=logfile_name)
kb_config.init_with_rest_api(cred_tested=cred_tested,
cred_testing=cred_testing)
self.fix_config(kb_config, user_config)
kb_session = KBSession()
kb_session.kb_config = kb_config
try:
kb_session.kloudbuster = KloudBuster(
kb_config.cred_tested, kb_config.cred_testing,
kb_config.server_cfg, kb_config.client_cfg,
kb_config.topo_cfg, kb_config.tenants_list)
kb_session.kloudbuster.fp_logfile = open(logfile_name)
except Exception:
LOG.warn(traceback.format_exc())
kb_session.kb_status = 'ERROR'
response.status = 400
response.text = u"Cannot initialize KloudBuster instance."
return response.text
KBSessionManager.add(session_id, kb_session)
response.status = 201

View File

@ -24,7 +24,6 @@ sys.path.append(kb_main_path)
from kb_session import KBSessionManager
from kloudbuster import __version__ as kb_version
from kloudbuster import KloudBuster
from pecan import expose
from pecan import response
@ -55,13 +54,7 @@ class KBController(object):
def kb_stage_thread_handler(self, session_id):
kb_session = KBSessionManager.get(session_id)
kb_session.kb_status = 'STAGING'
kb_config = kb_session.kb_config
try:
if not kb_session.kloudbuster:
kb_session.kloudbuster = KloudBuster(
kb_config.cred_tested, kb_config.cred_testing,
kb_config.server_cfg, kb_config.client_cfg,
kb_config.topo_cfg, kb_config.tenants_list)
if kb_session.kloudbuster.check_and_upload_images():
kb_session.sync_cfg(["server_cfg", "client_cfg", "topo_cfg", "tenants_list"])
kb_session.kloudbuster.stage()

View File

@ -497,7 +497,7 @@ class KloudBuster(object):
def dump_logs(self, offset=0):
if not self.fp_logfile:
self.fp_logfile = open(CONF.log_file)
return ""
self.fp_logfile.seek(offset)
return self.fp_logfile.read()