def set_table(self, plan_id, value):
     try:
         redispool.hset("%s:%s" % (self.key, plan_id), "table", value)
         db_logger.debug("内容设定成功")
         return True
     except Exception as e:
         db_logger.error("内容设定失败,失败原因:" + repr(e))
         return False
 def query_time(self, plan_id):
     try:
         data = redispool.hget("%s:%s" % (self.key, plan_id), "time")
         db_logger.debug("内容查询成功")
         return data
     except Exception as e:
         db_logger.error("内容查询失败,失败原因:" + repr(e))
         return None
 def query(self, role_id):
     try:
         data = redispool.hget(self.key, role_id)
         logmsg = "Redis查询|" + self.key + "查询成功"
         db_logger.debug(logmsg)
         return data
     except Exception as e:
         logmsg = "Redis查询|" + self.key + "查询失败,失败原因:" + repr(e)
         db_logger.error(logmsg)
 def set_time(self, plan_id):
     try:
         redispool.hset("%s:%s" % (
             self.key, plan_id), "time", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
         db_logger.debug("内容设定成功")
         return True
     except Exception as e:
         db_logger.error("内容设定失败,失败原因:" + repr(e))
         return False
 def delete(self, role_id):
     try:
         redispool.hdel(self.key, role_id)
         logmsg = "Redis值删除|" + self.key + "值删除成功"
         db_logger.debug(logmsg)
         return True
     except Exception as e:
         logmsg = "Redis值删除|" + self.key + "值删除失败,失败原因:" + repr(e)
         db_logger.error(logmsg)
         return False
 def set(self, role_id, value):
     try:
         redispool.hset(self.key, role_id, value)
         logmsg = "Redis值设定|" + self.key + "值设定成功"
         db_logger.debug(logmsg)
         return True
     except Exception as e:
         logmsg = "Redis值设定|" + self.key + "值设定失败,失败原因:" + repr(e)
         db_logger.error(logmsg)
         return False
 def delete(self, user_id):
     try:
         redispool.hdel(self.key, user_id)
         logmsg = "Redis值删除|" + self.key + "值对应缓存数据删除"
         db_logger.debug(logmsg)
         return True
     except Exception as e:
         logmsg = "Redis值删除|" + self.key + "值对应缓存数据删除,失败原因:" + repr(e)
         db_logger.error(logmsg)
         return False
 def delete(self, plan_id):
     try:
         redispool.hdel("%s:%s" % (self.key, plan_id), "table")
         redispool.hdel("%s:%s" % (self.key, plan_id), "time")
         logmsg = "内容数据删除成功"
         db_logger.debug(logmsg)
         return True
     except Exception as e:
         logmsg = "内容数据删除失败,失败原因:" + repr(e)
         db_logger.error(logmsg)
         return False
Exemple #9
0
def kill_task(assign_data):
    """
        :param assign_data: 测试任务下发数据
        :return: 无返回
    """
    # 获取已下发测试任务的所有有效的worker信息
    good_workers = []
    # 轮询assign_data中的worker,判断是否可用
    for ad in assign_data:
        # 根据ad的workerId查询workerInfo
        try:
            worker_info = model_mysql_workerinfo.query.filter(
                model_mysql_workerinfo.workerId == ad.workerId).first()
        except Exception as e:
            db_logger.error("worker:" + str(ad.workerId) + " 信息查询失败,失败原因:" +
                            repr(e))
        else:
            db_logger.debug("worker:" + str(ad.workerId) + " 信息查询成功")
            # 判断数据是否存在
            if worker_info is None:
                # 如果worker的条目没有了,则将对应下发记录的finishTime直接赋上
                update_finishtime(ad.assignId)
            else:
                s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                s.settimeout(2)
                r = s.connect_ex((worker_info.ip, worker_info.port))
                if r != 0:
                    # 将worker的状态置为异常
                    worker_info.status = 0
                    # 如果worker的状态为异常,则将对应下发记录的finishTime直接赋上
                    update_finishtime(ad.assignId)
                else:
                    # 将worker的状态置为正常
                    worker_info.status = 1
                    good_workers.append(ad)
                try:
                    mysqlpool.session.commit()
                except Exception as e:
                    sys_logger.error("worker:" + str(ad.workerId) +
                                     " 信息更新失败,失败原因:" + repr(e))
                else:
                    sys_logger.debug("worker:" + str(ad.workerId) + " 信息更新成功")
                s.close()

    # 如果缺少可用worker
    if len(good_workers) < 1:
        pass
    else:
        # 开启线程池
        pool = ThreadPool(len(good_workers))
        pool.map(kill, good_workers)
        pool.close()
        pool.join()
Exemple #10
0
def update_finishtime(assign_id):
    try:
        assign_data = model_mysql_taskassign.query.filter(
            model_mysql_taskassign.assignId == assign_id).first()
        if assign_data:
            assign_data.finishTime = datetime.datetime.now().strftime(
                "%Y-%m-%d %H:%M:%S")
            mysqlpool.session.commit()
    except Exception as e:
        db_logger.error("assign_id:" + str(assign_id) + " 信息更新失败,失败原因:" +
                        repr(e))
    else:
        db_logger.debug("assign_id:" + str(assign_id) + " 信息更新成功")
Exemple #11
0
def user_password_put():
    # 初始化返回内容
    response_json = {"code": 200, "msg": "操作成功", "data": {}}

    # 取出参数
    user_id = flask.request.headers['UserId']
    old_password = flask.request.json['oldPassword']
    new_password = flask.request.json['newPassword']
    confirm_password = flask.request.json['confirmPassword']

    # 判断新密码与确认密码是否一致
    if new_password != confirm_password:
        return route.error_msgs[201]['msg_new_password_inconformity']

    # 查找账户id以及旧密码
    try:
        mysql_user_info = model_mysql_userinfo.query.filter(
            model_mysql_userinfo.userId == user_id).first()
        db_logger.debug("账户基础信息读取成功")
    except Exception as e:
        db_logger.error("账户基础信息读取失败,失败原因:" + repr(e))
        return route.error_msgs[500]['msg_db_error']
    else:
        if mysql_user_info is None:
            return route.error_msgs[201]['msg_no_user']
        else:
            user_pass = mysql_user_info.userPassword

    # 根据userId查询旧密码,并判断一致性
    if user_pass != old_password:
        return route.error_msgs[201]['msg_old_password_incorrect']
    else:
        # 更新mysql密码
        mysql_user_info.userPassword = new_password
        try:
            mysqlpool.session.commit()
            db_logger.debug("账户基础信息修改成功")
        except Exception as e:
            db_logger.error("账户基础信息更新失败,失败原因:" + repr(e))
            return route.error_msgs[500]['msg_db_error']

    # 最后返回内容
    return response_json