本文整理汇总了Python中commodule.log.LOGGER类的典型用法代码示例。如果您正苦于以下问题:Python LOGGER类的具体用法?Python LOGGER怎么用?Python LOGGER使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LOGGER类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __run_webapi_test
def __run_webapi_test(self, latest_dir):
""" run webAPI test"""
if self.bdryrun:
LOGGER.info("[ WRTLauncher mode does not support dryrun ]")
return True
list_auto = []
list_manual = []
for i in self.exe_sequence:
if i[-4::1] == "auto":
list_auto.append(i)
if i[-6::1] == "manual":
list_manual.append(i)
list_auto.sort()
list_manual.sort()
self.exe_sequence = []
self.exe_sequence.extend(list_auto)
self.exe_sequence.extend(list_manual)
for webapi_total_file in self.exe_sequence:
for webapi_file in self.testsuite_dict[webapi_total_file]:
# print identical xml file name
if self.current_test_xml != JOIN(latest_dir, webapi_total_file):
time.sleep(3)
LOGGER.info("\n[ testing xml: %s.xml ]\n"
% JOIN(latest_dir, webapi_total_file))
self.current_test_xml = JOIN(latest_dir, webapi_total_file)
self.__run_with_commodule(webapi_file)
示例2: __run_with_commodule
def __run_with_commodule(self, webapi_file):
"""run_with_commodule,Initialization,check status,get result"""
try:
# prepare test set list
test_xml_set_list = self.__split_xml_to_set(webapi_file)
# create temporary parameter
for test_xml_set in test_xml_set_list:
LOGGER.info("\n[ run set: %s ]" % test_xml_set)
# prepare the test JSON
self.__prepare_external_test_json(test_xml_set)
# init test here
init_status = self.__init_com_module(test_xml_set)
if not init_status:
continue
# send set JSON Data to com_module
self.testworker.run_test(
self.session_id, self.set_parameters)
while True:
time.sleep(1)
# check the test status ,if the set finished,get
# the set_result,and finalize_test
if self.__check_test_status():
set_result = self.testworker.get_test_result(
self.session_id)
# write_result to set_xml
self.__write_set_result(
test_xml_set, set_result)
# shut down server
self.finalize_test(self.session_id)
break
except IOError as error:
LOGGER.error(
"[ Error: fail to run webapi test xml, error: %s ]" % error)
示例3: killall
def killall(ppid):
"""Kill all children process by parent process ID"""
sys_platform = platform.system()
try:
if sys_platform == "Linux":
ppid = str(ppid)
pidgrp = []
def getchildpids(ppid):
"""Return a list of children process"""
command = "ps -ef | awk '{if ($3 == %s) print $2;}'" % str(ppid)
pids = os.popen(command).read()
pids = pids.split()
return pids
pidgrp.extend(getchildpids(ppid))
for pid in pidgrp:
pidgrp.extend(getchildpids(pid))
# Insert self process ID to PID group list
pidgrp.insert(0, ppid)
while len(pidgrp) > 0:
pid = pidgrp.pop()
try:
os.kill(int(pid), signal.SIGKILL)
except OSError, error:
pattern = re.compile('No such process')
match = pattern.search(str(error))
if not match:
LOGGER.info(
"[ Error: fail to kill pid: %s, error: %s ]\n" % (
int(pid), error))
# kill for windows platform
else:
示例4: run_test
def run_test(self, sessionid, test_set):
"""
process the execution for a test set
"""
if sessionid is None:
return False
if not "cases" in test_set:
return False
# start debug trace thread
dlogfile = test_set['current_set_name'].replace('.xml', '.dlog')
self.opts['dlog_file'] = dlogfile
self.conn.start_debug(dlogfile)
time.sleep(1)
self.result_obj = TestSetResut(
self.opts['testsuite_name'], self.opts['testset_name'])
cases, exetype, ctype = test_set[
"cases"], test_set["exetype"], test_set["type"]
if self.opts['test_type'] == "webapi":
return self.__run_web_test(sessionid, self.opts['testset_name'], exetype, ctype, cases)
elif self.opts['test_type'] == "coreapi":
return self.__run_core_test(sessionid, self.opts['testset_name'], exetype, cases)
elif self.opts['test_type'] == "jqunit":
return self.__run_jqt_test(sessionid, self.opts['testset_name'], cases)
else:
LOGGER.info("[ unsupported test suite type ! ]")
return False
示例5: __prepare_result_file
def __prepare_result_file(self, testxmlfile, resultfile):
""" write the test_xml content to resultfile"""
try:
parse_tree = etree.parse(testxmlfile)
suiteparent = parse_tree.getroot()
no_test_definition = 1
if parse_tree.getiterator('test_definition'):
no_test_definition = 0
if no_test_definition:
suiteparent = etree.Element('test_definition')
suiteparent.tail = "\n"
for suite in parse_tree.getiterator('suite'):
suite.tail = "\n"
suiteparent.append(suite)
self.apply_filter(suiteparent)
try:
with open(resultfile, 'w') as output:
tree = etree.ElementTree(element=suiteparent)
tree.write(output)
except IOError as error:
LOGGER.error("[ Error: create filtered result file: %s failed,\
error: %s ]" % (resultfile, error))
except IOError as error:
LOGGER.error(error)
return False
示例6: __get_test_options
def __get_test_options(self, deviceid, test_launcher, test_suite):
"""get test option dict """
test_opt = {}
test_opt["suite_name"] = test_suite
cmd = ""
if test_launcher.find("WRTLauncher") != -1:
test_opt["launcher"] = "wrt-launcher"
# test suite need to be installed by commodule
if self.__test_auto_iu:
test_wgt = self.__test_wgt
cmd = WRT_INSTALL_STR % (deviceid, test_suite, test_wgt)
exit_code, ret = shell_command(cmd)
else:
test_wgt = test_suite
# query the whether test widget is installed ok
cmd = WRT_QUERY_STR % (deviceid, test_wgt)
exit_code, ret = shell_command(cmd)
if len(ret) == 0:
LOGGER.info('[ test widget "%s" not installed in target ]' % test_wgt)
return None
else:
test_opt["suite_id"] = ret[0].strip("\r\n")
self.__test_wgt = test_opt["suite_id"]
else:
test_opt["launcher"] = test_launcher
return test_opt
示例7: prepare_run
def prepare_run(self, testxmlfile, resultdir=None):
"""
testxmlfile: target testxml file
execdir and resultdir: should be the absolute path since TRunner
is the common lib
"""
# resultdir is set to current directory by default
if not resultdir:
resultdir = os.getcwd()
ok_prepare = True
if ok_prepare:
try:
filename = testxmlfile
filename = os.path.splitext(filename)[0]
if platform.system() == "Linux":
filename = filename.split('/')[-2]
else:
filename = filename.split('\\')[-2]
if self.filter_rules["execution_type"] == ["manual"]:
resultfile = "%s.manual.xml" % filename
else:
resultfile = "%s.auto.xml" % filename
resultfile = JOIN(resultdir, resultfile)
if not EXISTS(resultdir):
os.mkdir(resultdir)
LOGGER.info("[ analysis test xml file: %s ]" % resultfile)
self.__prepare_result_file(testxmlfile, resultfile)
self.__split_test_xml(resultfile, resultdir)
except IOError as error:
LOGGER.error(error)
ok_prepare &= False
return ok_prepare
示例8: finalize_test
def finalize_test(self, sessionid):
'''shut_down testkit-stub'''
try:
self.testworker.finalize_test(sessionid)
except Exception as error:
LOGGER.error("[ Error: fail to close webapi http server, "
"error: %s ]" % error)
示例9: __prepare_starup_parameters
def __prepare_starup_parameters(self, testxml):
""" prepare_starup_parameters """
starup_parameters = {}
LOGGER.info("[ prepare_starup_parameters ]")
try:
parse_tree = etree.parse(testxml)
tsuite = parse_tree.getroot().getiterator('suite')[0]
tset = parse_tree.getroot().getiterator('set')[0]
if tset.get("launcher") is not None:
starup_parameters['test-launcher'] = tset.get("launcher")
else:
starup_parameters['test-launcher'] = tsuite.get("launcher")
starup_parameters['testsuite-name'] = tsuite.get("name")
starup_parameters['testset-name'] = tset.get("name")
starup_parameters['stub-name'] = self.stub_name
if self.external_test is not None:
starup_parameters['external-test'] = self.external_test
starup_parameters['debug'] = self.debug
starup_parameters['test_prefix'] = self.test_prefix
if self.rerun:
starup_parameters['rerun'] = self.rerun
if len(self.capabilities) > 0:
starup_parameters['capability'] = self.capabilities
except IOError as error:
LOGGER.error(
"[ Error: prepare starup parameters, error: %s ]" % error)
return starup_parameters
示例10: _upload_file
def _upload_file(deviceid, remote_path, local_path):
"""upload file to device"""
cmd = "sdb -s %s push %s %s" % (deviceid, local_path, remote_path)
exit_code, result = shell_command(cmd)
if exit_code != 0:
LOGGER.info('[ Upload file "%s" failed,' " get error: %s ]" % (local_path, result))
return False
else:
return True
示例11: _download_file
def _download_file(deviceid, remote_path, local_path):
"""download file from device"""
cmd = "sdb -s %s pull %s %s" % (deviceid, remote_path, local_path)
exit_code, ret = shell_command(cmd)
if exit_code != 0:
LOGGER.info('[ Download file "%s" from target failed, error: %s ]' % (remote_path, ret[0].strip("\r\n")))
return False
else:
return True
示例12: download_file
def download_file(self, remote_path, local_path):
"""download file from device"""
cmd = "adb -s %s pull %s %s" % (self.deviceid, remote_path, local_path)
exit_code, ret = shell_command(cmd)
if exit_code != 0:
error = ret[0].strip('\r\n') if len(ret) else "sdb shell timeout"
LOGGER.info("[ Download file \"%s\" failed, error: %s ]"
% (remote_path, error))
return False
else:
return True
示例13: upload_file
def upload_file(self, remote_path, local_path):
"""upload file to device"""
cmd = "sdb -s %s push %s %s" % (self.deviceid, local_path, remote_path)
exit_code, ret = shell_command(cmd)
if exit_code != 0:
error = ret[0].strip('\r\n') if len(ret) else "sdb shell timeout"
LOGGER.info("[ Upload file \"%s\" failed,"
" get error: %s ]" % (local_path, error))
return False
else:
return True
示例14: get_test_result
def get_test_result(self, sessionid):
"""get the test result for a test set """
result = {}
if sessionid is None:
return result
try:
global TEST_SERVER_RESULT
LOCK_OBJ.acquire()
result = TEST_SERVER_RESULT
LOCK_OBJ.release()
except OSError, error:
LOGGER.error("[ Error: failed to get test result, error:%s ]\n" % error)
示例15: write_json_result
def write_json_result(set_result_xml, set_result):
''' fetch result form JSON'''
case_results = set_result["cases"]
try:
parse_tree = etree.parse(set_result_xml)
root_em = parse_tree.getroot()
dubug_file = os.path.basename(set_result_xml)
dubug_file = os.path.splitext(dubug_file)[0] + '.dlog'
for tset in root_em.getiterator('set'):
tset.set("set_debug_msg", dubug_file)
for tcase in tset.getiterator('testcase'):
for case_result in case_results:
if tcase.get("id") == case_result['case_id']:
tcase.set('result', case_result['result'].upper())
# Check performance test
if tcase.find('measurement') is not None:
for measurement in tcase.getiterator(
'measurement'):
if 'measures' in case_result:
m_results = case_result['measures']
for m_result in m_results:
if measurement.get('name') == \
m_result['name'] and 'value' in m_result:
measurement.set(
'value', m_result[
'value'])
if tcase.find("./result_info") is not None:
tcase.remove(tcase.find("./result_info"))
result_info = etree.SubElement(tcase, "result_info")
actual_result = etree.SubElement(
result_info, "actual_result")
actual_result.text = case_result['result'].upper()
start = etree.SubElement(result_info, "start")
end = etree.SubElement(result_info, "end")
stdout = etree.SubElement(result_info, "stdout")
stderr = etree.SubElement(result_info, "stderr")
if 'start_at' in case_result:
start.text = case_result['start_at']
if 'end_at' in case_result:
end.text = case_result['end_at']
if 'stdout' in case_result:
stdout.text = str2xmlstr(case_result['stdout'])
if 'stderr' in case_result:
stderr.text = str2xmlstr(case_result['stderr'])
parse_tree.write(set_result_xml)
LOGGER.info("[ cases result saved to resultfile ]\n")
except IOError as error:
traceback.print_exc()
LOGGER.error(
"[ Error: fail to write cases result, error: %s ]\n" % error)