예제 #1
0
파일: tasktool.py 프로젝트: chinple/mserver
    def _syncTasks(self, task=None, isfinish=False, tret=None):
        if task is not None:
            slog.info(toJsonStr(task))
        subject, body = None, None
        if isfinish:
            emailstatus = 0
            if task['fcount'] == 0:
                if task['ftime'] > 0:
                    task['ftime'] = 0
                    emailstatus = 1  # must send
            elif task['ftime'] == 0:
                task['ftime'] = time.time()
            else:
                if (time.time() - task['ftime']) < 7200:
                    emailstatus = 2  # not send
                else:
                    task['ftime'] = time.time()
                    emailstatus = 1

            if task['notifycond'] == 'all' or (task['notifycond'] == 'failed' and task["result"] > 0) \
                or (task['notifycond'] == 'condition' and (emailstatus == 1 or (emailstatus != 2 and task["result"] > 0))):
                try:
                    subject, body = self.task.getTaskReport(task, tret)
                except Exception as ex:
                    slog.info("Fail to get report %s: %s" % (ex, task))
        try:
            return self._callServer(aname="_syncTaskNode",
                task=task, subject=subject, body=body, tnode={'n':self.nodename, 'v':self.nodehost })
        except Exception as ex:
            slog.info("Fail to sync for %s: %s" % (ex, task))
예제 #2
0
파일: cclient.py 프로젝트: achievec/mserver
def curlCservice(hosts,
                 infPath,
                 isGetInfo=False,
                 isCheckResp=False,
                 logHandler=None,
                 curlHeader={},
                 **args):
    from libs.parser import toJsonStr, toJsonObj
    if isGetInfo:
        resp = curl("%s/cservice/%s" % (hosts, infPath),
                    logHandler=logHandler,
                    **curlHeader)
        try:
            return toJsonObj(resp)
        except:
            return resp

    resp = curl("%s/cservice/%s" % (hosts, infPath),
                toJsonStr(args),
                logHandler=logHandler,
                **curlHeader)
    resp = toJsonObj(resp)
    if isCheckResp:
        if resp[0] != 0:
            raise Exception("Fail to response: %s" % resp[1])
        return resp[1]
    else:
        return resp
예제 #3
0
파일: cclient.py 프로젝트: wanxi3/mserver
def curlCservice(hosts, infPath, isCheckResp=False, isGetInfo=False, logHandler=None, connTimeout=None, **args):
    from libs.parser import toJsonStr, toJsonObj

    resp = curl("%s/cservice/%s" % (hosts, infPath), None if isGetInfo else toJsonStr(args), logHandler=logHandler, connTimeout=connTimeout)
    resp = toJsonObj(resp)
    if isCheckResp:
        if resp[0] != 0:
            raise Exception("Fail to response: %s" % resp[1])
        return resp[1]
    else:
        return resp
예제 #4
0
 def addDeploy(self, version, procode, branch, pendtime=None, owner=None, notifyer=None, remark=None, attach=None,
         fnid=None, nid1=None, nid2=None, phaseInit=False, deployid=None, __session__=None):
     proname, protype, brancharg, deployarg = None, None, None, None
     phase, status = (1 if phaseInit else 0, 0) if deployid is None else (None, None)
     creator = __session__['name']
     if deployid is not None:
         deploy = self.dbapi.getCdeploy(deployid=deployid)[0]
         if not __session__['admin'] and not self._isRelativeDeploy(creator, deploy):
             raise Exception("Not the creator or owner")
     if not Sql.isEmpty(attach):
         attach = toJsonStr(attach)
     return self.dbapi.saveCdeploy(version, procode, proname, protype, branch, brancharg, pendtime,
         creator, owner, notifyer, remark, attach, fnid, nid1, nid2, phase, status, deployarg, deployid=deployid)
예제 #5
0
def encodeUrl(jdata):
    from libs.parser import toJsonStr

    if jdata is None:return
    ds = []
    for k in jdata.keys():
        v = jdata[k]
        if type(v) == dict or type(v) == list:
            v = toJsonStr(v)
        else:
            v = str(v)
        ds.append("%s=%s" % (k, urllib.quote(v)))
    return "&".join(ds)
예제 #6
0
 def _doreport(self, t, s):
     if self.repUrl:
         from server.cclient import curl
         from libs.parser import toJsonStr
         if len(s) > 0:
             curl(self.repUrl,
                  toJsonStr({
                      "t": t,
                      "s": s,
                      'perf': self.isperf,
                      'env': self.env,
                      'span': self.tspan
                  }),
                  connTimeout=.2)
     elif self.repHandle:
         self.repHandle(t, s)
     else:
         print t, s
예제 #7
0
    def sendEmail(self, emailProxy, smtpAddr, smtpLogin, sender, receiver):
        if emailProxy == "" or smtpAddr == "" or receiver == "": return

        try:
            receiver = receiver.split(";")
            mimeMail = self.__makeEmail(sender, receiver, self.subject,
                                        self.htmlContent)
            if emailProxy.strip() != "":
                from server.cclient import curl
                from libs.parser import toJsonStr
                slog.info("Sending report: %s -> %s" % (emailProxy, receiver))
                slog.info(
                    curl(
                        "%s/cservice/TestPlanApi/sendMtestEmail" % emailProxy,
                        toJsonStr({
                            "mimeMail": mimeMail.as_string(),
                            "mailto": ";".join(receiver),
                            "mailcc": "",
                            "verify": "mtest"
                        })))
                return

            smtpAccount, smtpPasswd = base64.decodestring(smtpLogin).split("/")
            slog.info("Sending report mail(SMTP %s):\n\t%s -> %s" %
                      (smtpAddr, smtpAccount, receiver))
            smtp = smtpAddr.split(':')
            smtpServer = smtp[0]
            smtpPort = int(ObjOperation.tryGetVal(smtp, 1, 25))

            from smtplib import SMTP
            smtpClient = SMTP(smtpServer, smtpPort)
            try:
                smtpClient.ehlo()
                smtpClient.login(smtpAccount, smtpPasswd)
            except:
                pass
            smtpClient.sendmail(sender, receiver, mimeMail.as_string())
            smtpClient.quit()
        except Exception as ex:
            slog.info(self.htmlContent)
            slog.info("Fail to send mail for: %s" % ex)
예제 #8
0
 def flushRecord(self, fname):
     with codecs.open(self.dbFileFormat % fname, "w", encoding="utf-8") as df:
         df.write(toJsonStr(self.__getRecords(fname)))
예제 #9
0
파일: cclient2.py 프로젝트: chinple/mserver
 def makeFormValue(self, name, value, filetype=None):
     if isinstance(value, dict) or isinstance(value, list):
         from libs.parser import toJsonStr
         value = toJsonStr(value)
     return '%s=%s%s' % (name, value, '' if filetype is None else
                         (';type=%s' % filetype))
예제 #10
0
def curlCservice(hosts, infPath, urlPath=None, isCheckResp=False, isGetInfo=False, logHandler=None, connTimeout=None, **args):
    from libs.parser import toJsonStr, toJsonObj
    if infPath: infPath = infPath.replace(".", "/")
    resp = curl(("%s%s" % (hosts, urlPath)) if urlPath else ("%s/cservice/%s" % (hosts, infPath)), None if isGetInfo else toJsonStr(args), logHandler=logHandler, connTimeout=connTimeout)
    resp = toJsonObj(resp)
    if isCheckResp:
        if resp[0] != 0:
            raise Exception("[%s] %s" % (infPath, resp[1]))
        return resp[1]
    else:
        return resp