Exemple #1
0
    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))
Exemple #2
0
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
Exemple #3
0
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
Exemple #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)
Exemple #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)
Exemple #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
Exemple #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)
Exemple #8
0
 def flushRecord(self, fname):
     with codecs.open(self.dbFileFormat % fname, "w", encoding="utf-8") as df:
         df.write(toJsonStr(self.__getRecords(fname)))
Exemple #9
0
 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))
Exemple #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