Beispiel #1
0
def dhcp_test():
    logger.info("DHCP test...")
    # tc_connect_stc()
    # tc_capture_start()
    # logger.info("STC traffic config...")
    # tc_traffic_config()
    tc_creatDHCPDevice()
Beispiel #2
0
def dut_disconnect_telnet(tn):
    """断开连接"""
    try:
        logger.info("Telnet disconnect!")
        tn.close()
    except Exception as err:
        logger.error(err)
Beispiel #3
0
def send_cmdlines_tl1(tn_obj, cmds, promot=b';', timeout=5, delay=0):
    try:
        for cmd in cmds:
            tn_obj.write(bytes(cmd, encoding='utf8'), timeout=timeout)
            line_ret = str(tn_obj.read_until(promot, timeout), encoding='utf8')
            logger.info(line_ret)
            time.sleep(delay)
        return True
    except Exception as err:
        print(err)
        return None
Beispiel #4
0
def dut_disconnect_tl1(tn_obj):
    try:
        # tn = telnetlib.Telnet(host, port=port)
        logout_str = "LOGOUT:::CTAG::;\n"
        print(logout_str)
        tn_obj.write(bytes(logout_str, encoding='utf8'))
        line_b = tn_obj.read_until(b';', 5)
        line_s = str(line_b, encoding='utf8')
        logger.info(line_s)
        tn_obj.close()
        return True
    except Exception as err:
        print(err)
        return None
Beispiel #5
0
def dut_connect_tl1(host,
                    port=3337,
                    username='******',
                    password='******',
                    timeout=5):
    """通过TL1连接网管"""
    try:
        tn = telnetlib.Telnet(host, port=port)
        login_str = "LOGIN:::CTAG::UN=%s,PWD=%s;\n" % (username, password)
        logger.info(login_str)
        tn.write(bytes(login_str, encoding='utf8'))
        line_b = tn.read_until(b';', 5)
        logger.info(str(line_b, encoding='utf8'))
        return tn
    except Exception as err:
        logger.error("TL1 Connect Failed")
        return None
Beispiel #6
0
    def sendcmdlines(self, cmdlines=None, promot=b"#", timeout=5, delay=0):
        """
        函数功能
            下发命令到设备
        函数参数:
            @para cmdlines:
                命令行列表, 如果为none,下发self.__cmdline中的命令
            @para promot:
                命令行之后完成之后提示符
            @para timeout:
                命令执行超时时间,单位s
            @para delay:
                命令执行间隔时间,单位s
        """
        try:
            if self.__tn is None:
                self.connect_olt()
            if cmdlines is not None:
                self.append_cmdlines(cmdlines)

            if self.version == OLT_VERSION_6K:
                self.__cmdlines.insert(0, 'config\n')
                self.__cmdlines.append("quit\n")
            logger.debug("send command to device...")

            while len(self.__cmdlines) != 0:
                item = self.__cmdlines.pop(0)
                if len(item.strip()) == 0:
                    continue
                logger.debug("cmd:"+item)
                self.__tn.write(bytes(item, encoding='utf8'))
                cmd_rets = ''
                while True:  # 判断执行命令是否执行完成
                    ret = self.__tn.read_until(promot, timeout)
                    cmd_rets += ret.decode("utf-8")
                    if promot not in ret:
                        self.__tn.write(bytes(" ", encoding='utf8'))
                    else:
                        break
                logger.info(cmd_rets)
                return cmd_rets

                time.sleep(delay)
        except Exception as err:
            raise FHATCMDError("sendcmdlines", "send cmd Failed!", traceback.format_exc())
Beispiel #7
0
def PPPoe_test():
    logger.info("PPPoE test...")
    # tc_connect_stc()
    # tc_capture_start()
    # logger.info("STC traffic config...")
    # tc_traffic_config()
    tc_createPPPoEdevice()
    # tc_capture_stop()
    fhstc.stc_saveAsXML('pppoe.xml')
    fhstc.stc_PPPoEv4Connect('server')
    fhstc.stc_PPPoEv4Connect('client')
    time.sleep(5)
    print(fhstc.stc_getPPPoEServerStatus('server'))
    print(fhstc.stc_getPPPoEClientStatus('client'))
    fhstc.stc_streamBlockStart("pppoe_client")
    fhstc.stc_streamBlockStart("pppoe_server")
    waitTime(5)
    tc_get_result()

    fhstc.stc_PPPoEv4Disconnect('server')
    fhstc.stc_PPPoEv4Disconnect('client')
    print(fhstc.stc_getPPPoESimpleResult('server'))
    print(fhstc.stc_getPPPoESimpleResult('client'))
Beispiel #8
0
def waitTime(t):
    """倒计时功能"""
    for i in range(t, 0, -1):
        if i > 10:
            if i == t:
                logger.info("倒计时{}秒!".format(i))
                time.sleep(1)
            else:
                if i % 10 == 0:
                    logger.info("倒计时{}秒!".format(i))
                    time.sleep(1)
        else:
            logger.info("倒计时{}秒!".format(i))
            time.sleep(1)
Beispiel #9
0
def dut_connect_telnet(host: str,
                       port=23,
                       login_promot=fh_olt_promot,
                       promot=None):
    """
    函数功能:
       通过telnet连接设备

    参数说明:
        @param host(str): 
            dut设备的IP地址, 字符串类型 
        @param port(int): 
            telnet登录端口号, 范围(0~65535)默认23
        @param login_promot(dict): 
        key为提示字符, value为对应用户名或者密码, 默认采用烽火OLT登录的默认提示符及用户名和密码
        @param promot: 
            设备登录成功提示符,正常输入命令提示符

    使用说明:
        dut_connect_telnet('10.182.3.100', port=8006, login_promot={"Username:"******"admin", "Password:"******"12345"}, '#')
    """

    # 针对烽火OLT,默认都添加 'User>' 对应命令行'enable'
    if 'User>' not in login_promot:
        login_promot['User>'] = 'enable'

    promot_keys = list(
        bytes(key, encoding='utf8') for key in login_promot.keys())
    promot_keys.append(bytes(promot, encoding='utf8'))

    try:
        logger.info("Connect to Host(%s) by telnet." % host)
        tn = telnetlib.Telnet(host, port=port)
        i, m, data = tn.expect(promot_keys, 5)
        m = str(m.group(), encoding='utf8')

        promot_times = dict()
        while i != -1:  # 没有登录成功,并且提示符正确
            if m == promot:
                logger.info("Connect to Host(%s) success!\n" %
                            host)  # 登录成功,返回tn
                return tn

            if m in promot_times.keys():
                promot_times[m] += 1
                if promot_times[m] > 2:
                    logger.info("Connect to Host(%s) Failed!\n" %
                                host)  # 登录失败,返回 None
                    tn.close()
                    return None
            else:
                promot_times[m] = 1

            logger.debug("%s:%s" % (m, login_promot[m]))
            tn.write(bytes(login_promot[m] + '\n', encoding='utf8'))
            i, m, data = tn.expect(promot_keys, 5)
            m = str(m.group(), encoding='utf8')

    except Exception as err:
        logger.error(err)
        tn = None

    return tn
Beispiel #10
0
def tc_main():
    try:
        logger.info("step 1. connect STC...")
        # tc_connect_stc()
        # logger.info("STC traffic config...")
        tc_traffic_config()
        # tc_creatDHCPDevice()
        fhstc.stc_saveAsXML()
        # tc_generatorConfig()
        tc_capture_start()
        logger.info("start traffic....")
        tc_traffic_start()
        tc_traffic_clear()
        logger.info("get traffic result")
        tc_get_result()
        tc_get_DataSetResult()

        logger.info("Service config...")
        # tc_service_config()
        # logger.info("延时60s")
        # time.sleep(60)
        # logger.info("get traffic result")
        # tc_get_result()

        logger.info("stop traffic...")
        tc_traffic_stop()
        tc_capture_stop()
        logger.info("release ports and disconnet stc.")
        tc_traffic_disconnect()

    except:
        logger.error("用例执行失败")
        global TC_RET
        TC_RET = "Failed"
    else:
        logger.info("用例执行成功")
    finally:
        logger.info(
            "\n=======Result=========\n{:^20}\n======================".format(
                TC_RET))