Commit 75b02b2a authored by Sebastien Robin's avatar Sebastien Robin

testnode was still sometimes logging at several files at a time

parent 3f126710
......@@ -454,16 +454,13 @@ branch = foo
original_runTestSuite = test_node.runTestSuite
test_node.runTestSuite = doNothing
SlapOSControler.initializeSlapOSControler = doNothing
try:
test_node.run()
except Exception as e:
self.assertEqual(type(e),StopIteration)
finally:
time.sleep = original_sleep
TaskDistributor.startTestSuite = original_startTestSuite
TaskDistributionTool.createTestResult = original_createTestResult
test_node._prepareSlapOS = original_prepareSlapOS
test_node.runTestSuite = original_runTestSuite
test_node.run()
self.assertEquals(5, counter)
time.sleep = original_sleep
TaskDistributor.startTestSuite = original_startTestSuite
TaskDistributionTool.createTestResult = original_createTestResult
test_node._prepareSlapOS = original_prepareSlapOS
test_node.runTestSuite = original_runTestSuite
def test_12_spawn(self):
def _checkCorrectStatus(expected_status,*args):
......@@ -512,12 +509,11 @@ branch = foo
counter = 0
def patch_startTestSuite(self,test_node_title):
global counter
config_list = []
if counter == 0:
config_list.append(test_self.getTestSuiteData(reference='aa')[0])
if counter == 1:
config_list.append(test_self.getTestSuiteData(reference='bb')[0])
elif counter == 2:
config_list = [test_self.getTestSuiteData(reference='aa')[0],
test_self.getTestSuiteData(reference='bb')[0]]
if counter in (1, 2):
config_list.reverse()
elif counter == 3:
raise StopIteration
counter += 1
return json.dumps(config_list)
......@@ -530,9 +526,10 @@ branch = foo
def checkTestSuite(test_node):
test_node.node_test_suite_dict
rand_part_set = set()
self.assertEquals(2, len(test_node.node_test_suite_dict))
assert(test_node.suite_log is not None)
assert(isinstance(test_node.suite_log, types.MethodType))
for ref, suite in test_node.node_test_suite_dict.items():
assert(suite.suite_log is not None)
assert(isinstance(suite.suite_log, types.MethodType))
self.assertTrue('var/log/testnode/%s' % suite.reference in \
suite.suite_log_path,
"Incorrect suite log path : %r" % suite.suite_log_path)
......@@ -542,6 +539,9 @@ branch = foo
assert(len(rand_part) == 32)
assert(rand_part not in rand_part_set)
rand_part_set.add(rand_part)
suite_log = open(suite.suite_log_path, 'r')
self.assertEquals(1, len([x for x in suite_log.readlines() \
if x.find("Activated logfile")>=0]))
original_sleep = time.sleep
time.sleep = doNothing
......@@ -556,17 +556,14 @@ branch = foo
original_runTestSuite = test_node.runTestSuite
test_node.runTestSuite = doNothing
SlapOSControler.initializeSlapOSControler = doNothing
try:
test_node.run()
except Exception as e:
checkTestSuite(test_node)
self.assertEqual(type(e),StopIteration)
finally:
time.sleep = original_sleep
TaskDistributor.startTestSuite = original_startTestSuite
TaskDistributionTool.createTestResult = original_createTestResult
test_node._prepareSlapOS = original_prepareSlapOS
test_node.runTestSuite = original_runTestSuite
test_node.run()
self.assertEquals(counter, 3)
checkTestSuite(test_node)
time.sleep = original_sleep
TaskDistributor.startTestSuite = original_startTestSuite
TaskDistributionTool.createTestResult = original_createTestResult
test_node._prepareSlapOS = original_prepareSlapOS
test_node.runTestSuite = original_runTestSuite
def test_16_cleanupLogDirectory(self):
# Make sure that we are able to cleanup old log folders
......
......@@ -89,7 +89,6 @@ class NodeTestSuite(SlapOSInstance):
def __init__(self, reference):
super(NodeTestSuite, self).__init__()
self.reference = reference
self.file_handler = None
def edit(self, **kw):
super(NodeTestSuite, self).edit(**kw)
......@@ -123,30 +122,11 @@ class NodeTestSuite(SlapOSInstance):
SlapOSControler.createFolders(suite_log_directory)
self.suite_log_path = os.path.join(suite_log_directory,
'suite.log')
self._initializeSuiteLog()
return self.getSuiteLogPath(), random_suite_folder_id
def getSuiteLogPath(self):
return getattr(self,"suite_log_path", None)
def getSuiteLog(self):
return getattr(self, "suite_log", None)
def _initializeSuiteLog(self):
# remove previous handlers
logger = logging.getLogger('testsuite')
if self.file_handler is not None:
logger.removeHandler(self.file_handler)
# and replace it with new handler
logger_format = '%(asctime)s %(name)-13s: %(levelname)-8s %(message)s'
formatter = logging.Formatter(logger_format)
logging.basicConfig(level=logging.INFO, format=logger_format)
self.file_handler = logging.FileHandler(filename=self.suite_log_path)
self.file_handler.setFormatter(formatter)
logger.addHandler(self.file_handler)
logger.info('Activated logfile %r output' % self.suite_log_path)
self.suite_log = logger.info
class TestNode(object):
def __init__(self, log, config, max_log_time=MAX_LOG_TIME,
......@@ -158,6 +138,7 @@ class TestNode(object):
self.node_test_suite_dict = {}
self.max_log_time = max_log_time
self.max_temp_time = max_temp_time
self.file_handler = None
def checkOldTestSuite(self,test_suite_data):
config = self.config
......@@ -252,20 +233,36 @@ branch = %(branch)s
Create a log dedicated for the test suite,
and register the url to master node.
"""
log_file_name, folder_id = node_test_suite.createSuiteLog()
if log_file_name is None and config.get('log_file'):
log_file_name = config['log_file']
suite_log_path, folder_id = node_test_suite.createSuiteLog()
self._initializeSuiteLog(suite_log_path)
# TODO make the path into url
test_result.reportStatus('LOG url', "%s/%s" % (self.config.get('httpd_url'),
folder_id), '')
self.log("going to switch to log %r" % log_file_name)
log = node_test_suite.getSuiteLog()
self.process_manager.log = self.log = log
return log_file_name
self.log("going to switch to log %r" % suite_log_path)
self.process_manager.log = self.log = self.getSuiteLog()
return suite_log_path
def getSuiteLog(self):
return self.suite_log
def _initializeSuiteLog(self, suite_log_path):
# remove previous handlers
logger = logging.getLogger('testsuite')
if self.file_handler is not None:
logger.removeHandler(self.file_handler)
# and replace it with new handler
logger_format = '%(asctime)s %(name)-13s: %(levelname)-8s %(message)s'
formatter = logging.Formatter(logger_format)
logging.basicConfig(level=logging.INFO, format=logger_format)
self.file_handler = logging.FileHandler(filename=suite_log_path)
self.file_handler.setFormatter(formatter)
logger.addHandler(self.file_handler)
logger.info('Activated logfile %r output' % suite_log_path)
self.suite_log = logger.info
def checkRevision(self, test_result, node_test_suite):
config = self.config
log = node_test_suite.getSuiteLog()
log = self.log
if log is None:
log = self.log
if node_test_suite.revision != test_result.revision:
......@@ -328,7 +325,7 @@ branch = %(branch)s
software_path_list=self.config.get("software_list"))
def prepareSlapOSForTestSuite(self, node_test_suite):
log = node_test_suite.getSuiteLog()
log = self.log
if log is None:
log = self.log
return self._prepareSlapOS(node_test_suite.working_directory,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment