예제 #1
0
 def POST(self):
     id = web.input().id
     value = web.input().value
     if not id or not value:
         return _response(200, 'no id or value')
     cfg = _getModel(web.ctx.ip)
     if not cfg.run:
         return _response(200, 'not run')
     for sc in cfg.cases:
         for scd in sc['data']:
             if scd['id'] == id:
                 if not scd['resp'] or scd['status'] != '4010':
                     _log.info('4010 redo')
                     return _response(200, 'null')
                 try:
                     scd['status'] = '4010 '
                     _updatedb(web.ctx.ip, cfg.to_json())
                     data = 'org=%s&taskName=%s&channel=hywechat&loginType=%s&passWord=%s' \
                            '&login=%s&extralParams=1001&extralParamsValue=%s&extralParamsA=' \
                            '&extralParamsValueA=&extralParamsB=&extralParamsValueB=&host=%s&port=%s' \
                            '&id=%s&timeout=0&signature=&taskey=%s&crawlChange=1000' % (
                                scd['org'], scd['entry'], scd['logintype'], scd['pwd'], scd['user'], value,
                                cfg.peerip, cfg.peerport, scd['resp']['id'], scd['resp']['taskkey'])
                     sit = _http_post(cfg.server[cfg.envs]['sendtaskurl'], data)
                     singleret = Data()
                     singleret.from_json(sit)
                     tmpp = Data()
                     tmpp.from_json(singleret.result)
                     singleret.result = tmpp
                     scd['resp'] = singleret
                 except:
                     return _response(500, 'single post error')
     _updatedb(web.ctx.ip, cfg.to_json())
     return _response(200, 'ok')
예제 #2
0
def _getModel(ips):
    cfg = Data()
    if _getdb(ips):
        cfg.from_json(_getdb(ips)[0]['cfg'])
    else:
        with open("data.json") as file:
            cfg.from_json(file.read())

        cfg.run = False
        cfg.error = False
        cfg.sc_run = 0  # 0 serials; 1 concurrence
        cfg.envs = '0'  # cfg. 0 self; 1 dev; 2 beta
        cfg.peerip = ''
        cfg.ips = web.ctx.ip
        cfg.peerport = ''
        _updatedb(ips, cfg.to_json())
    return cfg
예제 #3
0
 def POST(self):
     cfg = _getModel(web.ctx.ip)
     if cfg.run:
         return _response(400, u'测试中')
     cfg.run = True
     _log.info("starttest")
     cfg.sc_run = web.input().sc_run
     cfg.envs = web.input().envs
     org = web.input().org
     _log.info('sc_run:' + cfg.sc_run + ' envs:' + cfg.envs + ' org:' + org)
     if cfg.envs == '0':
         cfg.peerip = web.ctx.ip
         if web.ctx.ip == '127.0.0.1':
             cfg.peerip = '172.18.40.8'
         cfg.peerport = '8088'
     else:
         cfg.peerip = ''
         cfg.peerport = ''
     for testi in cfg.cases:
         for onetask in testi['data']:
             if org == 'all' or testi['bank'] == org:
                 data = 'org=%s&taskName=%s&channel=hywechat&loginType=%s&passWord=%s' \
                        '&login=%s&extralParams=1000&extralParamsValue=&extralParamsA=' \
                        '&extralParamsValueA=&extralParamsB=&extralParamsValueB=&host=%s&port=%s' \
                        '&id=&timeout=0&signature=&taskey=&crawlChange=1000' % (
                            onetask['org'], onetask['entry'], onetask['logintype'], onetask['pwd'], onetask['user'],
                            cfg.peerip,
                            cfg.peerport)
                 try:
                     it = _http_post(cfg.server[cfg.envs]['sendtaskurl'], data)
                     oneret = Data()
                     oneret.from_json(it)
                     tmpp = Data()
                     tmpp.from_json(oneret.result)
                     oneret.result = tmpp
                 except:
                     _log.error(traceback.format_exc())
                     _testshutdown(web.ctx.ip)
                     return _response(500, 'remote server error')
                 onetask['createtime'] = time.time()
                 onetask['status'] = '100'
                 onetask['rawdata'] = ''
                 onetask['resp'] = oneret
     _updatedb(web.ctx.ip, cfg.to_json())
     return _response(200, "success")
예제 #4
0
 def GET(self, id):
     if not id:
         return ''
     web.header('Content-Type', 'text/json; charset=utf-8', unique=True)
     cfg = _getModel(web.ctx.ip)
     for vc in cfg.cases:
         for vcd in vc['data']:
             if vcd['id'] == id:
                 try:
                     vi = Data()
                     if vcd.has_key('rawdata'):
                         vi.from_json(vcd['rawdata'])
                         if len(vi.result) == 0 and isinstance(vcd['resp'], types.DictType):
                             vi.from_dict(vcd['resp'])
                     else:
                         vi.from_dict(vcd['resp'])
                     return vi.to_json()
                 except:
                     return vcd['resp']
     return ''
예제 #5
0
def _checktimer():
    while True:
        try:
            time.sleep(2)
            # print 'check timer'
            db.commit()
            for item in db:
                cfg = Data()
                cfg.from_json(item['cfg'])
                flag = False
                for case in cfg.cases:
                    for twotask in case['data']:
                        if not twotask['resp'] or twotask['status'] not in stop_code or twotask['createtime'] == 0 or (
                                        twotask['createtime'] != 0 and time.time() - twotask['createtime'] > 350):
                            continue
                        if twotask['resp']['result']['code'] != 'success':
                            twotask['status'] = 'fail'
                            continue
                        flag = True
                        data = 'requestId=%s&taskey=%s' % (twotask['resp']['requestId'], twotask['resp']['taskkey'][5:])
                        it = _http_post(cfg.server[cfg.envs]['findtaskurl'], data)
                        ret = Data()
                        try:
                            ret.from_json(it)
                        except:
                            _log.error(traceback.format_exc())
                            ret.result = []
                        for r in ret.result:
                            twotask['status'] = r['taskStatus']
                            if r['taskStatus'] not in stop_code:
                                break
                        twotask['rawdata'] = ret.to_json()
                cfg.run = flag
                _updatedb(item['ips'], cfg.to_json())
        except:
            _log.error(traceback.format_exc())