Beispiel #1
0
def deal_ssh_command(root):
    step = importOfflineCase_step()
    step.set_stepname(root.get("testname"))
    step.set_stepdes(root.get("testname"))
    steps = [step.get_step()]

    # 添加脚本
    script_name = "ssh_jmeter_smart_route"
    ssh_connect = "smart_route_jmeter_ssh"
    ds = dealScriptData(base_name)
    ds.set_ssh_with_default(script_name, ssh_connect, root.get("testname"))
    resp, script_id = post_blade.dealScriptData(ds)
    # 添加数据
    data_content = list()
    temp = dict()
    temp["sheet0"] = list()
    data_chose_row = random_uuid(32)
    one = [random_uuid(32), "序号", "期望", "command"]
    two = [random_uuid(32), "参数说明", "", "脚本文件需要事先放到redis的bin目录下"]
    three = [
        data_chose_row, "", "keyword=OK", "EXEC,sh {};".format(
            root.element.find(".//stringProp[@name='command']").text)
    ]
    temp["sheet0"].append(one)
    temp["sheet0"].append(two)
    temp["sheet0"].append(three)
    data_content.append(temp)

    step.set_scriptcontent(script_id)
    step.set_dataarrcontent(data_chose_row, data_content)

    return steps
Beispiel #2
0
def deal_redis_beanshellsampler(root):
    # 添加脚本
    script_name = "redis_jmeter_smart_route"
    ssh_connect = "smart_route_jmeter_redis"
    ds = dealScriptData(base_name)
    ds.set_ssh_with_default(script_name, ssh_connect, root.get("testname"))
    resp, script_id = post_blade.dealScriptData(ds)
    # 添加数据
    data_content = list()
    temp = dict()
    temp["sheet0"] = list()
    data_chose_row = random_uuid(32)
    one = [random_uuid(32), "序号", "期望", "command"]
    two = [random_uuid(32), "参数说明", "", "脚本文件需要事先放到redis的bin目录下"]
    three = [
        data_chose_row, "", "keyword=OK", "EXEC,sh clear_redis_smart_route.sh;"
    ]
    temp["sheet0"].append(one)
    temp["sheet0"].append(two)
    temp["sheet0"].append(three)
    data_content.append(temp)

    step = importOfflineCase_step()
    step.set_stepname(root.tag + root.get("testname"))
    step.set_stepdes(root.get("testname"))
    step.set_scriptcontent(script_id)
    step.set_dataarrcontent(data_chose_row, data_content)
    return step.get_step()
Beispiel #3
0
    def set_default_dataarrcontent(self):
        default_data_content = list()
        temp = dict()
        temp["sheet0"] = list()
        one = [random_uuid(32), "序号", "期望"]
        two = [random_uuid(32), "参数说明", ""]
        temp["sheet0"].append(one)
        temp["sheet0"].append(two)
        default_data_content.append(temp)

        data_content = self.step_json["dataContent"]
        data_content["id"] = ""
        data_content["dataChoseRow"] = ""
        data_content["content"] = ""
        data_content["dataArrContent"] = default_data_content
Beispiel #4
0
def deal_redis_beanshellsampler(root, step_name, script_content):
    data_content = list()
    temp = dict()
    temp["sheet0"] = list()
    data_chose_row = random_uuid(32)
    one = [random_uuid(32), "序号", "期望", "command"]
    two = [random_uuid(32), "参数说明", "", "脚本文件需要事先放到redis的bin目录下"]
    three = [data_chose_row, "", "keyword=OK", "EXEC,sh clear_redis_ibps.sh;"]
    temp["sheet0"].append(one)
    temp["sheet0"].append(two)
    temp["sheet0"].append(three)
    data_content.append(temp)

    step = importOfflineCase_step()
    step.set_stepname(step_name)
    step.set_stepdes(root.get("testname"))
    step.set_scriptcontent(script_content)
    step.set_dataarrcontent(data_chose_row, data_content)
    return step.get_step()
Beispiel #5
0
def deal_msg_beanshellsampler(root, step_name):
    step = importOfflineCase_step()
    step.set_stepname(step_name)
    step.set_stepdes(root.get("testname"))

    sub_elements = root.get_sub_elements()
    for sub_element in sub_elements:
        if not sub_element.isEnabled():
            continue

        if sub_element.tag == "JDBCPreProcessor":
            data_source = sub_element.element.find(".//stringProp[@name='dataSource']").text
            sql_text = sub_element.element.find(".//stringProp[@name='query']").text
            # 对sql做提取
            sqls = re.findall(
                r"([delete|insert|update|select|DELETE|INSERT|UPDATE|SELECT|Update|Insert|Select|Delete].*?'.*;)",
                sql_text)
            logger.debug("提取的sql:%s" % str(sqls))
            for sql in sqls:
                sql = replace_argument(sql)
                if "%" in sql:
                    sql = sql.replace("%", "%25")
                step.add_presqlcontent(data_sources[data_source], sql)

    script_text = root.element.find(".//stringProp[@name='BeanShellSampler.query']").text
    body = replace_argument(re.findall(r'String msg_body=[\r\n]?(.*?);', script_text)[0])
    body = body.replace("\\r\\n", "\r\n")
    logger.debug(body)

    data_content = list()
    temp = dict()
    temp["sheet0"] = list()
    data_chose_row = random_uuid(32)
    one = [random_uuid(32), "序号", "期望", "body"]
    two = [random_uuid(32), "参数说明", "", ""]
    three = [data_chose_row, "", "", body]
    temp["sheet0"].append(one)
    temp["sheet0"].append(two)
    temp["sheet0"].append(three)
    data_content.append(temp)
    step.set_dataarrcontent(data_chose_row, data_content)
    return step
Beispiel #6
0
def Josn2Blade(message, result, num=0, check_Message=""):
    """
    将报文转化为Blade可接收的测试数据格式
    :param message: 报文数据
    :param num: sheet计数
    :param result: Blade 数据格式
    :param check_Message: 验证字符串
    :return:
    """
    logger.debug("message:{}, num:{}".format(message, num))
    temp = dict()
    temp["sheet" + str(num)] = []
    result.append(temp)
    dict_num = 0
    data_chose_row = random_uuid(32)
    # 传入了验证字段, 则 0 特殊处理
    if num == 0:
        one = [random_uuid(32), "序号", "期望"]
        two = [random_uuid(32), "参数说明", ""]
        three = [data_chose_row, "", check_Message]
        temp["sheet" + str(num)].append(one)
        temp["sheet" + str(num)].append(two)
        temp["sheet" + str(num)].append(three)
    else:
        one = [random_uuid(32), "GroupID"]
        two = [random_uuid(32), "1"]
        temp["sheet" + str(num)].append(one)
        temp["sheet" + str(num)].append(two)

    for key, value in message.items():
        if isinstance(value, dict):
            dict_num += 1
            temp["sheet" + str(num)][0].append(key + "(Object)")
            temp["sheet" + str(num)][-1].append("sheet" + str(num + dict_num) +
                                                "|1")
            Josn2Blade(value, result, num + dict_num)
        else:
            temp["sheet" + str(num)][0].append(key)
            temp["sheet" + str(num)][-1].append(value)

    return data_chose_row, result