def run(self, args, opts): """Sub command 'check' runner""" if not opts.cases: raise UsageError("case path must be set with -c or --cases!") print " Syntax Checking ".center(70, '*') print '...' log_level = 'TRACE' cases_path = opts.cases tmp_path = tempfile.gettempdir() xml_result = os.path.join(tmp_path, "check_result.xml") output_file = os.path.join(tmp_path, "stdout.txt") with open(output_file, 'w') as stdout: dryrun_result = run(cases_path, dryrun=True, loglevel=log_level, log='NONE', report='NONE', output=xml_result, stdout=stdout) detail_result = ExecutionResult(xml_result) if opts.is_tcms: if not opts.plan_id: raise UsageError("plan id must be set with -p or --planid!") plan_id = opts.plan_id tcms = TCMS() ids = tcms.get_plan_case_ids(plan_id) detail_result.visit(ResultChecker(ids, plan_id)) elif dryrun_result == 0: print 'Contratulations, no syntax error' else: detail_result.visit(DryRunChecker()) print '\n( No news is good news:) )' print 'checing result is in the file: %s' % output_file print ' DONE '.center(70, '*')
def collect_results(tags, plan_id, run_id, worker_root, slavesip, is_tcms, output_dir): """for collecting tcms xmlrpc signal and dealing with them""" project_name = os.environ['project_name'] port = plan_id tcms = TCMS() tcms.update_run_status(run_id, 0) context = zmq.Context() # socket for results_receive results_receiver = context.socket(zmq.PULL) rport = str(int(port) + 1) results_receiver.bind("tcp://*:%s" % rport) task_num = len(tags) receive_count = 0 # socket for worker control(send kill signal) controller = context.socket(zmq.PUB) cport = str(int(port) - 1) controller.bind("tcp://*:%s" % cport) while True: result = results_receiver.recv_pyobj() receive_count += 1 if is_tcms: #***************** Update TCMS caserun status ************** caserun_id = tcms.get_caserun_id(run_id, result['caseid']) tcms.update_caserun_status(caserun_id, result['status']) if result['status'] != 'PASSED': tcms.update_caserun_log(caserun_id, result['log']) print 'Case-run %s is updated in TCMS' % result['caseid'] #*********************************************************** #*********************** Finally ******************************* if receive_count == task_num: #sending kill signal to workers controller.send_pyobj("KILL") # collect reports and produce final report robotx_path = robotx.__path__[0] fab_file = os.path.join(robotx_path, 'core', 'fabworker.py') collectresults = "collect_reports:%s,%s" \ % (worker_root, project_name) os.system('fab --hide=running -f %s -H %s %s' % (fab_file, slavesip, collectresults)) os.system("rebot --name 'RobotX Report' --outputdir %s \ --output output --processemptysuite --tagstatexclude \ 'ID_*' ./*.xml" % output_dir) time.sleep(3) os.system('rm -rf ID_*.xml') # kill all workers!!! # coon die henchman boil:-) time.sleep(5) break tcms.update_run_status(run_id, 1) print '\n', 'GAME OVER'.center(80, '=')
def __init__(self, planid, runid): self.planid = planid self.runid = runid self.tcms = TCMS() self.tcms.update_run_status(self.runid, 0) self.caseruns = []
def run(self, args, opts): """Sub command 'run' runner""" stime = datetime.now() tcms = TCMS() log_level = 'DEBUG' noncritical = ['noncritical'] exclude_tag = ['notready'] tagstatexclude = 'ID_*' if opts.is_jenkins: # run with Jenkins params = ParamsHandler() project_name = params.project_name os.environ['project_name'] = project_name cases_path = params.cases_path plan_id = params.tcms_plan_id run_id = params.tcms_run_id tags = params.case_tags priorities = params.case_priorities run_id, case_ids = tcms.get_case_ids(plan_id, run_id, tags, priorities, opts.is_tcms) other_variables = params.other_variables if len(case_ids) == 0: print "There's no case matching filter conditions" sys.exit(255) tag_case_id = ['ID_' + str(theid) for theid in case_ids] output_dir = params.result_path if not opts.is_dist: # In Jenkins, run all testing on one node, and not distributed if opts.is_tcms: # run with Jenkins and TCMS listener = params.tcms_listener(plan_id, run_id) run(cases_path, loglevel=log_level, include=tag_case_id, exclude=exclude_tag, noncritical=noncritical, outputdir=output_dir, variable=other_variables, tagstatexclude=tagstatexclude, listener=listener) else: # run with Jenkins but without TCMS run(cases_path, loglevel=log_level, include=tag_case_id, exclude=exclude_tag, noncritical=noncritical, outputdir=output_dir, variable=other_variables, tagstatexclude=tagstatexclude) else: # In Jenkins, running testing on multi nodes concurrently if not params.master_ip: raise UsageError("mater ip must be set") if not params.slave_ips: raise UsageError("slave ip must be set") if not params.slave_pwd: raise UsageError("slave password must be set") slave_password = params.slave_pwd os.environ['all_slave_password'] = slave_password slavesip_list = params.slave_ips slavesip = reduce(lambda x, y: x + ',' + y, slavesip_list) masterip = params.master_ip worker_root = '/home/automation' project_path = params.project_path robotpool = Pool() print 'Start to launch workers ...'.center(50, '*') robotpool.apply_async(launch_workers, args=( project_path, worker_root, masterip, slavesip, plan_id, other_variables, )) robotpool.apply_async(distribute_tasks, args=( tag_case_id, plan_id, )) robotpool.apply_async(collect_results, args=(tag_case_id, plan_id, run_id, worker_root, slavesip, opts.is_tcms, output_dir)) robotpool.close() robotpool.join() else: # run without Jenkins if not opts.cases: raise UsageError("case path must be set with -c or --cases!") if not opts.plan_id: raise UsageError("plan id must be set with -p or --planid!") plan_id = opts.plan_id run_id = opts.run_id project_path = opts.cases if project_path[-1] == '/': project_path = project_path[:-1] project_name = project_path.split('/')[-1] os.environ['project_name'] = project_name pass cases_path = os.path.join(project_path, 'cases') tags = opts.case_tags priorities = opts.case_priorities output_dir = opts.output_dir run_id, case_ids = tcms.get_case_ids(plan_id, run_id, tags, priorities, opts.is_tcms) other_variables = opts.other_variables if len(case_ids) == 0: print "There's no case matching filter conditions" sys.exit(255) tag_case_id = ['ID_' + str(theid) for theid in case_ids] # In cmd, run all testing on one node, and not distributed. if not opts.is_dist: if opts.is_tcms: # run without Jenkins but with TCMS listener = 'robotx.core.listener.TCMSListener:%s:%s' \ % (plan_id, run_id) run(cases_path, loglevel=log_level, include=tag_case_id, exclude=exclude_tag, noncritical=noncritical, outputdir=output_dir, variable=other_variables, tagstatexclude=tagstatexclude, listener=listener) else: # run without Jenkins and TCMS run(cases_path, loglevel=log_level, include=tag_case_id, exclude=exclude_tag, noncritical=noncritical, outputdir=output_dir, variable=other_variables, tagstatexclude=tagstatexclude) # In cmd, running testing on multi nodes concurrently else: if not opts.masterip: raise UsageError("mater ip must be set with -m") if not opts.slave_ips: raise UsageError("slave ip must be set \ with -i or --slave_ips") if not opts.password: raise UsageError("password must be set \ with -w or --password!") slave_password = opts.password os.environ['all_slave_password'] = slave_password slavesip_list = opts.slave_ips slavesip = reduce(lambda x, y: x + ',' + y, slavesip_list) masterip = opts.masterip worker_root = '/home/automation' robotpool = Pool() robotpool.apply_async(launch_workers, args=( project_path, worker_root, masterip, slavesip, plan_id, other_variables, )) robotpool.apply_async(distribute_tasks, args=( tag_case_id, plan_id, )) robotpool.apply_async(collect_results, args=( tag_case_id, plan_id, run_id, worker_root, slavesip, opts.is_tcms, output_dir, )) robotpool.close() robotpool.join() etime = datetime.now() elapsed_time = etime - stime print 'Elapsed Time: %s' % elapsed_time