def _iosuiauto_test_exec(test_session, cases, result_obj, session_dir): """function for running iosuiauto tests""" result_obj.set_status(0) result_list = [] for i_case in cases['cases']: i_case_timeout = i_case.get('timeout', DEFAULT_TIMEOUT) try: case_entry = i_case['entry'] expected_result = int(i_case['expected_result']) if not EXISTS(case_entry): i_case['result'] = STR_BLOCK i_case[ 'stdout'] = "[Message]No such file or dirctory: %s" % case_entry result_list.append(i_case) continue case_id = i_case['case_id'] destination = "platform=%s,name=%s" % (os.environ["IOS_PLATFORM"], os.environ["IOS_NAME"]) if os.environ.get("IOS_VERSION", None): destination = "%s,OS=%s" % (destination, os.environ["IOS_VERSION"]) device_id = os.environ["DEVICE_ID"] popen_args = 'python %s -d "%s" -u "%s"' % (case_entry, destination, device_id) i_case_proc = subprocess.Popen(args=popen_args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) i_case_pre_time = time.time() while True: output_infos = i_case_proc.communicate() i_case_exit_code = i_case_proc.returncode i_case_elapsed_time = time.time() - i_case_pre_time if i_case_exit_code == None: if i_case_elapsed_time >= i_case_timeout: tr_utils.KillAllProcesses(ppid=i_case_proc.pid) i_case['result'] = STR_BLOCK i_case['stdout'] = "[Message]Timeout" LOGGER.debug("Run %s timeout" % case_id) result_list.append(i_case) break else: if i_case_exit_code == expected_result: i_case['result'] = STR_PASS i_case[ 'stdout'] = "[Message]" + output_infos[0].replace( "\n", "\r") else: i_case['result'] = STR_FAIL i_case['stderr'] = output_infos[1].replace("\n", "\r") result_list.append(i_case) break time.sleep(1) except Exception, e: i_case['result'] = STR_BLOCK i_case['stdout'] = "[Message]%s" % e LOGGER.error("Run %s: failed: %s, exit from executer" % (case_id, e)) result_list.append(i_case)
def kill_stub(self): stub_status = False server_url = "http://%s:9000" % self.deviceip ret = http_request( get_url(server_url, "/kill_stub"), "GET", {}) if ret is None: LOGGER.error("[ ERROR: get server status timeout, please check deivce! ]") else: if ret.get("OK") is not None: stub_status = True return stub_status
def launch_stub(self, stub_app, stub_port="8000", debug_opt=""): stub_status = False server_url = "http://%s:9000" % self.deviceip ret = http_request( get_url(server_url, "/launch_stub"), "GET", {}) if ret is None: LOGGER.error("[ ERROR: get server status timeout, please check deivce! ]") else: if ret.get("OK") is not None: stub_status = True return stub_status
def kill_stub(self): stub_status = False server_url = "http://%s:9000" % self.deviceip ret = http_request(get_url(server_url, "/kill_stub"), "GET", {}) if ret is None: LOGGER.error( "[ ERROR: get server status timeout, please check deivce! ]") else: if ret.get("OK") is not None: stub_status = True return stub_status
def launch_stub(self, stub_app, stub_port="8000", debug_opt=""): stub_status = False server_url = "http://%s:9000" % self.deviceip ret = http_request(get_url(server_url, "/launch_stub"), "GET", {}) if ret is None: LOGGER.error( "[ ERROR: get server status timeout, please check deivce! ]") else: if ret.get("OK") is not None: stub_status = True return stub_status
def check_process(self, process_name): stub_status = 0 server_url = "http://%s:9000" % self.deviceip LOGGER.error("[ Server URL: %s]" % server_url) ret = http_request(get_url(server_url, "/check_stub"), "GET", {}) if ret is None: LOGGER.error( "[ ERROR: get server status timeout, please check deivce! ]") else: if ret.get("OK") is not None: stub_status = 1 return stub_status
def check_process(self, process_name): stub_status = 0 server_url = "http://%s:9000" % self.deviceip LOGGER.error("[ Server URL: %s]" % server_url) ret = http_request( get_url(server_url, "/check_stub"), "GET", {}) if ret is None: LOGGER.error("[ ERROR: get server status timeout, please check deivce! ]") else: if ret.get("OK") is not None: stub_status = 1 return stub_status
def __init__(self, config): self.conn = None if "commodule" in config: try: exec "from testkitlite.commodule.%s import get_target_conn" % config[ "commodule"] device_no = config.get('deviceid', None) if device_no is not None: self.conn = get_target_conn(device_no) else: self.conn = get_target_conn() except Exception as error: LOGGER.error("[ Error: Initialize commodule failed: '%s']\n" % error)
def _bdd_test_exec(test_session, cases, result_obj, session_dir): """function for running bdd tests""" result_obj.set_status(0) result_list = [] for i_case in cases['cases']: i_case_timeout = i_case.get('timeout', DEFAULT_TIMEOUT) try: case_entry = i_case['entry'] if not EXISTS(case_entry): i_case['result'] = STR_BLOCK i_case['stdout'] = "[Message]No such file or dirctory: %s" % case_entry result_list.append(i_case) continue case_id = i_case['case_id'] tmp_result_dir = "%s/%s" % (session_dir, case_id) os.makedirs(tmp_result_dir) popen_args = "behave %s --junit --junit-directory %s" % (case_entry, tmp_result_dir) i_case_proc = subprocess.Popen(args=popen_args, shell=True) i_case_pre_time = time.time() while True: i_case_exit_code = i_case_proc.poll() i_case_elapsed_time = time.time() - i_case_pre_time if i_case_exit_code == None: if i_case_elapsed_time >= i_case_timeout: tr_utils.KillAllProcesses(ppid=i_case_proc.pid) i_case['result'] = STR_BLOCK i_case['stdout'] = "[Message]Timeout" LOGGER.debug("Run %s timeout" % case_id) break elif str(i_case_exit_code) == str(i_case['expected_result']): i_case['result'] = STR_PASS i_case['stdout'] = tmp_result_dir break else: i_case['result'] = STR_FAIL i_case['stdout'] = tmp_result_dir break time.sleep(1) except KeyError: i_case['result'] = STR_BLOCK i_case['stdout'] = "[Message]No 'bdd_test_script_entry' node." LOGGER.error( "Run %s: failed: No 'bdd_test_script_entry' node, exit from executer" % case_id) except Exception, e: i_case['result'] = STR_BLOCK i_case['stdout'] = "[Message]%s" % e LOGGER.error( "Run %s: failed: %s, exit from executer" % (case_id, e)) result_list.append(i_case)
def _iosuiauto_test_exec(test_session, cases, result_obj, session_dir): """function for running iosuiauto tests""" result_obj.set_status(0) result_list = [] for i_case in cases['cases']: i_case_timeout = i_case.get('timeout', DEFAULT_TIMEOUT) try: case_entry = i_case['entry'] expected_result = int(i_case['expected_result']) if not EXISTS(case_entry): i_case['result'] = STR_BLOCK i_case['stdout'] = "[Message]No such file or dirctory: %s" % case_entry result_list.append(i_case) continue case_id = i_case['case_id'] destination = "platform=%s,name=%s" % (os.environ["IOS_PLATFORM"], os.environ["IOS_NAME"]) if os.environ.get("IOS_VERSION", None): destination = "%s,OS=%s" % (destination, os.environ["IOS_VERSION"]) device_id = os.environ["DEVICE_ID"] popen_args = 'python %s -d "%s" -u "%s"' % (case_entry, destination, device_id) i_case_proc = subprocess.Popen(args=popen_args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) i_case_pre_time = time.time() while True: output_infos = i_case_proc.communicate() i_case_exit_code = i_case_proc.returncode i_case_elapsed_time = time.time() - i_case_pre_time if i_case_exit_code == None: if i_case_elapsed_time >= i_case_timeout: tr_utils.KillAllProcesses(ppid=i_case_proc.pid) i_case['result'] = STR_BLOCK i_case['stdout'] = "[Message]Timeout" LOGGER.debug("Run %s timeout" % case_id) result_list.append(i_case) break else: if i_case_exit_code == expected_result: i_case['result'] = STR_PASS i_case['stdout'] = "[Message]" + output_infos[0].replace("\n", "\r") else: i_case['result'] = STR_FAIL i_case['stderr'] = output_infos[1].replace("\n", "\r") result_list.append(i_case) break time.sleep(1) except Exception, e: i_case['result'] = STR_BLOCK i_case['stdout'] = "[Message]%s" % e LOGGER.error( "Run %s: failed: %s, exit from executer" % (case_id, e)) result_list.append(i_case)
def _nodeunit_test_exec(test_session, cases, result_obj, session_dir): """function for running nodeunit tests""" result_obj.set_status(0) result_list = [] for i_case in cases['cases']: i_case_timeout = i_case.get('timeout', DEFAULT_TIMEOUT) try: case_entry = i_case['entry'] if not EXISTS(case_entry): i_case['result'] = STR_BLOCK i_case['stdout'] = "[Message]No such file or dirctory: %s" % case_entry result_list.append(i_case) continue case_id = i_case['case_id'] tmp_result_dir = "%s/%s" % (session_dir, case_id) os.makedirs(tmp_result_dir) popen_args = "nodeunit %s --reporter junit --output %s" % (case_entry, tmp_result_dir) i_case_proc = subprocess.Popen(args=popen_args, shell=True, stderr=subprocess.PIPE) i_case_pre_time = time.time() while True: i_case_exit_code = i_case_proc.poll() i_case_elapsed_time = time.time() - i_case_pre_time if i_case_exit_code == None: if i_case_elapsed_time >= i_case_timeout: tr_utils.KillAllProcesses(ppid=i_case_proc.pid) i_case['result'] = STR_BLOCK i_case['stdout'] = "[Message]Timeout" LOGGER.debug("Run %s timeout" % case_id) break else: if int(i_case_exit_code) == 0: i_case['result'] = STR_PASS i_case['stdout'] = tmp_result_dir elif int(i_case_exit_code) == 1: i_case['result'] = STR_FAIL i_case['stdout'] = tmp_result_dir else: i_case['result'] = STR_BLOCK i_case['stdout'] = "[Message]%s" % ''.join(i_case_proc.stderr.readlines()).strip('\n') break time.sleep(1) except Exception, e: i_case['result'] = STR_BLOCK i_case['stdout'] = "[Message]%s" % e LOGGER.error( "Run %s: failed: %s, exit from executer" % (case_id, e)) result_list.append(i_case)
def __init__(self, config): self.conn = None if "commodule" in config: try: exec "from testkitlite.commodule.%s import get_target_conn" % config[ "commodule"] device_no = config.get('deviceid', None) if device_no is not None: self.conn = get_target_conn(device_no) else: self.conn = get_target_conn() except Exception as error: LOGGER.error("[ Error: Initialize commodule failed: '%s']\n" % error)
def _xcunit_test_exec(test_session, cases, result_obj, session_dir): """function for running xcunit tests""" result_obj.set_status(0) result_list = [] for i_case in cases['cases']: i_case_timeout = i_case.get('timeout', DEFAULT_TIMEOUT) try: case_entry = i_case['entry'] if not EXISTS(case_entry): i_case['result'] = STR_BLOCK i_case['stdout'] = "[Message]No such file or dirctory: %s" % case_entry result_list.append(i_case) continue case_id = i_case['case_id'] destination = "platform=%s,name=%s" % (os.environ["IOS_PLATFORM"], os.environ["IOS_NAME"]) if os.environ.get("IOS_VERSION", None): destination = "%s,OS=%s" % (destination, os.environ["IOS_VERSION"]) popen_args = 'python %s -d "%s"' % (case_entry, destination) i_case_proc = subprocess.Popen(args=popen_args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) i_case_pre_time = time.time() while True: output_infos = i_case_proc.communicate() i_case_exit_code = i_case_proc.returncode i_case_elapsed_time = time.time() - i_case_pre_time if i_case_exit_code == None: if i_case_elapsed_time >= i_case_timeout: tr_utils.KillAllProcesses(ppid=i_case_proc.pid) i_case['result'] = STR_BLOCK i_case['stdout'] = "[Message]Timeout" LOGGER.debug("Run %s timeout" % case_id) result_list.append(i_case) break else: for line in output_infos[0].split('\n'): result_dic = {} if line.startswith("Test Case '-["): if line.find("seconds") != -1: info_list = line.split(' ') result_dic['case_id'] = "%s/%s" % (info_list[2][3:], info_list[3][:-2]) result_dic['result'] = {"passed": STR_PASS, "failed": STR_FAIL}[info_list[4]] result_list.append(result_dic) break time.sleep(1) except Exception, e: i_case['result'] = STR_BLOCK i_case['stdout'] = "[Message]%s" % e LOGGER.error( "Run %s: failed: %s, exit from executer" % (case_id, e)) result_list.append(i_case)
def _mocha_test_exec(test_session, cases, result_obj, session_dir): """function for running mocha tests""" result_obj.set_status(0) result_list = [] for i_case in cases['cases']: i_case_timeout = i_case.get('timeout', DEFAULT_TIMEOUT) try: case_entry = i_case['entry'] status, output = commands.getstatusoutput("ssh %s 'ls %s'" % (os.environ["DEVICE_ID"], case_entry)) if status != 0: i_case['result'] = STR_BLOCK i_case['stdout'] = "[Message]No such file or dirctory: %s" % case_entry result_list.append(i_case) continue case_id = i_case['case_id'] tmp_result_dir = "%s/json_results" % session_dir os.makedirs(tmp_result_dir) popen_args = "ssh %s 'mocha %s --reporter json' > %s/%s.json" % (os.environ["DEVICE_ID"], case_entry, tmp_result_dir, case_id) i_case_proc = subprocess.Popen(args=popen_args, shell=True) i_case_pre_time = time.time() while True: i_case_exit_code = i_case_proc.poll() i_case_elapsed_time = time.time() - i_case_pre_time if i_case_exit_code == None: if i_case_elapsed_time >= i_case_timeout: tr_utils.KillAllProcesses(ppid=i_case_proc.pid) i_case['result'] = STR_BLOCK i_case['stdout'] = "[Message]Timeout" LOGGER.debug("Run %s timeout" % case_id) break else: i_case['result'] = STR_FAIL i_case['stdout'] = tmp_result_dir break time.sleep(1) except Exception, e: i_case['result'] = STR_BLOCK i_case['stdout'] = "[Message]%s" % e LOGGER.error( "Run %s: failed: %s, exit from executer" % (case_id, e)) result_list.append(i_case)
def _core_test_exec(conn, test_session, test_set_name, exetype, cases_queue, result_obj): """function for running core tests""" exetype = exetype.lower() total_count = len(cases_queue) current_idx = 0 manual_skip_all = False result_list = [] stdout_file = FILES_ROOT + test_session + "_stdout.log" stderr_file = FILES_ROOT + test_session + "_stderr.log" for test_case in cases_queue: if result_obj.get_status() == 1: break current_idx += 1 core_cmd = "" if "entry" in test_case: core_cmd = test_case["entry"] else: LOGGER.info("[ Warnning: test script is empty," " please check your test xml file ]") continue expected_result = test_case.get('expected_result', '0') time_out = int(test_case.get('timeout', '90')) location = test_case.get('location', 'device') measures = test_case.get('measures', []) retmeasures = [] LOGGER.info("\n[core test] execute case:\nTestCase: %s\n" "TestEntry: %s\nExpected: %s\nTotal: %s, Current: %s" % (test_case['case_id'], test_case['entry'], expected_result, total_count, current_idx)) LOGGER.info("[ execute core test script, please wait ! ]") strtime = datetime.now().strftime(DATE_FORMAT_STR) LOGGER.info("start time: %s" % strtime) test_case["start_at"] = strtime if exetype == 'auto': return_code, stdout, stderr = -1, [], [] if location == 'host': return_code, stdout, stderr = conn.shell_cmd_host( core_cmd, time_out, False, stdout_file, stderr_file) else: return_code, stdout, stderr = conn.shell_cmd_ext( core_cmd, time_out, False, stdout_file, stderr_file) if return_code is not None and return_code != "timeout": test_case["result"] = "pass" if str( return_code) == expected_result else "fail" test_case["stdout"] = stdout test_case["stderr"] = stderr for item in measures: ind = item['name'] fname = item['file'] if fname is None: continue tmpname = FILES_ROOT + test_session + "_mea_tmp" if conn.download_file(fname, tmpname): try: config = ConfigParser.ConfigParser() config.read(tmpname) item['value'] = config.get(ind, 'value') retmeasures.append(item) os.remove(tmpname) except IOError as error: LOGGER.error("[ Error: fail to parse value," " error:%s ]\n" % error) test_case["measures"] = retmeasures else: test_case["result"] = "BLOCK" test_case["stdout"] = stdout test_case["stderr"] = stderr elif exetype == 'manual': # handle manual core cases try: # LOGGER.infopre-condition info if "pre_condition" in test_case: LOGGER.info("\n****\nPre-condition: %s\n ****\n" % test_case['pre_condition']) # LOGGER.infostep info if "steps" in test_case: for step in test_case['steps']: LOGGER.info("********************\n" "Step Order: %s" % step['order']) LOGGER.info("Step Desc: %s" % step['step_desc']) LOGGER.info("Expected: %s\n********************\n" % step['expected']) if manual_skip_all: test_case["result"] = "N/A" else: while True: test_result = raw_input( '[ please input case result ]' ' (p^PASS, f^FAIL, b^BLOCK, n^Next, d^Done):') if test_result.lower() == 'p': test_case["result"] = "PASS" break elif test_result.lower() == 'f': test_case["result"] = "FAIL" break elif test_result.lower() == 'b': test_case["result"] = "BLOCK" break elif test_result.lower() == 'n': test_case["result"] = "N/A" break elif test_result.lower() == 'd': manual_skip_all = True test_case["result"] = "N/A" break else: LOGGER.info( "[ Warnning: you input: '%s' is invalid," " please try again ]" % test_result) except IOError as error: LOGGER.info("[ Error: fail to get core manual test step," " error: %s ]\n" % error) strtime = datetime.now().strftime(DATE_FORMAT_STR) LOGGER.info("end time: %s" % strtime) test_case["end_at"] = strtime LOGGER.info("Case Result: %s" % test_case["result"]) result_list.append(test_case) result_obj.extend_result(result_list, False) result_obj.set_status(1)
def _web_test_exec(conn, server_url, test_web_app, exetype, cases_queue, result_obj): """function for running web tests""" exetype = exetype.lower() test_set_finished = False err_cnt = 0 for test_group in cases_queue: if test_set_finished: break ret = http_request(get_url(server_url, "/set_testcase"), "POST", test_group, 30) if ret is None: LOGGER.error("[ set testcases timeout, please check device! ]") result_obj.set_status(1) break if not conn.launch_app(test_web_app): LOGGER.error("[ ERROR: launch test app %s failed! ]" % test_web_app) result_obj.set_status(1) break while True: if result_obj.get_status() == 1: test_set_finished = True break ret = http_request(get_url(server_url, "/check_server_status"), "GET", {}) if ret is None: LOGGER.error( "[ ERROR: get server status timeout, please check deivce! ]" ) err_cnt += 1 else: result_cases = ret.get("cases") error_code = ret.get("error_code") if error_code is not None: if not conn.launch_app(test_web_app): test_set_finished = True result_obj.set_status(1) break if error_code == LAUNCH_ERROR: LOGGER.error( "[ ERROR: test app no response, hang or not launched! ]" ) test_set_finished = True result_obj.set_status(1) break elif error_code == BLOCK_ERROR: LOGGER.error("[ ERROR: test case block issue! ]") err_cnt += 1 else: err_cnt = 0 if result_cases is not None and len(result_cases): result_obj.extend_result(result_cases) elif exetype == 'manual': LOGGER.info("[ please execute manual cases ]\r\n") if ret["finished"] == 1: test_set_finished = True result_obj.set_status(1) break elif ret["block_finished"] == 1: break if err_cnt >= CNT_RETRY: LOGGER.error( "[ ERROR: get too many errors, stop current set! ]") test_set_finished = True result_obj.set_status(1) break time.sleep(2)
def _core_test_exec(conn, test_session, test_set_name, exetype, cases_queue, result_obj): """function for running core tests""" exetype = exetype.lower() total_count = len(cases_queue) current_idx = 0 manual_skip_all = False result_list = [] stdout_file = FILES_ROOT + test_session + "_stdout.log" stderr_file = FILES_ROOT + test_session + "_stderr.log" initscript = os.environ.get('initscript','') postscript = os.environ.get('postscript','') for test_case in cases_queue: if result_obj.get_status() == 1: break current_idx += 1 core_cmd = "" if "entry" in test_case: core_cmd = test_case["entry"] else: LOGGER.info( "[ Warnning: test script is empty," " please check your test xml file ]") continue expected_result = test_case.get('expected_result', '0') time_out = int(test_case.get('timeout', '90')) location = test_case.get('location', 'device') measures = test_case.get('measures', []) retmeasures = [] #LOGGER.info("CASE_ID %s" %test_case['case_id']) os.environ['CASE_ID'] = test_case['case_id'] LOGGER.info("\n[core test] execute case:\nTestCase: %s\n" "TestEntry: %s\nExpected: %s\nTotal: %s, Current: %s" % (test_case['case_id'], test_case['entry'], expected_result, total_count, current_idx)) LOGGER.info("[ execute core test script, please wait ! ]") strtime = datetime.now().strftime(DATE_FORMAT_STR) LOGGER.info("start time: %s" % strtime) test_case["start_at"] = strtime if exetype == 'auto': return_code, stdout, stderr = -1, [], [] if location == 'host': if len(initscript) > 1: return_code, stdout, stderr = conn.shell_cmd_host(initscript, time_out, False, stdout_file, stderr_file) if return_code is not None and return_code != "timeout": LOGGER.info('init script ok') else: LOGGER.info('init script fail') return_code, stdout, stderr = -1, [], [] return_code, stdout, stderr = conn.shell_cmd_host(core_cmd, time_out, False, stdout_file, stderr_file) else: if len(initscript) >1 : return_code, stdout, stderr = conn.shell_cmd_ext(initscript, time_out, False, stdout_file, stderr_file) if return_code is not None and return_code != "timeout": LOGGER.info('init script ok') else: LOGGER.info('init script fail') return_code, stdout, stderr = -1, [], [] return_code, stdout, stderr = conn.shell_cmd_ext(core_cmd, time_out, False, stdout_file, stderr_file) print 'return ', return_code, stdout, stderr if return_code is not None and return_code != "timeout": test_case["result"] = "pass" if str( return_code) == expected_result else "fail" test_case["stdout"] = stdout test_case["stderr"] = stderr for item in measures: ind = item['name'] fname = item['file'] if fname is None: continue tmpname = FILES_ROOT + test_session + "_mea_tmp" if conn.download_file(fname, tmpname): try: config = ConfigParser.ConfigParser() config.read(tmpname) item['value'] = config.get(ind, 'value') retmeasures.append(item) os.remove(tmpname) except IOError as error: LOGGER.error( "[ Error: fail to parse value," " error:%s ]\n" % error) test_case["measures"] = retmeasures else: test_case["result"] = "BLOCK" test_case["stdout"] = stdout test_case["stderr"] = stderr elif exetype == 'manual': # handle manual core cases try: # LOGGER.infopre-condition info if "pre_condition" in test_case: LOGGER.info("\n****\nPre-condition: %s\n ****\n" % test_case['pre_condition']) # LOGGER.infostep info if "steps" in test_case: for step in test_case['steps']: LOGGER.info( "********************\n" "Step Order: %s" % step['order']) LOGGER.info("Step Desc: %s" % step['step_desc']) LOGGER.info( "Expected: %s\n********************\n" % step['expected']) if manual_skip_all: test_case["result"] = "N/A" else: while True: test_result = raw_input( '[ please input case result ]' ' (p^PASS, f^FAIL, b^BLOCK, n^Next, d^Done):') if test_result.lower() == 'p': test_case["result"] = "PASS" break elif test_result.lower() == 'f': test_case["result"] = "FAIL" break elif test_result.lower() == 'b': test_case["result"] = "BLOCK" break elif test_result.lower() == 'n': test_case["result"] = "N/A" break elif test_result.lower() == 'd': manual_skip_all = True test_case["result"] = "N/A" break else: LOGGER.info( "[ Warnning: you input: '%s' is invalid," " please try again ]" % test_result) except IOError as error: LOGGER.info( "[ Error: fail to get core manual test step," " error: %s ]\n" % error) strtime = datetime.now().strftime(DATE_FORMAT_STR) LOGGER.info("end time: %s" % strtime) test_case["end_at"] = strtime LOGGER.info("Case Result: %s" % test_case["result"]) result_list.append(test_case) if len(postscript) > 1 : if location == 'host': return_code, stdout, stderr = conn.shell_cmd_host(postscript, time_out, False, stdout_file, stderr_file) if return_code is not None and return_code != "timeout": LOGGER.info('post script ok') else: LOGGER.info('post script fail') else: if postscript is not None or postscript is not '': return_code, stdout, stderr = conn.shell_cmd_ext(postscript, time_out, False, stdout_file, stderr_file) if return_code is not None and return_code != "timeout": LOGGER.info('post script ok') else: LOGGER.info('post script fail') result_obj.extend_result(result_list, False) result_obj.set_status(1)
def _web_test_exec(conn, server_url, test_web_app, exetype, cases_queue, result_obj): """function for running web tests""" print 'test_web_app', test_web_app exetype = exetype.lower() test_set_finished = False err_cnt = 0 for test_group in cases_queue: if test_set_finished: break ret = http_request( get_url(server_url, "/set_testcase"), "POST", test_group, 30) if ret is None: LOGGER.error( "[ set testcases timeout, please check device! ]") result_obj.set_status(1) break if not conn.launch_app(test_web_app): LOGGER.error("[ ERROR: launch test app %s failed! ]" % test_web_app) result_obj.set_status(1) break while True: if result_obj.get_status() == 1: test_set_finished = True break ret = http_request( get_url(server_url, "/check_server_status"), "GET", {}) if ret is None: LOGGER.error( "[ ERROR: get server status timeout, please check deivce! ]") err_cnt += 1 else: result_cases = ret.get("cases") error_code = ret.get("error_code") if error_code is not None: if not conn.launch_app(test_web_app): test_set_finished = True result_obj.set_status(1) break if error_code == LAUNCH_ERROR: LOGGER.error("[ ERROR: test app no response, hang or not launched! ]") test_set_finished = True result_obj.set_status(1) break elif error_code == BLOCK_ERROR: LOGGER.error("[ ERROR: test case block issue! ]") err_cnt += 1 else: err_cnt = 0 if result_cases is not None and len(result_cases): result_obj.extend_result(result_cases) elif exetype == 'manual': LOGGER.info( "[ please execute manual cases ]\r\n") if ret["finished"] == 1: test_set_finished = True result_obj.set_status(1) break elif ret["block_finished"] == 1: break if err_cnt >= CNT_RETRY: LOGGER.error( "[ ERROR: get too many errors, stop current set! ]") test_set_finished = True result_obj.set_status(1) break time.sleep(2)