#! /usr/bin/env python # -*- coding: utf-8 -*- from atplatform.plan.runengine.runningmanager import * from atplatform.plan.runengine import execute import gc import time from atplatform.plan.runengine import runninginfo from atplatform.plan.plan import plan import sys reload(sys) sys.setdefaultencoding("utf8") if __name__ == "__main__": for x in xrange(1, 2): p = plan() l = [] l.append( ( "case1", { "Browsername": "firefox", "ignoreProtectedModeSettings": True, "Browserversion": "", "Platform": "WINDOWS", "Findtimeout": 10, "Webdriverhub": "http://localhost:4444/wd/hub", "Javascriptenabled": "True", }, ) ) l.append(
def post(self,argv): s=None planname=None try: so.planprogresslog.info('receive execute plan request') #读取plan schema文件 data=urllib.unquote(self.request.body) a=file("schema.xsd") s=a.read() a.close() #生成schema对象,并提取参数 so.planprogresslog.info('check request body xml format') schema_root = etree.XML(s) schema = etree.XMLSchema(schema_root) parser = etree.XMLParser(schema = schema) root = etree.fromstring(data, parser) planname=root[0].text.strip() so.planprogresslog.info('plan '+str(planname)+' xml format checked passed') if len(str(planname))>50: self.write('failed,planname too long') so.planprogresslog.error('planname too long,plan: '+str(planname)) return s=so.Session() so.planprogresslog.debug('dbsession opened one for '+'plan '+str(planname)) res=s.query(Plan).filter(Plan.Name==planname) so.planprogresslog.info('check plan '+str(planname)+' exist or not') if (res.count()!=0): s.close() self.write("plan already exist!") so.planprogresslog.error('plan '+str(planname)+' has already exist') return so.planprogresslog.info('plan '+str(planname)+' nonexistence check passed') starttime=root[1].text l=[] for case in root[2]: casename=case[0].text config={} config['Browsername']=case[1][0].text if case[1][1].text!=None: config['Browserversion']=case[1][1].text else: config['Browserversion']='' if case[1][2].text.startswith('t'): config['ignoreProtectedModeSettings']=True else: config['ignoreProtectedModeSettings']=False if case[1][3].text!=None: config['Platform']=case[1][3].text else: config['Platform']='ANY' config['Findtimeout']=int(case[1][4].text) config['Webdriverhub']=case[1][5].text if case[1][6].text.startswith('t'): config['Javascriptenabled']='True' else: config['Javascriptenabled']='False' l.append([casename,config]) so.planprogresslog.debug('plan info has been extracted') p=plan() p.name=str(planname) re=p.setplanstarttime(starttime.strip()) if re==False: s.close() self.write("timeset error") so.planprogresslog.error('plan(object) '+str(planname)+' timeset error') return so.planprogresslog.info('plan(object) '+str(planname)+' timeset success') p.setplancases(l) planhandlers[planname]=p plan_add=Plan(planname) plan_add.PlanStatus=s.query(PlanStatus).filter(PlanStatus.Name==so.planstatus[4]).first() plan_add.CreateTime=long(p.plantimeinfo[0]) plan_add.StartTime=long(p.plantimeinfo[1]) s.add(plan_add) check_c_p={} check_cp_bp={} casecache={} browsercache={} for _case in l: if not check_c_p.has_key(str([_case[0],planname])): rel_case=None if casecache.has_key(str([_case[0],planname])): rel_case=casecache[str([_case[0],planname])] else: rel_case=s.query(Case).filter(Case.Name==_case[0]).one() casecache[str([_case[0],planname])]=rel_case cip=Case_in_Plan() cip.Case=rel_case cip.Plan=plan_add s.add(cip) check_c_p[str([_case[0],planname])]=cip if not check_cp_bp.has_key((str([_case[0],planname]),str([_case[1]['Platform'],_case[1]['Browsername'],_case[1]['Browserversion']]))): rel_browser=None if browsercache.has_key(str([_case[0],planname])): rel_browser=casecache[str([_case[1]['Platform'],_case[1]['Browsername'],_case[1]['Browserversion']])] else: rel_browser=s.query(Browser_on_Platform).join(Browser_on_Platform.Browser).join(Browser_on_Platform.Platform).filter(Browser.Name==_case[1]['Browsername'],Browser.Version==_case[1]['Browserversion'],Platform.Name==_case[1]['Platform'],Browser_on_Platform.Browser_on_Platform_Status_ID==1).one() casecache[str([_case[1]['Platform'],_case[1]['Browsername'],_case[1]['Browserversion']])]=rel_case check_c_p[str([_case[0],planname])].Browser_on_Platform.append(rel_browser) check_cp_bp[(str([_case[0],planname]),str([_case[1]['Platform'],_case[1]['Browsername'],_case[1]['Browserversion']]))]=True s.commit() s.close() so.planprogresslog.debug('close dbsession for plan '+str(planname)) so.planprogresslog.info('plan '+str(planname)+' has insert all info to database') p.run() so.planprogresslog.info('plan '+str(planname)+' has get in schedual') self.write('success!') except IntegrityError,e: so.planprogresslog.error(str(traceback.format_exc())) if s!=None: s.rollback() self.write('failed,params conflict')