コード例 #1
0
 def setUp(self):
     logger.info('setUp start')
     login.loginWeb(self)
     self.driver.implicitly_wait(10)
     wan_config = NetworkConfig_wanpage(self.driver, self.url)
     wan_config.click_NetworkConfig()
     time.sleep(0.5)
コード例 #2
0
 def setUp(self):
     logger.info('setUp start')
     login.loginWeb(self)  # admin账号登录
     self.driver.implicitly_wait(10)
     wanpage = NetworkConfig_wanpage(self.driver,self.url)
     wanpage.click_NetworkConfig()
     time.sleep(0.5)
     wanpage.click_WANconfig()
     time.sleep(1)
     wanpage.click_GlobalConfig()
     time.sleep(1)
コード例 #3
0
 def test_000_getReady(self):
     u'''更改wan口数量/初始化交换机vlan'''
     wan_config = NetworkConfig_wanpage(self.driver, self.url)
     # 动态wan口,调整wan口数量
     self.driver.implicitly_wait(2)
     try:
         wan_config.find_GlobalConfig()
         time.sleep(1)
     except AttributeError:
         logger.info(u'wan口页面没有全局配置,则不支持动态WAN口')
     except NoSuchElementException:
         logger.info(u'wan口页面没有全局配置,则不支持动态WAN口')
     else:
         try:
             wan_config.find_PortNumber()
         except ElementNotVisibleException:
             logger.info(u'页面没有wan口数量调整,不支持动态WAN口')
         except ElementNotInteractableException:
             logger.info(u'页面没有wan口数量调整,不支持动态WAN口')
         else:
             selPortNumber = wan_config.selelement_byName(
                 wan_config.selPortNumber)
             Select(selPortNumber).select_by_value('1')
             time.sleep(2)
             try:
                 wan_config.find_cfm_ok()
             except NoSuchElementException:
                 logger.info(u'WAN口数量已为1')
             else:
                 time.sleep(30)
                 i = 0
                 while i < 20:
                     now_url = str(self.driver.current_url)
                     # print(now_url,i)
                     if '/noAuth/login.html' not in now_url:  # 如果不同
                         time.sleep(5)
                     else:
                         break
                     i += 1
                 else:
                     raise Exception('更改设备wan口数量后未正常启动')
     self.driver.quit()
     # 2 初始化初始化交换机vlan
     swconfig.test_initSwPort(self)
     logger.info('test_000_getReady passed')
コード例 #4
0
 def test_000_getReady(self):
     u'''更改wan口数量 以及设置wan2与上联口互通'''
     wan_config = NetworkConfig_wanpage(self.driver, self.url)
     #1、 动态wan口,调整wan口数量
     wan_config.click_GlobalConfig()
     time.sleep(1)
     try:
         self.driver.implicitly_wait(2)
         wan_config.find_PortNumber()
     except ElementNotVisibleException:
         logger.info(u'页面没有wan口数量调整,不支持动态WAN口')
     except ElementNotInteractableException:
         logger.info(u'页面没有wan口数量调整,不支持动态WAN口')
     else:
         selPortNumber = wan_config.selelement_byName(
             wan_config.selPortNumber)
         Select(selPortNumber).select_by_value('2')
         time.sleep(2)
         try:
             wan_config.find_cfm_ok()
         except NoSuchElementException:
             logger.info(u'WAN口数量已为2')
         else:
             time.sleep(30)
             i = 0
             while i < 20:
                 now_url = str(self.driver.current_url)
                 # print(now_url,i)
                 if '/noAuth/login.html' not in now_url:  # 如果不同
                     time.sleep(5)
                 else:
                     break
                 i += 1
             else:
                 raise Exception('更改设备wan口数量后未正常启动')
     self.driver.quit()
     #2 调整wan2 与上联口互通
     swconfig.test_changeWAN2(self)
     logger.info('test_000_getReady passed')
コード例 #5
0
 def test_000_getReady(self):
     u'''更改wan口数量 以及设置wan5与上联口互通'''
     wan_config = NetworkConfig_wanpage(self.driver, self.url)
     # #1、 动态wan口,调整wan口数量 目前没有支持wan口动态调整到5个wan口的
     # wan_config.click_GlobalConfig()
     # time.sleep(1)
     # try:
     #     self.driver.implicitly_wait(2)
     #     wan_config.find_PortNumber()
     # except ElementNotVisibleException:
     #     logger.info(u'页面没有wan口数量调整,不支持动态WAN口')
     # except ElementNotInteractableException:
     #     logger.info(u'页面没有wan口数量调整,不支持动态WAN口')
     # else:
     #     selPortNumber = wan_config.selelement_byName(wan_config.selPortNumber)
     #     Select(selPortNumber).select_by_value('5')
     #     time.sleep(2)
     #     try:
     #         wan_config.find_cfm_ok()
     #     except NoSuchElementException:
     #         logger.info(u'WAN口数量已为5')
     #     else:
     #         time.sleep(30)
     #         i = 0
     #         while i < 20:
     #             now_url = str(self.driver.current_url)
     #             # print(now_url,i)
     #             if '/noAuth/login.html' not in now_url:  # 如果不同
     #                 time.sleep(5)
     #             else:
     #                 break
     #             i += 1
     #         else:
     #             raise Exception('更改设备wan口数量后未正常启动')
     self.driver.quit()
     #2 调整wan2 与上联口互通
     swconfig.test_changeWAN5(self)
     logger.info('test_000_getReady passed')
コード例 #6
0
    def test_001_hwNat(self):
        u'''硬件转发 '''
        wanpage = NetworkConfig_wanpage(self.driver, self.url)

        # 默认自动模式
        enable1 = wanpage.getAttribute_byXpath(wanpage.enable1, 'selected')
        enable2 = wanpage.getAttribute_byXpath(wanpage.enable2, 'selected')
        # print('enable1:', enable1,'enable2:', enable2,)
        if enable1 != 'true':
            logger.info(u'快速转发模式开关默认不为自动')
            CapPic(self.driver)
            raise Exception(u'快速转发模式开关默认不为自动')
        if enable2 != 'true':
            logger.info(u'模式开关默认不为硬件转发')
            CapPic(self.driver)
            raise Exception(u'模式开关默认不为硬件转发')
        # 查看后台文件
        tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
        tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        tn.read_until(b'login:'******'Password:'******'#')
        tn.write(b'lsmod ;ls -l /sys/fast_classifier' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 获取WAN口对应接口名称
        result1 = str(result[3:-7])
        print(result1)
        if 'fast_classifier ' in result1 and 'shortcut_fe ' in result1 and 'No such file or directory' in result1:
            print(u'自动模式 模块及转发文件正常')
        else:
            logger.info(u'自动模式 模块or转发文件 异常')
            raise Exception(u'自动模式 模块or转发文件 异常')

        # 开启
        FastForwardEnable = wanpage.selelement_byName('FastForwardEnable')
        Select(FastForwardEnable).select_by_value('NatOpen')
        wanpage.click_save()
        time.sleep(2)
        # 等待弹窗提示成功
        i = 0
        while i < 80:
            try:
                self.driver.implicitly_wait(1)
                wanpage.find_tipsshowin()
            except NoSuchElementException:
                time.sleep(1)
                i = i + 1
                print(i)
            else:
                tips = str(wanpage.getAttribute_byClass(wanpage.tipsshowin, 'tip-sign'))
                print(tips, i)
                if tips != 'success':
                    CapPic(self.driver)
                    logger.info(u'极速模式保存 异常')
                    raise Exception(u'极速模式保存 异常')
                break
        else:
            raise Exception(u'极速模式保存 未弹出提示框')
        time.sleep(6)
        # 查看后台文件
        tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
        tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        tn.read_until(b'login:'******'Password:'******'#')
        tn.write(b'lsmod ;ls -l /sys/fast_classifier' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 获取WAN口对应接口名称
        result1 = str(result[3:-7])
        print(result1)
        lsmod = ['hw_nat', 'ls: /sys/fast_classifier: No such file or directory']
        if all(x in result1 for x in lsmod):
            print(u'开启模式 模块及转发文件正常')
        else:
            logger.info(u'开启模式 模块or转发文件 异常')
            raise Exception(u'开启模式 模块or转发文件 异常')

        # 关闭
        FastForwardEnable = wanpage.selelement_byName('FastForwardEnable')
        Select(FastForwardEnable).select_by_value('0')
        wanpage.click_save()
        time.sleep(2)
        # 等待弹窗提示成功
        i = 0
        while i < 80:
            try:
                self.driver.implicitly_wait(1)
                wanpage.find_tipsshowin()
            except NoSuchElementException:
                time.sleep(1)
                i = i + 1
                print(i)
            else:
                tips = str(wanpage.getAttribute_byClass(wanpage.tipsshowin, 'tip-sign'))
                print(tips, i)
                if tips != 'success':
                    CapPic(self.driver)
                    logger.info(u'极速模式保存 异常')
                    raise Exception(u'极速模式保存 异常')
                break
        else:
            raise Exception(u'极速模式保存 未弹出提示框')
        time.sleep(5)
        # 查看后台文件
        tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
        tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        tn.read_until(b'login:'******'Password:'******'#')
        tn.write(b'lsmod ;ls -l /sys/fast_classifier' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 获取WAN口对应接口名称
        result1 = str(result[3:-7])
        print(result1)
        lsmod = ['fast_classifier ', 'shortcut_fe ', 'exceptions', 'skip_to_bridge_ingress', 'debug_info',
                 'offload_at_pkts','hw_nat']
        if all(x not in result1 for x in lsmod):
            print(u'关闭模式 模块及转发文件正常')
        else:
            logger.info(u'关闭模式 模块or转发文件 异常')
            raise Exception(u'关闭模式 模块or转发文件 异常')

        # 改回自动
        FastForwardEnable = wanpage.selelement_byName('FastForwardEnable')
        Select(FastForwardEnable).select_by_value('NatAuto')
        wanpage.click_save()
        time.sleep(2)
        # 等待弹窗提示成功
        i = 0
        while i < 80:
            try:
                self.driver.implicitly_wait(1)
                wanpage.find_tipsshowin()
            except NoSuchElementException:
                time.sleep(1)
                i = i + 1
                print(i)
            else:
                tips = str(wanpage.getAttribute_byClass(wanpage.tipsshowin, 'tip-sign'))
                print(tips, i)
                if tips != 'success':
                    CapPic(self.driver)
                    logger.info(u'极速模式保存 异常')
                    raise Exception(u'极速模式保存 异常')
                break
        else:
            raise Exception(u'极速模式保存 未弹出提示框')
        time.sleep(5)
        # 查看后台文件
        tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
        tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        tn.read_until(b'login:'******'Password:'******'#')
        tn.write(b'lsmod ;ls -l /sys/fast_classifier' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 获取WAN口对应接口名称
        result1 = str(result[3:-7])
        print(result1)
        if 'fast_classifier ' in result1 and 'shortcut_fe ' in result1 and 'No such file or directory' in result1:
            print(u'自动模式 模块及转发文件正常')
        else:
            logger.info(u'自动模式 模块or转发文件 异常')
            raise Exception(u'自动模式 模块or转发文件 异常')

        logger.info('test_001_changePortRateLAN passed')
コード例 #7
0
    def test_001_dhcp(self):
        u'''外网配置 - 动态接入'''
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        #先判断几条外线接入,删除其他几条外线
        wan_config.click_line1edit()
        time.sleep(1)
        value_list = []
        wan_num = wan_config.selelement_byName(wan_config.PortName)
        options_list = wan_num.find_elements_by_tag_name(
            wan_config.PortNameOptions)
        for option in options_list:
            print("Value is:%s  Text is:%s" %
                  (option.get_attribute("value"), option.text))
            value_list.append(option.get_attribute("value"))
        print(value_list)
        wan_config.click_back()
        time.sleep(1)
        if 'WAN2' in value_list:
            wan_config.click_line2delete()
            time.sleep(1)
            wan_config.click_cfm_ok()
            time.sleep(10)
        if 'WAN3' in value_list:
            wan_config.click_line3delete()
            time.sleep(1)
            wan_config.click_cfm_ok()
            time.sleep(10)
        if 'WAN4' in value_list:
            wan_config.click_line4delete()
            time.sleep(1)
            wan_config.click_cfm_ok()
            time.sleep(10)
        if 'WAN5' in value_list:
            wan_config.click_line5delete()
            time.sleep(1)
            wan_config.click_cfm_ok()
            time.sleep(10)

        # 获取外线的链接类型
        line1_type = wan_config.getText_byXpath(wan_config.line1Type)
        linetype = getAssertText('DHCPline')
        ConnectState = getAssertText('ConnectState')
        # 先改为动态接入,得到正确的IP地址及网关地址
        # WAN1
        if str(line1_type) != linetype:
            wan_config.click_line1edit()
            time.sleep(1)
            access_mode = wan_config.selelement_byName(
                wan_config.connectionType)
            Select(access_mode).select_by_value('DHCP')
            wan_config.click_save()
            time.sleep(10)  # 修改接口后 可能会回到登录页面 所以关闭,再打开
            self.driver.quit()
            login.loginWeb(self)  # admin账号登录
            self.driver.implicitly_wait(10)
            wan_config = NetworkConfig_wanpage(self.driver, self.url)
            wan_config.click_NetworkConfig()
            time.sleep(0.5)
            wan_config.click_WANconfig()
            time.sleep(1)
        else:
            print('wan1 动态接入')
        #断言
        list_lineType = wan_config.getText_byXpath(wan_config.line1Type)
        print('list_lineType:', list_lineType)
        self.assertEqual(str(list_lineType), linetype, msg='连接类型 不为 动态接入')
        # 判断联网状态
        i = 0
        while i < 21:
            wan_config.click_refresh()
            time.sleep(1)
            list_conState = wan_config.getText_byXpath(
                wan_config.connectState1)
            print(str(list_conState), i)
            if str(list_conState) != ConnectState:
                time.sleep(3)
                i += 1
            else:
                break
        else:
            CapPic(self.driver)
            logger.info(u"WAN口未连接")
            raise Exception('WAN1 未连接')
        i = 0
        while i < 21:
            # 判断联网 ,不能上网则报错
            # pingTestIP('114.114.114.114')
            p = pingTestIP('www.baidu.com')
            print(p, i)
            if p == 'N':
                time.sleep(3)
                i += 1
            else:
                break
        else:
            logger.info(u"connect failed")
            raise Exception('connect failed.')

        self.driver.quit()
        logger.info('test_001_dhcp passed')
コード例 #8
0
    def test_004_Fastforward(self):
        u'''硬件转发/软件转发 '''
        wanpage = NetworkConfig_wanpage(self.driver, self.url)
        wanpage.click_NetworkConfig()
        time.sleep(0.5)
        wanpage.click_WANconfig()
        time.sleep(1)
        wanpage.click_GlobalConfig()
        time.sleep(1)

        if hwNatP == '√':
            logger.info(u'参数支持硬件快速转发')
            try:
                self.driver.implicitly_wait(2)
                # 默认自动模式
                wanpage.click_FastForwardEnableC()
                wanpage.click_FastForwardModeC()
            except AttributeError:
                CapPic(self.driver)
                logger.info(u'不支持硬件快速转发,与参数表不相符')
                raise Exception('不支持硬件快速转发,与参数表不相符')
            else:
                enable1 = wanpage.getAttribute_byXpath(wanpage.enable1,
                                                       'selected')
                enable2 = wanpage.getAttribute_byXpath(wanpage.enable2,
                                                       'selected')
                # print('enable1:', enable1,'enable2:', enable2,)
                if enable1 != 'true':
                    logger.info(u'快速转发模式开关默认不为自动')
                    CapPic(self.driver)
                    raise Exception(u'快速转发模式开关默认不为自动')
                if enable2 != 'true':
                    logger.info(u'模式开关默认不为硬件转发')
                    CapPic(self.driver)
                    raise Exception(u'模式开关默认不为硬件转发')
                FastForwardEnable = wanpage.selelement_byName(
                    'FastForwardEnable')
                Select(FastForwardEnable).select_by_value('NatOpen')
                time.sleep(0.3)
                Select(FastForwardEnable).select_by_value('0')
                time.sleep(0.3)
                Select(FastForwardEnable).select_by_value('NatAuto')
                time.sleep(0.3)
                FastForwardMode = wanpage.selelement_byName('FastForwardMode')
                Select(FastForwardMode).select_by_value('sfNat')
                time.sleep(0.3)
                Select(FastForwardMode).select_by_value('hwNat')
        elif hwNatP == '×':
            logger.info(u'参数不支持硬件快速转发')
            try:
                self.driver.implicitly_wait(2)
                wanpage.click_FastForwardModeC()
            except AttributeError:
                logger.info('不支持硬件快速转,与参数表相符')
            else:
                CapPic(self.driver)
                logger.info(u'支持硬件快速转,与参数表不相符')
                raise Exception('支持硬件快速转,与参数表不相符')
        else:
            logger.info(u'参数表读取异常')
            logger.info(u'参数表读取值为:', hwNatP)
            raise Exception(u'参数表读取异常')

        if hwNatP == '×' and sfnatP == '√':
            logger.info(u'参数支持软件快速转发')
            try:
                self.driver.implicitly_wait(2)
                # 默认自动模式
                wanpage.click_FastForwardEnableC()
            except AttributeError:
                CapPic(self.driver)
                logger.info(u'不支持软件快速转发,与参数表不相符')
                raise Exception('不支持软件快速转发,与参数表不相符')
            else:
                enable1 = wanpage.getAttribute_byXpath(wanpage.enable1,
                                                       'selected')
                # print('enable1:', enable1)
                if enable1 != 'true':
                    logger.info(u'快速转发模式开关默认不为自动')
                    CapPic(self.driver)
                    raise Exception(u'快速转发模式开关默认不为自动')
                FastForwardEnable = wanpage.selelement_byName(
                    'FastForwardEnable')
                Select(FastForwardEnable).select_by_value('NatOpen')
                time.sleep(0.3)
                Select(FastForwardEnable).select_by_value('0')
                time.sleep(0.3)
                Select(FastForwardEnable).select_by_value('NatAuto')
        elif sfnatP == '×':
            logger.info(u'参数不支持软件快速转发')
            try:
                self.driver.implicitly_wait(2)
                wanpage.click_FastForwardEnableC()
            except AttributeError:
                logger.info('不支持软件快速转,与参数表相符')
            else:
                CapPic(self.driver)
                logger.info(u'支持软件快速转,与参数表不相符')
                raise Exception('支持软件快速转,与参数表不相符')
        self.driver.quit()
        logger.info('test_004_Fastforward passed')
コード例 #9
0
    def test_002_uttcare(self):
        u'''uttcare 解析地址为WAN口IP地址'''
        ConnectState = getAssertText('ConnectState')
        nodata = getAssertText('nodata')

        ddnsconfig = DDNSpage(self.driver, self.url)
        ddnsconfig.click_add()
        time.sleep(1)
        selDDNSProvider = ddnsconfig.selelement_byName(
            ddnsconfig.selDDNSProvider)
        Select(selDDNSProvider).select_by_value('uttcare.com')
        time.sleep(0.5)
        ddnsconfig.click_save()
        time.sleep(5)

        # 从外网配置页面获取WAN1口地址
        wanpage = NetworkConfig_wanpage(self.driver, self.url)
        wanpage.click_WANconfig()
        time.sleep(1)
        # WAN1 ip变量赋值,页面读取
        # 判断联网状态
        i = 0
        while i < 21:
            wanpage.click_refresh()
            time.sleep(1)
            list_conState = wanpage.getText_byXpath(wanpage.connectState1)
            print(str(list_conState), i)
            if str(list_conState) != ConnectState:
                time.sleep(3)
                i += 1
            else:
                break
        else:
            CapPic(self.driver)
            logger.info(u"WAN口未连接")
            raise Exception('WAN1 未连接')
        WAN1_ip = str(wanpage.getText_byXpath(wanpage.line1IP))
        time.sleep(1)

        ddnsconfig = DDNSpage(self.driver, self.url)
        # 打开网络配置 - 动态域名
        ddnsconfig.click_DDNSconfig()
        time.sleep(1)
        n = 0
        while n < 20:
            ddnsconfig.click_fresh()
            time.sleep(1)
            list_status = ddnsconfig.getText_byXpath(ddnsconfig.list_status)
            if list_status == ConnectState:
                list_ServiceProvider = ddnsconfig.getText_byXpath(
                    ddnsconfig.list_ServiceProvider)
                self.assertEqual(list_ServiceProvider,
                                 'uttcare.com',
                                 msg='服务商不为 uttcare.com')
                list_ip = ddnsconfig.getText_byXpath(ddnsconfig.list_ip)
                self.assertEqual(list_ip, WAN1_ip, msg='解析的IP与wan1口IP不一致')
                break
            else:
                time.sleep(3)
                n += 1
        else:
            raise Exception('uttcare域名未更新成功')
        # 删除已配置的域名
        ddnsconfig.click_delete()
        time.sleep(1)
        ddnsconfig.click_ok()
        time.sleep(1)
        list_nodata = str(ddnsconfig.getText_byXpath(ddnsconfig.list_nodata))
        self.assertEqual(list_nodata, nodata, msg='uttcare域名删除失败')
        self.driver.quit()
        logger.info('test_002_uttcare passed')
コード例 #10
0
    def test_003_pppoe(self):
        u'''外网配置 - PPPoE接入'''
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        PPPoEline = getAssertText('PPPoEline')
        ConnectState = getAssertText('ConnectState')

        wan_config.click_line1edit()
        time.sleep(1)
        access_mode = wan_config.selelement_byName(wan_config.connectionType)
        Select(access_mode).select_by_value('PPPOE')
        time.sleep(1)
        wan_config.input_pppoeUser('111')
        wan_config.input_pppoePass('111')
        wan_config.click_save()
        time.sleep(10)
        self.driver.quit()  # 修改接口后 可能会回到登录页面 所以关闭,再打开

        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        #断言
        list_lineType = wan_config.getText_byXpath(wan_config.line1Type)
        # print('list_lineType:',list_lineType)
        self.assertEqual(str(list_lineType), PPPoEline, msg='连接类型 不为 PPPoE接入')
        # PPPoE接入 拨号成功才会显示已连接
        i = 0
        while i < 21:
            wan_config.click_refresh()
            time.sleep(1)
            list_conState = wan_config.getText_byXpath(
                wan_config.connectState1)
            print(str(list_conState), i)
            if str(list_conState) != ConnectState:
                time.sleep(3)
                i += 1
            else:
                break
        else:
            CapPic(self.driver)
            logger.info(u"WAN口未连接")
            raise Exception('WAN1 未连接')
        i = 0
        while i < 21:
            # 判断联网 ,不能上网则报错
            # pingTestIP('114.114.114.114')
            p = pingTestIP('www.baidu.com')
            print(p, i)
            if p == 'N':
                i += 1
                time.sleep(3)
            else:
                break
        else:
            logger.info(u"connect failed")
            raise Exception('connect failed.')

        # list_connectState1 = wan_config.getText_byXpath(wan_config.connectState1)
        # print('list_connection_state:',str(list_connectState1))
        # if str(list_connectState1) != ConnectState:  # PPPoE接入 拨号成功才会显示已连接
        #     time.sleep(5)
        #     wan_config.click_refresh()
        #     time.sleep(0.5)
        #     list_connectState1 = wan_config.getText_byXpath(wan_config.connectState1)
        #     if str(list_connectState1) != ConnectState:
        #         wan_config.click_connectState1()
        #         wan_config.click_dial()
        #         time.sleep(10)
        #         wan_config.click_refresh()
        #         time.sleep(0.5)
        #         list_connectState1 = wan_config.getText_byXpath(wan_config.connectState1)
        #         if str(list_connectState1) != ConnectState:
        #             raise Exception('WAN1 未连接')
        #         else:  # 已连接
        #             time.sleep(3)
        #             pingTestIP('114.114.114.114') #避免失误
        #             pingTestIP('www.baidu.com') #避免失误
        #             p = pingTestIP('www.baidu.com')
        #             if p == 'N':
        #                 raise Exception('connect failed.')
        #     else:  # 已连接
        #         time.sleep(3)
        #         pingTestIP('114.114.114.114') #避免失误
        #         pingTestIP('www.baidu.com') #避免失误
        #         p = pingTestIP('www.baidu.com')
        #         if p == 'N':
        #             raise Exception('connect failed.')
        # else:  # 已连接
        #     time.sleep(3)
        #     pingTestIP('114.114.114.114')
        #     pingTestIP('www.baidu.com')
        #     p = pingTestIP('www.baidu.com')
        #     if p == 'N':
        #         raise Exception('connect failed.')

        self.driver.quit()
        print(u'外网配置 - PPPoE接入 验证通过')

        #改回动态接入
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_line1edit()
        time.sleep(1)
        access_mode = wan_config.selelement_byName(wan_config.connectionType)
        Select(access_mode).select_by_value('DHCP')
        wan_config.click_save()
        time.sleep(10)
        self.driver.quit()
        logger.info('test_003_pppoe passed')
コード例 #11
0
    def test_001_static(self):
        u'''五条线路固定IP地址接入'''
        # 获取5条外线的链接类型
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        linetype = getAssertText('DHCPline')
        ConnectState = getAssertText('ConnectState')
        line1_type = wan_config.getText_byXpath(wan_config.line1Type)
        line2_type = wan_config.getText_byXpath(wan_config.line2Type)
        line3_type = wan_config.getText_byXpath(wan_config.line3Type)
        line4_type = wan_config.getText_byXpath(wan_config.line4Type)
        line5_type = wan_config.getText_byXpath(wan_config.line5Type)
        print(linetype,line1_type,line2_type,line3_type,line4_type,line5_type)
        # 先改为动态接入,得到正确的IP地址及网关地址
        # WAN1
        if str(line1_type) != linetype:
            wan_config.click_line1edit()
            time.sleep(1)
            access_mode = wan_config.selelement_byName(wan_config.connectionType)
            Select(access_mode).select_by_value('DHCP')
            wan_config.click_save()
            time.sleep(10)  # 修改接口后 可能会回到登录页面 所以关闭,再打开
            self.driver.quit()
            login.loginWeb(self)  # admin账号登录
            self.driver.implicitly_wait(10)
            wan_config = NetworkConfig_wanpage(self.driver, self.url)
            wan_config.click_NetworkConfig()
            time.sleep(0.5)
            wan_config.click_WANconfig()
            time.sleep(1)
        else:
            print('wan1 动态接入')
        if str(line2_type) != linetype:
            wan_config.click_line2edit()
            time.sleep(1)
            access_mode = wan_config.selelement_byName(wan_config.connectionType)
            Select(access_mode).select_by_value('DHCP')
            wan_config.click_save()
            time.sleep(10)  # 修改接口后 可能会回到登录页面 所以关闭,再打开
            self.driver.quit()
            login.loginWeb(self)  # admin账号登录
            self.driver.implicitly_wait(10)
            wan_config = NetworkConfig_wanpage(self.driver, self.url)
            wan_config.click_NetworkConfig()
            time.sleep(0.5)
            wan_config.click_WANconfig()
            time.sleep(1)
        else:
            print('wan2 动态接入')
        if str(line3_type) != linetype:
            wan_config.click_line3edit()
            time.sleep(1)
            access_mode = wan_config.selelement_byName(wan_config.connectionType)
            Select(access_mode).select_by_value('DHCP')
            wan_config.click_save()
            time.sleep(10)  # 修改接口后 可能会回到登录页面 所以关闭,再打开
            self.driver.quit()
            login.loginWeb(self)  # admin账号登录
            self.driver.implicitly_wait(10)
            wan_config = NetworkConfig_wanpage(self.driver, self.url)
            wan_config.click_NetworkConfig()
            time.sleep(0.5)
            wan_config.click_WANconfig()
            time.sleep(1)
        else:
            print('wan3 动态接入')
        if str(line4_type) != linetype:
            wan_config.click_line4edit()
            time.sleep(1)
            access_mode = wan_config.selelement_byName(wan_config.connectionType)
            Select(access_mode).select_by_value('DHCP')
            wan_config.click_save()
            time.sleep(10)  # 修改接口后 可能会回到登录页面 所以关闭,再打开
            self.driver.quit()
            login.loginWeb(self)  # admin账号登录
            self.driver.implicitly_wait(10)
            wan_config = NetworkConfig_wanpage(self.driver, self.url)
            wan_config.click_NetworkConfig()
            time.sleep(0.5)
            wan_config.click_WANconfig()
            time.sleep(1)
        else:
            print('wan4 动态接入')
        if str(line5_type) != linetype:
            wan_config.click_line5edit()
            time.sleep(1)
            access_mode = wan_config.selelement_byName(wan_config.connectionType)
            Select(access_mode).select_by_value('DHCP')
            wan_config.click_save()
            time.sleep(10)  # 修改接口后 可能会回到登录页面 所以关闭,再打开
            self.driver.quit()
            login.loginWeb(self)  # admin账号登录
            self.driver.implicitly_wait(10)
            wan_config = NetworkConfig_wanpage(self.driver, self.url)
            wan_config.click_NetworkConfig()
            time.sleep(0.5)
            wan_config.click_WANconfig()
            time.sleep(1)
        else:
            print('wan5 动态接入')
        # 断言
        n = 0
        while n < 30:
            wan_config.click_refresh()
            time.sleep(1)
            list_connectState1 = wan_config.getText_byXpath(wan_config.connectState1)
            list_connectState2 = wan_config.getText_byXpath(wan_config.connectState2)
            list_connectState3 = wan_config.getText_byXpath(wan_config.connectState3)
            list_connectState4 = wan_config.getText_byXpath(wan_config.connectState4)
            list_connectState5 = wan_config.getText_byXpath(wan_config.connectState5)
            print(str(list_connectState1), str(list_connectState2), str(list_connectState3),str(list_connectState4),
                  str(list_connectState5))
            list_connectState = [str(list_connectState1), str(list_connectState2), str(list_connectState3),
                                 str(list_connectState4),str(list_connectState5)]
            # 动态接入 未获取到地址/wan口线未接入 都是未连接
            if all(t == ConnectState for t in  list_connectState):
                print('WAN口均已获取到地址', n)
                break
            else:
                time.sleep(2)
                n += 1
        else:
            raise Exception('WAN口未获取到地址')

        # 获取三个wan口IP、网关、mac
        WAN1_ip = wan_config.getText_byXpath(wan_config.line1IP)
        WAN2_ip = wan_config.getText_byXpath(wan_config.line2IP)
        WAN3_ip = wan_config.getText_byXpath(wan_config.line3IP)
        WAN4_ip = wan_config.getText_byXpath(wan_config.line4IP)
        WAN5_ip = wan_config.getText_byXpath(wan_config.line5IP)
        # print('WAN1_ip=',WAN1_ip,'WAN2_ip=',WAN2_ip,'WAN3_ip=',WAN3_ip,'WAN4_ip=',WAN4_ip)
        WAN1_gw = wan_config.getText_byXpath(wan_config.line1gw)
        WAN2_gw = wan_config.getText_byXpath(wan_config.line2gw)
        WAN3_gw = wan_config.getText_byXpath(wan_config.line3gw)
        WAN4_gw = wan_config.getText_byXpath(wan_config.line4gw)
        WAN5_gw = wan_config.getText_byXpath(wan_config.line5gw)
        # print('WAN1_gw=',WAN1_gw)
        WAN1_dns = wan_config.getText_byXpath(wan_config.line1Dns)
        WAN2_dns = wan_config.getText_byXpath(wan_config.line2Dns)
        WAN3_dns = wan_config.getText_byXpath(wan_config.line3Dns)
        WAN4_dns = wan_config.getText_byXpath(wan_config.line4Dns)
        WAN5_dns = wan_config.getText_byXpath(wan_config.line5Dns)
        # print('WAN1_dns=',WAN1_dns)
        line1_mac = str(wan_config.getText_byXpath(wan_config.line1Mac))
        # print('WAN1_dns=',line1_mac)
        line2_mac = str((wan_config.getText_byXpath(wan_config.line2Mac)))
        # print('WAN1_dns=',line2_mac)
        line3_mac = str((wan_config.getText_byXpath(wan_config.line3Mac)))
        # print('WAN1_dns=',line3_mac)
        line4_mac = str((wan_config.getText_byXpath(wan_config.line4Mac)))
        line5_mac = str((wan_config.getText_byXpath(wan_config.line5Mac)))

        # 改为固定接入
        # 将wan1口的IP/网关/dns 拿来输入
        wan_config.click_line1edit()
        time.sleep(1)
        access_mode = wan_config.selelement_byName(wan_config.connectionType)
        Select(access_mode).select_by_value('STATIC')
        time.sleep(1)
        wan_config.input_staticIp(WAN1_ip)
        wan_config.input_staticGateway(WAN1_gw)
        wan_config.input_staticPriDns(WAN1_dns)
        wan_config.click_save()
        time.sleep(10)
        self.driver.quit()  # 修改接口后 可能会回到登录页面 所以关闭,再打开
        # WAN2
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_line2edit()
        time.sleep(1)
        access_mode = wan_config.selelement_byName(wan_config.connectionType)
        Select(access_mode).select_by_value('STATIC')
        time.sleep(1)
        wan_config.input_staticIp(WAN2_ip)
        wan_config.input_staticGateway(WAN2_gw)
        wan_config.input_staticPriDns(WAN2_dns)
        wan_config.click_save()
        time.sleep(10)
        self.driver.quit()  # 修改接口后 可能会回到登录页面 所以关闭,再打开
        # WAN3
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_line3edit()
        time.sleep(1)
        access_mode = wan_config.selelement_byName(wan_config.connectionType)
        Select(access_mode).select_by_value('STATIC')
        time.sleep(1)
        wan_config.input_staticIp(WAN3_ip)
        wan_config.input_staticGateway(WAN3_gw)
        wan_config.input_staticPriDns(WAN3_dns)
        wan_config.click_save()
        time.sleep(10)
        self.driver.quit()  # 修改接口后 可能会回到登录页面 所以关闭,再打开
        # WAN4
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_line4edit()
        time.sleep(1)
        access_mode = wan_config.selelement_byName(wan_config.connectionType)
        Select(access_mode).select_by_value('STATIC')
        time.sleep(1)
        wan_config.input_staticIp(WAN4_ip)
        wan_config.input_staticGateway(WAN4_gw)
        wan_config.input_staticPriDns(WAN4_dns)
        wan_config.click_save()
        time.sleep(10)
        self.driver.quit()  # 修改接口后 可能会回到登录页面 所以关闭,再打开
        # WAN5
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_line5edit()
        time.sleep(1)
        access_mode = wan_config.selelement_byName(wan_config.connectionType)
        Select(access_mode).select_by_value('STATIC')
        time.sleep(1)
        wan_config.input_staticIp(WAN5_ip)
        wan_config.input_staticGateway(WAN5_gw)
        wan_config.input_staticPriDns(WAN5_dns)
        wan_config.click_save()
        time.sleep(10)
        self.driver.quit()  # 修改接口后 可能会回到登录页面 所以关闭,再打开

        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        # 断言
        n = 0
        while n < 30:
            wan_config.click_refresh_s()
            time.sleep(1)
            list_connectState1 = wan_config.getText_byXpath(wan_config.connectState1)
            list_connectState2 = wan_config.getText_byXpath(wan_config.connectState2)
            list_connectState3 = wan_config.getText_byXpath(wan_config.connectState3)
            list_connectState4 = wan_config.getText_byXpath(wan_config.connectState4)
            list_connectState5 = wan_config.getText_byXpath(wan_config.connectState5)
            print(str(list_connectState1), str(list_connectState2), str(list_connectState3), str(list_connectState4),
                  str(list_connectState5))
            list_connectState = [str(list_connectState1), str(list_connectState2), str(list_connectState3),
                                 str(list_connectState4), str(list_connectState5)]
            # 动态接入 未获取到地址/wan口线未接入 都是未连接
            if all(t == ConnectState for t in list_connectState):
                print('WAN口均已连接', n)
                break
            else:
                time.sleep(2)
                n += 1
        else:
            raise Exception('WAN口未连接')

        # 处理wan口的mac地址
        # 字母变大写
        line1_mac1 = line1_mac.upper()
        line2_mac1 = line2_mac.upper()
        line3_mac1 = line3_mac.upper()
        line4_mac1 = line4_mac.upper()
        line5_mac1 = line5_mac.upper()
        # 加冒号
        line1_mac2 = line1_mac1[0:2] + ':' + line1_mac1[2:4] + ':' + line1_mac1[4:6] + ':' + line1_mac1[
                                                                                             6:8] + ':' + line1_mac1[
                                                                                                          8:10] + ':' + line1_mac1[
                                                                                                                        10:]
        line2_mac2 = line2_mac1[0:2] + ':' + line2_mac1[2:4] + ':' + line2_mac1[4:6] + ':' + line2_mac1[
                                                                                             6:8] + ':' + line2_mac1[
                                                                                                          8:10] + ':' + line2_mac1[
                                                                                                                        10:]
        line3_mac2 = line3_mac1[0:2] + ':' + line3_mac1[2:4] + ':' + line3_mac1[4:6] + ':' + line3_mac1[
                                                                                             6:8] + ':' + line3_mac1[
                                                                                                          8:10] + ':' + line3_mac1[
                                                                                                                        10:]
        line4_mac2 = line4_mac1[0:2] + ':' + line4_mac1[2:4] + ':' + line4_mac1[4:6] + ':' + line4_mac1[
                                                                                             6:8] + ':' + line4_mac1[
                                                                                                          8:10] + ':' + line4_mac1[
                                                                                                                        10:]
        line5_mac2 = line5_mac1[0:2] + ':' + line5_mac1[2:4] + ':' + line5_mac1[4:6] + ':' + line5_mac1[
                                                                                             6:8] + ':' + line5_mac1[
                                                                                                          8:10] + ':' + line5_mac1[
                                                                                                                        10:]
        print(line1_mac2, line2_mac2, line3_mac2, line4_mac2, line5_mac2)

        # telnet获取接口名称及确认默认路由
        # 获取接口名称
        hostip = gettelnet('host')
        port = gettelnet('port')
        username = bytes(getweb('User'), encoding="utf8")
        password = bytes(getweb('Passwd'), encoding="utf8")
        # 获取接口名称
        tn = telnetlib.Telnet(host=hostip, port=port,timeout=10)
        tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        tn.read_until(b'login:'******'Password:'******'#')
        tn.write(b'ifconfig | grep eth' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 获取WAN口对应接口名称
        result1 = result[3:-9]
        # print(result1)
        result2 = result1.split(r'\r\n')
        print('result2:', result2)

        for i in range(len(result2)):
            if line1_mac2 in result2[i]:
                result2_num = (result2[i])
                print(result2_num)
                line1_Interface_name = result2_num.split()[0]
                print(line1_Interface_name)
            if line2_mac2 in result2[i]:
                result2_num = (result2[i])
                print(result2_num)
                line2_Interface_name = result2_num.split()[0]
                print(line2_Interface_name)
            if line3_mac2 in result2[i]:
                result2_num = (result2[i])
                print(result2_num)
                line3_Interface_name = result2_num.split()[0]
                print(line3_Interface_name)
            if line4_mac2 in result2[i]:
                result2_num = (result2[i])
                print(result2_num)
                line4_Interface_name = result2_num.split()[0]
                print(line4_Interface_name)
            if line5_mac2 in result2[i]:
                result2_num = (result2[i])
                print(result2_num)
                line5_Interface_name = result2_num.split()[0]
                print(line5_Interface_name)
        if line1_Interface_name == None:
            raise Exception('获取wan1口对应接口名称失败')
        if line2_Interface_name == None:
            raise Exception('获取wan2口对应接口名称失败')
        if line3_Interface_name == None:
            raise Exception('获取wan3口对应接口名称失败')
        if line4_Interface_name == None:
            raise Exception('获取wan4口对应接口名称失败')
        if line5_Interface_name == None:
            raise Exception('获取wan5口对应接口名称失败')
        # 确认默认路由情况
        tn.write(b'ip route' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 获取WAN1对应接口名称
        result1 = result[2:-7]
        print('result1', result1)
        result2 = result1.split(r'\r\n')
        print('result2', result2)

        wan1route = 'dev ' + line1_Interface_name + ' weight '
        wan2route = 'dev ' + line2_Interface_name + ' weight '
        wan3route = 'dev ' + line3_Interface_name + ' weight '
        wan4route = 'dev ' + line4_Interface_name + ' weight '
        wan5route = 'dev ' + line5_Interface_name + ' weight '
        print('wan1route:', wan1route, 'wan2route:', wan2route, 'wan3route:', wan3route, 'wan4route:', wan4route,
              'wan5route:', wan5route)

        for i in range(len(result2)):
            if wan1route in result2[i]:
                wan1route_status = not None
                print('wan1路由在')
            if wan2route in result2[i]:
                wan2route_status = not None
                print('wan2路由在')
            if wan3route in result2[i]:
                wan3route_status = not None
                print('wan3路由在')
            if wan4route in result2[i]:
                wan4route_status = not None
                print('wan4路由在')
            if wan5route in result2[i]:
                wan5route_status = not None
                print('wan5路由在')
        if wan1route_status == None:
            raise Exception('wan1默认路由不存在')
        if wan2route_status == None:
            raise Exception('wan2默认路由不存在')
        if wan3route_status == None:
            raise Exception('wan3默认路由不存在')
        if wan4route_status == None:
            raise Exception('wan4默认路由不存在')
        if wan5route_status == None:
            raise Exception('wan5默认路由不存在')

        tn.close()  # tn.write('exit\n')
        self.driver.quit()
        logger.info('test_001_static passed')
コード例 #12
0
    def test_004_WanAcessFTP(self):
        u'''WAN口访问FTP'''
        ftpSmaba = NetworkSharingPage(self.driver, self.url)
        #1、验证未打开 ‘wan口访问’ 无法从wan访问FTP
        #1)验证未打开
        WANEnable = str(
            self.driver.find_element_by_name('WANEnable').get_attribute(
                'checked'))
        print(WANEnable)
        if WANEnable == 'true':
            self.driver.find_element_by_name('WANEnable').click()
            ftpSmaba.click_save()
            time.sleep(1)
            ftpSmaba.click_NetworkSharing2()  # 点击网络共享子页面
            time.sleep(1)
            WANEnable = str(
                self.driver.find_element_by_name('WANEnable').get_attribute(
                    'checked'))
            self.assertEqual(WANEnable, 'None', msg='允许wan口访问 关闭失败')
        #2)从外网配置页面获取WAN1口地址
        wanpage = NetworkConfig_wanpage(self.driver, self.url)
        wanpage.click_WANconfig()
        time.sleep(1)
        # WAN1 ip变量赋值,页面读取
        WAN1_ip = str(wanpage.getText_byXpath(wanpage.line1IP))
        time.sleep(1)
        #3) 更改pc 交换机接口与wan口/上联口通
        swconfig.test_LanToWan(self)
        # 重新获取地址 应获取到上层网关下发的地址
        pcaddr = str(socket.gethostbyname(socket.getfqdn(
            socket.gethostname())))
        # 调用bat脚本 IP地址释放
        os.system('%s' % (batpath + 'ipconfig_release.bat'))
        time.sleep(2)
        pcaddr1 = str(
            socket.gethostbyname(socket.getfqdn(socket.gethostname())))
        print(pcaddr1)
        if pcaddr1 != str(pcaddr):
            print('IP地址已释放')
        else:
            time.sleep(3)
        time.sleep(2)
        # 重新获取地址
        os.system('%s' % (batpath + 'ipconfig_renew.bat'))
        time.sleep(5)
        n = 0
        while n < 30:
            # 获取本机ip 默认有线地址,有线断开会显示无线
            pcaddr = socket.gethostbyname(socket.getfqdn(socket.gethostname()))
            print(pcaddr, n)
            if '192.168.' not in str(pcaddr):
                time.sleep(2)
                n += 1
            else:
                print('IP地址已自动获取成功', n)
                break
        else:
            raise Exception('未获取到地址')
        time.sleep(2)
        #4)尝试访问FTP
        # ftp验证登录
        IP = WAN1_ip
        Port = 21
        ftp = ftplib.FTP()
        ftp.encoding = 'utf-8'
        try:
            ftp.connect(host=IP, port=Port, timeout=5)
            ftp.login(user='******')  # 相当于没有验证账号密码
        except socket.error or socket.gaierror:
            print("未开启“WAN口访问开关”无法访问FTP服务 验证通过")
        except ftplib.error_perm:  # 当前未开启wan口访问,wan口访问时候会弹出账号密码框,但输入会提示密码错误
            print("未开启“WAN口访问开关”访问FTP服务会密码错误 验证通过")
        else:
            raise Exception("未开启“WAN口访问开关” 依旧可以访问FTP服务")
        ftp.quit()
        #5)改为lan口 并重新获取地址
        switchURL2 = gettelnet('switchURL2')
        # 调用bat脚本 地址修改为 192.168.34.39 网关192.168.34.1
        os.system('%s' % (batpath + 'changeStaticIP3_34duan.bat'))
        time.sleep(5)
        n = 0
        while n < 30:
            # 获取本机ip 默认有线地址,有线断开会显示无线
            pcaddr = socket.gethostbyname(socket.getfqdn(socket.gethostname()))
            print(pcaddr, n)
            if str(pcaddr) != '192.168.34.39':
                time.sleep(2)
                n += 1
            else:
                print('地址已修改为地址 192.168.34.39', n)
                break
        else:
            raise Exception('地址修改为192.168.34.39 失败')
        # 更改pc 交换机接口与lan口通
        p = pingTestIP(switchURL2)
        if p == 'Y':
            swconfig.test_WanToLan(self)
        # 将IP改回自动获取 应获取到被测设备下发的地址
        os.system('%s' % (batpath + 'changeDhcpIp.bat'))
        n = 0
        while n < 30:
            # 获取本机ip 默认有线地址,有线断开会显示无线
            pcaddr_new = socket.gethostbyname(
                socket.getfqdn(socket.gethostname()))
            print(pcaddr_new, n)
            if '192.168.' not in str(pcaddr_new):
                time.sleep(2)
                n += 1
            else:
                print('IP地址已自动获取成功', n)
                break
        else:
            raise Exception('未获取到地址')
        time.sleep(3)
        #2 验证打开 ‘wan口访问’ 可以从wan口访问FTP
        #1)打开
        ftpSmaba = NetworkSharingPage(self.driver, self.url)
        ftpSmaba.click_NetworkSharing()
        time.sleep(1)
        ftpSmaba.click_NetworkSharing2()  # 点击网络共享子页面
        time.sleep(1)
        self.driver.find_element_by_name('WANEnable').click()
        ftpSmaba.click_save()
        time.sleep(2)
        WANEnable = self.driver.find_element_by_name(
            'WANEnable').get_attribute('checked')
        self.assertEqual(WANEnable, 'true', msg='允许wan口访问 启用失败')
        #2) 更改pc 交换机接口与wan口/上联口通
        swconfig.test_LanToWan(self)
        # 重新获取地址 应获取到上层网关下发的地址
        pcaddr = str(socket.gethostbyname(socket.getfqdn(
            socket.gethostname())))
        # 调用bat脚本 IP地址释放
        os.system('%s' % (batpath + 'ipconfig_release.bat'))
        time.sleep(2)
        pcaddr1 = str(
            socket.gethostbyname(socket.getfqdn(socket.gethostname())))
        print(pcaddr1)
        if pcaddr1 != str(pcaddr):
            print('IP地址已释放')
        else:
            time.sleep(3)
        time.sleep(2)
        # 重新获取地址
        os.system('%s' % (batpath + 'ipconfig_renew.bat'))
        time.sleep(5)
        n = 0
        while n < 30:
            # 获取本机ip 默认有线地址,有线断开会显示无线
            pcaddr = socket.gethostbyname(socket.getfqdn(socket.gethostname()))
            print(pcaddr, n)
            if '192.168.' not in str(pcaddr):
                time.sleep(2)
                n += 1
            else:
                print('IP地址已自动获取成功', n)
                break
        else:
            raise Exception('未获取到地址')
        time.sleep(2)
        # 3)ftp验证登陆
        try:
            ftp.connect(host=IP, port=Port, timeout=5)
        except socket.error or socket.gaierror:
            raise Exception("无法访问FTP服务")
        try:
            ftp.login(user='******')  # 相当于没有验证账号密码
        except ftplib.error_perm:
            raise Exception("FTP账号密码验证错误")
        ftpFile = ftp.nlst('1')  # 获取指定目录下的文件
        print('ftpFile', ftpFile)
        ftp.quit()

        self.driver.quit()
        logger.info('test_004_WanaAcess passed')
コード例 #13
0
 def test_004_changeMAC(self):
     u'''MAC地址修改'''
     CannotbeblankA = getAssertText('CannotbeblankA')
     lanpage = NetworkConfig_LANpage(self.driver, self.url)
     lanpage.click_NetworkConfig()
     time.sleep(0.5)
     lanpage.click_LANconfig()
     time.sleep(1)
     lanpage.click_globalconfig()
     time.sleep(1)
     # lan口MAC 清空lan mac的值保存 确认是否可以修改
     lanpage.clear_mac()
     time.sleep(0.5)
     lanpage.click_save()
     time.sleep(0.5)
     lan_tips = str(lanpage.getText_byXpath(lanpage.lan_tips))
     self.assertIn(CannotbeblankA, lan_tips, msg='lan口mac地址清空保存提示错误')
     print('lan口mac地址更改 验证通过')
     # wan1口MAC 清空lan mac的值保存 确认是否可以修改
     wanpage = NetworkConfig_wanpage(self.driver, self.url)
     wanpage.click_WANconfig()
     time.sleep(1)
     wanpage.click_line1edit()
     time.sleep(1)
     connectionType = wanpage.selelement_byName(wanpage.connectionType)
     Select(connectionType).select_by_value('DHCP')
     time.sleep(0.5)
     wanpage.clear_line1editmac()
     time.sleep(0.5)
     wanpage.click_save()
     time.sleep(0.5)
     wan_tips = str(wanpage.getText_byXpath(wanpage.wan_tips))
     self.assertIn(CannotbeblankA, lan_tips, msg='wan口mac地址清空保存提示错误')
     print('wan口mac地址更改 验证通过')
     self.driver.quit()
     logger.info('test_004_changeMAC passed')
コード例 #14
0
    def test_003_udp69(self):
        u'''验证udp69 映射'''
        #获取本机地址
        pcaddr = socket.gethostbyname(socket.gethostname())

        # 打开tftp32.exe,
        # 注意:tftp32打开后的目录是由 由哪个脚本执行 所在的路径决定
        #直接运行该脚本,则tftp32的目录是‘test_003_udp69’所在的‘D:\python\SEWEB\3.1.1Router\test_case\Port_mapping’
        #由all_test.py或者ProductModel_test.py调用执行,则目录为‘D:\python\SEWEB\3.1.1Router\run’
        #因此 需把握好 对应目录中包含上传的文件,此脚本设定上传的文件为'tftpd32.exe'
        handle = win32process.CreateProcess(
            r"D:\python\SEWEB\3.1.1Router\test_case\tftpd32.exe", '', None,
            None, 0, win32process.CREATE_NO_WINDOW, None, None,
            win32process.STARTUPINFO())  # 打开tftp32.exe,获得其句柄

        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        staticMapping = staticMappingPage(self.driver, self.url)
        # 配置映射
        staticMapping.click_NetworkConfig()
        time.sleep(0.5)
        staticMapping.click_portMapping()
        time.sleep(1)
        staticMapping.click_add()
        time.sleep(1)
        staticMapping.input_IDs('statictest')
        staticMapping.input_IPs(pcaddr)
        Selprotocols = staticMapping.selelement_byName(staticMapping.Protocols)
        Select(Selprotocols).select_by_value('2')  # 1:tcp 2:udp 3:tcp/udp
        time.sleep(0.5)
        staticMapping.input_inS('69')
        staticMapping.input_inE('69')
        staticMapping.input_outS('69')
        staticMapping.input_outE('69')
        staticMapping.click_save()
        time.sleep(1)
        # 断言
        list_port = str(staticMapping.getText_byXpath(staticMapping.list_port))
        print(list_port)
        self.assertEqual(list_port, '69~69:69~69', msg='端口对应关系不一致')
        print('tcp69映射 已添加')

        # 从外网配置页面获取WAN1口地址
        wanpage = NetworkConfig_wanpage(self.driver, self.url)
        wanpage.click_WANconfig()
        time.sleep(1)
        # WAN1 gw变量赋值,页面读取
        # 判断联网状态
        i = 0
        while i < 21:
            wanpage.click_refresh()
            time.sleep(1)
            list_conState = wanpage.getText_byXpath(wanpage.connectState1)
            print(str(list_conState), i)
            if str(list_conState) != ConnectState:
                time.sleep(3)
                i += 1
            else:
                break
        else:
            CapPic(self.driver)
            logger.info(u"WAN口未连接")
            raise Exception('WAN1 未连接')
        WAN1_gw = str(wanpage.getText_byXpath(wanpage.line1gw))
        # print('WAN1_gw=',WAN1_gw)
        time.sleep(1)
        # WAN1_gw = '192.168.11.1'
        # 连接Telnet服务器
        hostip = WAN1_gw
        port = gettelnet('port')
        username = bytes(getweb('User'), encoding="utf8")
        password = bytes(getweb('Passwd'), encoding="utf8")
        # 获取接口名称
        tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
        tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        # 输入登录用户名
        tn.read_until(b'login:'******'Password:'******'#')
        tn.write(b"rm tftpd32.exe lanip" + b'\n')
        tn.read_until(b'#')
        tn.write(
            b"cat /proc/net/nf_conntrack |grep tcp | grep `uttcli get interface 0 ethernet static ip`| grep 'dport=60023' | awk '{print $7}' |awk -F'=' '{print $2}' | sed -n '1p' >lanip"
            + b'\n')
        tn.read_until(b'#')
        tn.write(b"lanip=`cat lanip`" + b'\n')
        tn.read_until(b'#')
        tn.write(b'tftp -gr tftpd32.exe `cat lanip` 69' + b'\n')
        time.sleep(1)
        # print('1')
        tn.read_until(b'#')
        # print('2')
        tn.write(b"ls | grep tftpd32" + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)

        # 后台实际应有的结果
        # result1=  b' ls | grep tftpd32\r\ntftpd32.exe\r\n# '
        # 判断
        if 'tftpd32.exe' in result:
            print('ftfp 验证成功')
        else:
            raise Exception('ftfp 验证失败')  # 如果没有则报错
        tn.close()

        win32process.TerminateProcess(
            handle[0], 0)  # 关闭tftp32,注意脚本执行前关闭所有的tftp32进程 否则不能关闭会报错

        self.driver.quit()

        logger.info('test_003_udp69 passed')
コード例 #15
0
    def tearDown(self):
        #修改回默认 以访中间出错
        wanpage = NetworkConfig_wanpage(self.driver, self.url)
        save = 0
        enable1 = wanpage.getAttribute_byXpath(wanpage.enable1, 'selected')
        if hwNatP == '√':  # 包含硬件转转发开关
            if enable1 != 'true':
                FastForwardEnable = wanpage.selelement_byName('FastForwardEnable')
                Select(FastForwardEnable).select_by_value('NatAuto')
                save = 1
            enable2 = wanpage.getAttribute_byXpath(wanpage.enable2, 'selected')
            if enable2 != 'true':
                FastForwardMode = wanpage.selelement_byName('FastForwardMode')
                Select(FastForwardMode).select_by_value('hwNat')
                save = 1
        else:
            if enable1 != 'true':
                FastForwardEnable = wanpage.selelement_byName('FastForwardEnable')
                Select(FastForwardEnable).select_by_value('NatAuto')
                save = 1
        if save == 1:
            wanpage.click_save()
            time.sleep(2)
            # 等待弹窗提示成功
            i = 0
            while i < 80:
                try:
                    self.driver.implicitly_wait(1)
                    wanpage.find_tipsshowin()
                except NoSuchElementException:
                    time.sleep(1)
                    i = i + 1
                    print(i)
                else:
                    tips = str(wanpage.getAttribute_byClass(wanpage.tipsshowin, 'tip-sign'))
                    print(tips, i)
                    if tips != 'success':
                        CapPic(self.driver)
                        logger.info(u'极速模式保存 异常')
                        raise Exception(u'极速模式保存 异常')
                    break
            else:
                raise Exception(u'极速模式保存 未弹出提示框')
            time.sleep(2)
        self.driver.quit()

        logger.info('tearDown over')
        logger.info('%s' % ('=' * 50))
コード例 #16
0
    def test_001_tcp80(self):
        u'''验证tcp80 映射'''

        # #改用另外设置的server pc
        # # 打开Everthing,Evering充当80server(需事先设置开启相关http服务)
        # handle = win32process.CreateProcess("D:\Program Files\Everything\Everything.exe", '', None,
        #                                     None, 0, win32process.CREATE_NO_WINDOW, None, None,
        #                                     win32process.STARTUPINFO())  # 打开Evering,获得其句柄
        # #获取本机地址
        # pcaddr=socket.gethostbyname(socket.gethostname())

        #通过用户状态获取httpserver的IP地址
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        status = Organization_userStatusPage(self.driver, self.url)
        status.click_UserManage()
        time.sleep(0.5)
        status.click_userstatus()
        time.sleep(1)
        # 将页面刷新按钮改成“手动”
        sel = status.selelement_byXpath(status.selmanual)
        Select(sel).select_by_value('manual')
        time.sleep(1)
        status.click_refreshtable()
        time.sleep(1)
        status.input_search(serverPcMac)
        status.click_searchb()
        time.sleep(1)
        try:
            serverIP = status.getText_byXpath(status.list_IP1)
        except NoSuchElementException:
            raise Exception(u'用户状态中未找到server IP')
            # print(serverIP)
        else:
            try:
                telnetlib.Telnet(serverIP, port=80, timeout=10)
                print('server tcp80端口已开启')
            except socket.timeout:
                logger.info(u'内网方向无法访问server TCP80端口')
                raise Exception(u'内网方向无法访问server TCP80端口')

        staticMapping = staticMappingPage(self.driver, self.url)
        #配置映射
        staticMapping.click_NetworkConfig()
        time.sleep(0.5)
        staticMapping.click_portMapping()
        time.sleep(1)
        staticMapping.click_add()
        time.sleep(1)
        staticMapping.input_IDs('statictest')
        staticMapping.input_IPs(serverIP)
        Selprotocols = staticMapping.selelement_byName(staticMapping.Protocols)
        Select(Selprotocols).select_by_value('1')  #1:tcp 2:udp 3:tcp/udp
        time.sleep(0.5)
        staticMapping.input_inS('80')
        time.sleep(0.5)
        staticMapping.input_inE('80')
        time.sleep(1)
        staticMapping.input_outS('80')
        time.sleep(0.5)
        staticMapping.input_outE('80')
        staticMapping.click_save()
        time.sleep(1)
        #断言
        list_port = str(staticMapping.getText_byXpath(staticMapping.list_port))
        print(list_port)
        self.assertEqual(list_port, '80~80:80~80', msg='端口对应关系不一致')
        print('tcp80映射 已添加')

        # 从外网配置页面获取WAN1口地址
        wanpage = NetworkConfig_wanpage(self.driver, self.url)
        wanpage.click_WANconfig()
        time.sleep(1)
        # WAN1 ip变量赋值,页面读取
        # 判断联网状态
        i = 0
        while i < 21:
            wanpage.click_refresh()
            time.sleep(1)
            list_conState = wanpage.getText_byXpath(wanpage.connectState1)
            print(str(list_conState), i)
            if str(list_conState) != ConnectState:
                time.sleep(3)
                i += 1
            else:
                break
        else:
            CapPic(self.driver)
            logger.info(u"WAN口未连接")
            raise Exception('WAN1 未连接')
        WAN1_ip = str(wanpage.getText_byXpath(wanpage.line1IP))
        print('WAN1_ip=', WAN1_ip)
        time.sleep(1)
        self.driver.quit()
        url = 'http://' + str(WAN1_ip)
        print(url)

        if CPUmodel == 'Qualcomm':
            # 部分型号,如高通,因为芯片问题必须关闭wan口mac学习功能,原mac未清除之前无法从wan口访问路由器
            # 这里需要设置计划任务2分钟后清空原pc的arp缓存
            hostip = gettelnet('host')
            port = gettelnet('port')
            username = bytes(getweb('User'), encoding="utf8")
            password = bytes(getweb('Passwd'), encoding="utf8")
            tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
            tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
            # 输入登录用户名
            tn.read_until(b'login:'******'Password:'******'#')
            tn.write(b"uptime" + b"\n")
            # 输出结果,判断
            time.sleep(1)
            result = str(tn.read_very_eager())  # 只会存最后一条命令的结果
            print('-------------------输出结果------------------------')
            # 命令执行结果
            print('result:', result)
            result1 = str(result.split(r'\r\n')[1]).split(r':')
            print(result1[1])
            tn.close()  # tn.write('exit\n')
            if int(result1[1]) + 2 < 60:
                hour = result1[0]
                min = int(result1[1]) + 2
            else:
                if int(result1[0]) + 1 < 24:
                    hour = int(result1[0]) + 1
                    min = '0' + str((int(result1[1]) + 2) - 60)
                else:
                    hour = '0' + str(int(result1[0]) + 1 - 24)
                    min = '0' + str((int(result1[1]) + 2) - 60)
            print(hour)
            print(min)
            pcaddr = str(
                socket.gethostbyname(socket.getfqdn(socket.gethostname())))
            cmd = "echo '%s %s * * * arp -d %s' > cmd " % (min, hour, pcaddr)
            print(cmd)
            cmd = bytes(cmd, encoding='utf8')
            tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
            tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
            # 输入登录用户名
            tn.read_until(b'login:'******'Password:'******'#')
            tn.write(cmd + b"\n")
            tn.read_until(b'#')
            tn.write(b"cat cmd >> /var/spool/cron/crontabs/admin" + b"\n")
            tn.read_until(b'#')
            tn.write(b"killall crond" + b"\n")
            tn.read_until(b'#')
            tn.write(b"crond &" + b"\n")
            tn.read_until(b'#')
            tn.write(b"cat /var/spool/cron/crontabs/admin" + b"\n")
            # 输出结果,判断
            time.sleep(1)
            result = str(tn.read_very_eager())  # 只会存最后一条命令的结果
            print('-------------------输出结果------------------------')
            # 命令执行结果
            print('result:', result)
            if 'adp -d' in result:
                print('计划任务已写入')

        # 更改pc 交换机接口与wan口/上联口通
        swconfig.test_LanToWan(self)
        if CPUmodel == 'Qualcomm':
            time.sleep(120)  #等待计划任务执行
        # 重新获取地址 应获取到上层网关下发的地址
        pcaddr = str(socket.gethostbyname(socket.getfqdn(
            socket.gethostname())))
        # 调用bat脚本 IP地址释放
        os.system('%s' % (batpath + 'ipconfig_release.bat'))
        time.sleep(2)
        pcaddr1 = str(
            socket.gethostbyname(socket.getfqdn(socket.gethostname())))
        print(pcaddr1)
        if pcaddr1 != str(pcaddr):
            print('IP地址已释放')
        else:
            time.sleep(3)
        time.sleep(2)
        # 将IP改回自动获取(设置dns为自动获取)
        # 调用bat脚本
        os.system('%s' % (batpath + 'ipconfig_renew.bat'))
        time.sleep(5)
        n = 0
        while n < 30:
            # 获取本机ip 默认有线地址,有线断开会显示无线
            pcaddr = socket.gethostbyname(socket.getfqdn(socket.gethostname()))
            print(pcaddr, n)
            if '192.168.' not in str(pcaddr):
                time.sleep(2)
                n += 1
            else:
                print('IP地址已自动获取成功', n)
                break
        else:
            raise Exception('未获取到地址')

        print('url:', url)
        self.driver = webdriver.Chrome()
        # self.driver.maximize_window()
        self.driver.implicitly_wait(10)
        self.driver.get(url)
        title = self.driver.title
        print(title)
        self.assertEqual(title,
                         '探索昆虫世界,用老蛙24mm f/14微距镜头试试 - 摄影,镜头 - IT之家',
                         msg='http访问有误')
        self.driver.quit()

        # win32process.TerminateProcess(handle[0], 0)  # 关闭Everying,没有能关闭掉就不关了
        logger.info('test_001_tcp80 passed')
コード例 #17
0
ファイル: ConfigGuide.py プロジェクト: sanwzhou/SEWEB
    def test_001_dhcp(self):
        u'''配置向导 - 动态接入'''
        guide = ConfigGuidepage(self.driver, self.url)
        linetype = getAssertText('DHCPline')
        ConnectState = getAssertText('ConnectState')
        # 进入配置向导
        guide.click_configGuide()
        time.sleep(0.5)
        guide.click_next()
        time.sleep(1)
        connectionTypew = guide.selelement_byName(guide.connectionTypew)
        Select(connectionTypew).select_by_value('DHCP')
        try:
            self.driver.implicitly_wait(2)
            guide.find_okey()
        except NoSuchElementException:
            print('设备支持无线')
            if support2 != '--':
                logger.info(u'参数支持2.4G')
                logger.info(u'支持2.4G,与参数表相符')
            else:
                CapPic(self.driver)
                logger.info(u'支持2.4G,与参数表不相符')
                raise Exception('支持2.4G,与参数表不相符')
            guide.click_next()
            time.sleep(1)
            guide.input_ssid('ssid_2.4G')
            try:
                guide.find_ssid_5g()
            except NoSuchElementException:
                if support5 != '--':
                    CapPic(self.driver)
                    logger.info(u'不支持5G,与参数表不相符')
                    raise Exception('不支持5G,与参数表不相符')
                else:
                    logger.info(u'不支持5G,与参数表相符')
            else:
                print('设备支持5G')
                if support5 != '--':
                    CapPic(self.driver)
                    logger.info(u'支持5G,与参数表相符')
                else:
                    CapPic(self.driver)
                    logger.info(u'支持5G,与参数表不相符')
                    raise Exception('支持5G,与参数表不相符')
                guide.input_ssid_5g('ssid_5G')
            guide.click_okey()
            time.sleep(8)
        else:
            print('设备不支持无线')
            if support2 != '--':
                CapPic(self.driver)
                logger.info(u'不支持2.4G,与参数表不相符')
                raise Exception('不支持2.4G,与参数表不相符')
            else:
                logger.info(u'不支持2.4G,与参数表相符')
        time.sleep(15)
        self.driver.implicitly_wait(10)
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        # 断言
        list_lineType = wan_config.getText_byXpath(wan_config.line1Type)
        print('list_lineType:', list_lineType)
        self.assertEqual(str(list_lineType), linetype, msg='连接类型 不为 动态接入')
        # 判断联网状态
        i = 0
        while i < 21:
            wan_config.click_refresh()
            time.sleep(1)
            list_conState = wan_config.getText_byXpath(
                wan_config.connectState1)
            print(str(list_conState), i)
            if str(list_conState) != ConnectState:
                time.sleep(3)
                i += 1
            else:
                break
        else:
            CapPic(self.driver)
            logger.info(u"WAN口未连接")
            raise Exception('WAN1 未连接')
        i = 0
        while i < 21:
            # 判断联网 ,不能上网则报错
            # pingTestIP('114.114.114.114')
            p = pingTestIP('www.baidu.com')
            print(p, i)
            if p == 'N':
                time.sleep(3)
                i += 1
            else:
                break
        else:
            logger.info(u"connect failed")
            raise Exception('connect failed.')

        self.driver.quit()
        logger.info('test_001_dhcp passed')
コード例 #18
0
ファイル: ConfigGuide.py プロジェクト: sanwzhou/SEWEB
    def test_003_pppoe(self):
        u'''配置向导 - PPPoE接入'''
        guide = ConfigGuidepage(self.driver, self.url)
        PPPoEline = getAssertText('PPPoEline')
        ConnectState = getAssertText('ConnectState')
        # 进入配置向导
        guide.click_configGuide()
        time.sleep(0.5)
        guide.click_next()
        time.sleep(1)
        connectionTypew = guide.selelement_byName(guide.connectionTypew)
        Select(connectionTypew).select_by_value('PPPOE')
        time.sleep(1)
        guide.input_pppoeUser('111')  #输入上层网关配置的PPPoE账号密码
        guide.input_pppoePass('111')
        self.driver.implicitly_wait(2)  # 无线设备会定位不到okey,这里让等待时间缩短一些
        try:
            guide.find_okey()
        except NoSuchElementException:
            print('设备支持无线')
            if support2 != '--':
                logger.info(u'参数支持2.4G')
                logger.info(u'支持2.4G,与参数表相符')
            else:
                CapPic(self.driver)
                logger.info(u'支持2.4G,与参数表不相符')
                raise Exception('支持2.4G,与参数表不相符')
            guide.click_next()
            time.sleep(1)
            guide.input_ssid('ssid_2.4G')
            try:
                guide.find_ssid_5g()
            except NoSuchElementException:
                if support5 != '--':
                    CapPic(self.driver)
                    logger.info(u'不支持5G,与参数表不相符')
                    raise Exception('不支持5G,与参数表不相符')
                else:
                    logger.info(u'不支持5G,与参数表相符')
            else:
                print('设备支持5G')
                if support5 != '--':
                    CapPic(self.driver)
                    logger.info(u'支持5G,与参数表相符')
                else:
                    CapPic(self.driver)
                    logger.info(u'支持5G,与参数表不相符')
                    raise Exception('支持5G,与参数表不相符')
                guide.input_ssid_5g('ssid_5G')
            guide.click_okey()
            time.sleep(8)
        else:
            print('设备不支持无线')
            if support2 != '--':
                CapPic(self.driver)
                logger.info(u'不支持2.4G,与参数表不相符')
                raise Exception('不支持2.4G,与参数表不相符')
            else:
                logger.info(u'不支持2.4G,与参数表相符')
        time.sleep(15)
        self.driver.implicitly_wait(10)
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        # 断言
        list_lineType = wan_config.getText_byXpath(wan_config.line1Type)
        # print('list_lineType:',list_lineType)
        self.assertEqual(str(list_lineType), PPPoEline, msg='连接类型 不为 PPPoE接入')
        # PPPoE接入 拨号成功才会显示已连接
        i = 0
        while i < 21:
            wan_config.click_refresh()
            time.sleep(1)
            list_conState = wan_config.getText_byXpath(
                wan_config.connectState1)
            print(str(list_conState), i)
            if str(list_conState) != ConnectState:
                time.sleep(3)
                i += 1
            else:
                break
        else:
            CapPic(self.driver)
            logger.info(u"WAN口未连接")
            raise Exception('WAN1 未连接')
        i = 0
        while i < 21:
            # 判断联网 ,不能上网则报错
            # pingTestIP('114.114.114.114')
            p = pingTestIP('www.baidu.com')
            print(p, i)
            if p == 'N':
                i += 1
                time.sleep(3)
            else:
                break
        else:
            logger.info(u"connect failed")
            raise Exception('connect failed.')
        #
        # list_conState = guide.getText_byXpath(guide.list_connState)
        # print('list_connection_state:',str(list_conState))
        # if str(list_conState) != ConnectState:  # PPPoE接入 拨号成功才会显示已连接
        #     time.sleep(5)
        #     guide.click_refresh()
        #     time.sleep(0.5)
        #     list_conState = guide.getText_byXpath(guide.list_connState)
        #     if str(list_conState) != ConnectState:  # PPPoE接入 拨号成功才会显示已连接
        #         guide.click_list_connState()
        #         guide.click_dial()
        #         time.sleep(10)
        #         guide.click_refresh()
        #         time.sleep(0.5)
        #         list_conState = guide.getText_byXpath(guide.list_connState)
        #         if str(list_conState) != ConnectState:
        #             raise Exception('WAN1 未连接')
        #         else:  # 已连接
        #             time.sleep(3)
        #             pingTestIP('114.114.114.114')
        #             pingTestIP('www.baidu.com')
        #             p = pingTestIP('www.baidu.com')
        #             if p == 'N':
        #                 raise Exception('connect failed.')
        #     else:  # 已连接
        #         time.sleep(3)
        #         pingTestIP('114.114.114.114')
        #         pingTestIP('www.baidu.com')
        #         p = pingTestIP('www.baidu.com')
        #         if p == 'N':
        #             raise Exception('connect failed.')
        # else:  # 已连接
        #     time.sleep(3)
        # pingTestIP('114.114.114.114')
        # pingTestIP('www.baidu.com')
        # p = pingTestIP('www.baidu.com')
        # if p == 'N':
        #     raise Exception('connect failed.')

        self.driver.quit()
        logger.info('test_003_pppoe passed')
コード例 #19
0
ファイル: ConfigGuide.py プロジェクト: sanwzhou/SEWEB
    def test_002_static(self):
        u'''配置向导 - 固定接入'''
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        Staticline = getAssertText('Staticline')
        ConnectState = getAssertText('ConnectState')
        # 从外网配置页面获取WAN1口地址
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        # 判断联网状态
        i = 0
        while i < 21:
            wan_config.click_refresh()
            time.sleep(1)
            list_conState = wan_config.getText_byXpath(
                wan_config.connectState1)
            print(str(list_conState), i)
            if str(list_conState) != ConnectState:
                time.sleep(3)
                i += 1
            else:
                break
        else:
            CapPic(self.driver)
            logger.info(u"WAN口未连接")
            raise Exception('WAN1 未连接')
        WAN1_ip = wan_config.getText_byXpath(wan_config.line1IP)
        WAN1_gw = wan_config.getText_byXpath(wan_config.line1gw)
        WAN1_dns = wan_config.getText_byXpath(wan_config.line1Dns)
        time.sleep(1)
        # 进入配置向导 将wan1口的IP/网关/dns 拿来输入
        guide = ConfigGuidepage(self.driver, self.url)
        guide.click_configGuide()
        time.sleep(1)
        guide.click_next()
        time.sleep(1)
        connectionTypew = guide.selelement_byName(guide.connectionTypew)
        Select(connectionTypew).select_by_value('STATIC')
        time.sleep(1)
        guide.input_staticIp(WAN1_ip)
        guide.input_staticGateway(WAN1_gw)
        guide.input_staticPriDns(WAN1_dns)
        try:
            self.driver.implicitly_wait(2)
            guide.find_okey()
        except NoSuchElementException:
            print('设备支持无线')
            if support2 != '--':
                logger.info(u'参数支持2.4G')
                logger.info(u'支持2.4G,与参数表相符')
            else:
                CapPic(self.driver)
                logger.info(u'支持2.4G,与参数表不相符')
                raise Exception('支持2.4G,与参数表不相符')
            guide.click_next()
            time.sleep(1)
            guide.input_ssid('ssid_2.4G')
            try:
                guide.find_ssid_5g()
            except NoSuchElementException:
                if support5 != '--':
                    CapPic(self.driver)
                    logger.info(u'不支持5G,与参数表不相符')
                    raise Exception('不支持5G,与参数表不相符')
                else:
                    logger.info(u'不支持5G,与参数表相符')
            else:
                print('设备支持5G')
                if support5 != '--':
                    CapPic(self.driver)
                    logger.info(u'支持5G,与参数表相符')
                else:
                    CapPic(self.driver)
                    logger.info(u'支持5G,与参数表不相符')
                    raise Exception('支持5G,与参数表不相符')
                guide.input_ssid_5g('ssid_5G')
            guide.click_okey()
            time.sleep(8)
        else:
            print('设备不支持无线')
            if support2 != '--':
                CapPic(self.driver)
                logger.info(u'不支持2.4G,与参数表不相符')
                raise Exception('不支持2.4G,与参数表不相符')
            else:
                logger.info(u'不支持2.4G,与参数表相符')
        self.driver.implicitly_wait(10)
        time.sleep(15)
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        # 断言
        list_lineType = wan_config.getText_byXpath(wan_config.line1Type)
        print('list_lineType', list_lineType)
        self.assertEqual(str(list_lineType), Staticline, msg='连接类型 不为 固定接入')
        # 判断联网状态
        i = 0
        while i < 21:
            wan_config.click_refresh_s()
            time.sleep(1)
            list_conState = wan_config.getText_byXpath(
                wan_config.connectState1)
            print(str(list_conState), i)
            if str(list_conState) != ConnectState:
                time.sleep(3)
                i += 1
            else:
                break
        else:
            CapPic(self.driver)
            logger.info(u"WAN口未连接")
            raise Exception('WAN1 未连接')
        i = 0
        while i < 21:
            # 判断联网 ,不能上网则报错
            # pingTestIP('114.114.114.114')
            p = pingTestIP('www.baidu.com')
            print(p, i)
            if p == 'N':
                i += 1
                time.sleep(3)
            else:
                break
        else:
            logger.info(u"connect failed")
            raise Exception('connect failed.')

        self.driver.quit()
        logger.info('test_002_static passed')
コード例 #20
0
ファイル: VPNconfig_001_ipsec.py プロジェクト: sanwzhou/SEWEB
    def test_001_ipsec(self):
        u'''ipsec VPN'''
        vpnRouteLan = getweb('vpnRouteLan')
        host = gettelnet('host')
        StateVPN1 = getAssertText('StateVPN1')
        WillReboottips = getAssertText('WillReboottips')

        #先判断是否可以上网
        p = pingTestIP()
        if p == 'N':
            os.system('%s' % (batpath + 'changeDhcpIp.bat'))
            time.sleep(5)
            n = 0
            while n < 30:
                pcaddr = socket.gethostbyname(
                    socket.getfqdn(socket.gethostname()))
                print(pcaddr, n)
                if '192.168.' not in str(pcaddr):
                    time.sleep(2)
                    n += 1
                else:
                    print('IP地址已自动获取成功', n)
                    break
            else:
                raise Exception('未获取到地址')
            # 删除绑定绑定 清空组
            organization_group.group_delete(self)

        login.loginWeb(self)
        self.driver.implicitly_wait(10)
        ipsec = IPsecPage(self.driver, self.url)
        ipsec.click_VPNConfig()
        time.sleep(0.5)
        ipsec.click_IPSec()
        time.sleep(1)
        # 操作删除 以访已有规则
        ipsec.click_selall()
        time.sleep(0.2)
        ipsec.click_delall()
        time.sleep(2)
        try:
            self.driver.implicitly_wait(2)
            ipsec.find_ok()
        except NoSuchElementException:
            try:
                ipsec.find_tipsshowin()
                time.sleep(1)
            except NoSuchElementException:
                pass
        else:
            time.sleep(1)
            print('ipsec VPN列表为空')

        ipsec.click_add()
        time.sleep(1)
        ipsec.input_ids('test')
        ipsec.input_peer(vpnRouteWan)
        ipsec.input_remoteAddr(vpnRouteLan)
        # ipsec.input_remoteMask('255.255.255.0')
        ipsec.input_preshareKey('12345678')
        ipsec.click_save()
        time.sleep(2)
        try:  #无线设备增加ac功能后 配置第一条ipsec时会提示重启
            ipsec.find_ok()
        except NoSuchElementException:
            pass
        else:
            time.sleep(2)
            tips = str(ipsec.getText_byClass(ipsec.u_tim_str))
            self.assertEqual(tips, WillReboottips, msg='点击提示重启 操作失败')
            # 设备重启时间不一致,做个判断
            time.sleep(30)
            i = 0
            while i < 20:
                now_url = str(self.driver.current_url)
                # print(now_url,i)
                if '/noAuth/login.html' not in now_url:  # 如果不同
                    time.sleep(5)
                else:
                    break
                i += 1
            else:
                raise Exception('设备重启未正常启动')
            self.driver.quit()
            login.loginWeb(self)

        # 从外网配置页面获取WAN1口地址
        wanpage = NetworkConfig_wanpage(self.driver, self.url)
        wanpage.click_NetworkConfig()
        time.sleep(0.5)
        wanpage.click_WANconfig()
        time.sleep(1)

        # 判断联网状态
        i = 0
        while i < 21:
            wanpage.click_refresh()
            time.sleep(1)
            list_conState = wanpage.getText_byXpath(wanpage.connectState1)
            print(str(list_conState), i)
            if str(list_conState) != ConnectState:
                time.sleep(3)
                i += 1
            else:
                break
        else:
            CapPic(self.driver)
            logger.info(u"WAN口未连接")
            raise Exception('WAN1 未连接')
        i = 0
        while i < 21:
            # 判断联网 ,不能上网则报错
            p = pingTestIP('www.baidu.com')
            print(p, i)
            if p == 'N':
                time.sleep(3)
                i += 1
            else:
                break
        else:
            logger.info(u"connect failed")
            raise Exception('connect failed.')

        # WAN1 ip变量赋值,页面读取
        WAN1_ip = str(wanpage.getText_byXpath(wanpage.line1IP))
        # print('WAN1_ip=',WAN1_ip)
        time.sleep(1)
        self.driver.quit()

        # 另外一台路由器 配置ipsec
        i = 0  #以访刚重启wan口还不通
        while i < 60:
            pingTestIP(vpnRouteWan)
            if p == 'N':
                time.sleep(1)
                i += 1
            else:
                break
        else:
            raise Exception(u'无法ping通vpnRoute')
        # time.sleep(5)
        login.test_enableLoginWeb(self, url=vpnRouteUrl)
        ipsec = IPsecPage(self.driver, self.url)
        ipsec.click_VPNConfig()
        time.sleep(0.5)
        ipsec.click_IPSec()
        time.sleep(1)
        # 操作删除 以访已有规则
        ipsec.click_selall()
        time.sleep(0.2)
        ipsec.click_delall()
        time.sleep(1)
        try:
            self.driver.implicitly_wait(2)
            ipsec.find_ok()
        except NoSuchElementException:
            try:
                ipsec.find_tipsshowin()
                time.sleep(1)
            except NoSuchElementException:
                pass
        else:
            time.sleep(1)
            print('ipsec VPN列表为空')

        ipsec.click_add()
        time.sleep(1)
        ipsec.input_ids('test')
        ipsec.input_peer(WAN1_ip)
        ipsec.input_remoteAddr(host)
        # ipsec.input_remoteMask('255.255.255.0')
        ipsec.input_preshareKey('12345678')
        ipsec.click_save()
        time.sleep(2)

        i = 0
        while i < 100:
            ipsec.click_IPSec()
            time.sleep(1)
            list_status = ipsec.getText_byXpath(ipsec.list_status)
            print(list_status)
            if list_status == StateVPN1:
                logger.info(u'ipsec 已建立')
                break
            else:
                time.sleep(3)
                i += 1
        else:
            logger.info(u'ipsec 未建立成功')
            CapPic(self.driver)
            raise Exception(u'ipsec未建立成功')

        self.driver.quit()
        logger.info('test_001_ipsec passed')
コード例 #21
0
    def test_001_staticRouting(self):
        u'''配置静态路由,能在命令行查看到相关路由'''
        ConnectState = getAssertText('ConnectState')
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        # 从外网配置页面获取WAN1口地址
        wanpage = NetworkConfig_wanpage(self.driver, self.url)
        wanpage.click_NetworkConfig()
        time.sleep(0.5)
        wanpage.click_WANconfig()
        time.sleep(1)
        # WAN1 ip变量赋值,页面读取
        # 判断联网状态
        i = 0
        while i < 21:
            wanpage.click_refresh()
            time.sleep(1)
            list_conState = wanpage.getText_byXpath(wanpage.connectState1)
            print(str(list_conState), i)
            if str(list_conState) != ConnectState:
                time.sleep(3)
                i += 1
            else:
                break
        else:
            CapPic(self.driver)
            logger.info(u"WAN口未连接")
            raise Exception('WAN1 未连接')
        WAN1_ip = str(wanpage.getText_byXpath(wanpage.line1IP))
        time.sleep(1)

        # 添加静态路由
        routeconfig = RouteConfigPage(self.driver, self.url)
        routeconfig.click_Routeconfig()
        time.sleep(1)
        routeconfig.click_add()
        time.sleep(1)
        routeconfig.input_RouteNames('static')
        routeconfig.input_DesIPs('223.5.5.5')
        routeconfig.input_DesMasks('255.255.255.255')
        routeconfig.input_GateWays(WAN1_ip)
        routeconfig.click_save()
        time.sleep(5)
        #断言
        list_dst = str(routeconfig.getText_byXpath(routeconfig.list_dst))
        self.assertEqual(list_dst, '223.5.5.5', msg='目的网络不为"223.5.5.5"')
        self.driver.quit()

        # 连接Telnet服务器
        hostip = gettelnet('host')
        port = gettelnet('port')
        username = bytes(getweb('User'), encoding="utf8")
        password = bytes(getweb('Passwd'), encoding="utf8")
        tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
        tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        # 输入登录用户名
        tn.read_until(b'login:'******'Password:'******'#')
        tn.write(b'ip route show tab 120' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 判断
        if "223.5.5.5" in result:
            print('命令行可以看到配置路由')
        else:
            raise Exception('命令行未看到路由')  # 如果没有则报错

        tn.close()  # tn.write('exit\n')
        logger.info('test_001_staticRouting passed')
コード例 #22
0
    def test_001_line(self):
        u'''线路备份、负载均衡、带宽比、电信/联通/移动双线路接入策略路由'''
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_line1edit()
        time.sleep(1)
        #主备
        # 注意这里下拉框select_by_value('0')有问题,使用xpath选择
        wan_config.click_backline1()
        time.sleep(0.5)
        wan_config.click_mainline1()
        time.sleep(0.5)
        #上下行及带宽比
        wan_config.input_txBands2('1000')
        wan_config.input_rxBands2('2000')
        wan_config.input_rMin2('70')
        wan_config.input_rMax2('90')
        wan_config.input_limitRatio2('50')
        #线路模板
        wan_config.click_ISPType()
        time.sleep(0.5)
        wan_config.click_ISPType1()
        time.sleep(0.5)
        wan_config.click_ISPType2()
        time.sleep(0.5)

        self.driver.quit()
        logger.info('test_001_line passed')
コード例 #23
0
    def test_005_WanAcessSmaba(self):
        u'''WAN口访问samba服务器(部分型号暂未支持)'''
        ftpSmaba = NetworkSharingPage(self.driver, self.url)
        #1、验证未打开 ‘wan口访问’ 无法从wan访问samba
        #1)验证未打开
        WANEnable = str(
            self.driver.find_element_by_name('WANEnable').get_attribute(
                'checked'))
        print(WANEnable)
        if WANEnable == 'true':
            self.driver.find_element_by_name('WANEnable').click()
            ftpSmaba.click_save()
            time.sleep(1)
            ftpSmaba.click_NetworkSharing2()  # 点击网络共享子页面
            time.sleep(1)
            WANEnable = str(
                self.driver.find_element_by_name('WANEnable').get_attribute(
                    'checked'))
            self.assertEqual(WANEnable, 'None', msg='允许wan口访问 关闭失败')
        #2)从外网配置页面获取WAN1口地址
        wanpage = NetworkConfig_wanpage(self.driver, self.url)
        wanpage.click_WANconfig()
        time.sleep(1)
        # WAN1 ip变量赋值,页面读取
        WAN1_ip = str(wanpage.getText_byXpath(wanpage.line1IP))
        time.sleep(1)
        #3) 更改pc 交换机接口与wan口/上联口通
        swconfig.test_LanToWan(self)
        # 重新获取地址 应获取到上层网关下发的地址
        pcaddr = str(socket.gethostbyname(socket.getfqdn(
            socket.gethostname())))
        # 调用bat脚本 IP地址释放
        os.system('%s' % (batpath + 'ipconfig_release.bat'))
        time.sleep(2)
        pcaddr1 = str(
            socket.gethostbyname(socket.getfqdn(socket.gethostname())))
        print(pcaddr1)
        if pcaddr1 != str(pcaddr):
            print('IP地址已释放')
        else:
            time.sleep(3)
        time.sleep(2)
        # 重新获取地址
        os.system('%s' % (batpath + 'ipconfig_renew.bat'))
        time.sleep(5)
        n = 0
        while n < 30:
            # 获取本机ip 默认有线地址,有线断开会显示无线
            pcaddr = socket.gethostbyname(socket.getfqdn(socket.gethostname()))
            print(pcaddr, n)
            if '192.168.' not in str(pcaddr):
                time.sleep(2)
                n += 1
            else:
                print('IP地址已自动获取成功', n)
                break
        else:
            raise Exception('未获取到地址')
        time.sleep(2)
        #4)未开启验证无法登录
        user_name = "anonymous"
        pass_word = ""
        my_name = "anyname"
        domain_name = ""
        remote_smb_IP = WAN1_ip
        smb = SMBConnection(user_name,
                            pass_word,
                            my_name,
                            domain_name,
                            use_ntlm_v2=True)
        try:
            smb.connect(remote_smb_IP, 139, timeout=3)
        except ConnectionRefusedError:
            print('未开启samba 无法访问 验证通过')
        # 5)改为lan口 并重新获取地址
        switchURL2 = gettelnet('switchURL2')
        # 调用bat脚本 地址修改为 192.168.34.39 网关192.168.34.1
        os.system('%s' % (batpath + 'changeStaticIP3_34duan.bat'))
        time.sleep(5)
        n = 0
        while n < 30:
            # 获取本机ip 默认有线地址,有线断开会显示无线
            pcaddr = socket.gethostbyname(socket.getfqdn(socket.gethostname()))
            print(pcaddr, n)
            if str(pcaddr) != '192.168.34.39':
                time.sleep(2)
                n += 1
            else:
                print('地址已修改为地址 192.168.34.39', n)
                break
        else:
            raise Exception('地址修改为192.168.34.39 失败')
        # 更改pc 交换机接口与lan口通
        p1 = subprocess.Popen('ping -n 2 -w 2 %s' % switchURL2,
                              shell=True,
                              stdout=subprocess.PIPE)
        # print('错误IP联网状态(ping通为0 不通为1):', p1.wait())  # ping通为0 不通为1
        ping = int(p1.wait())
        if ping == 0:
            swconfig.test_WanToLan(self)
        # 将IP改回自动获取 应获取到被测设备下发的地址
        os.system('%s' % (batpath + 'changeDhcpIp.bat'))
        n = 0
        while n < 30:
            # 获取本机ip 默认有线地址,有线断开会显示无线
            pcaddr_new = socket.gethostbyname(
                socket.getfqdn(socket.gethostname()))
            print(pcaddr_new, n)
            if '192.168.' not in str(pcaddr_new):
                time.sleep(2)
                n += 1
            else:
                print('IP地址已自动获取成功', n)
                break
        else:
            raise Exception('未获取到地址')
        time.sleep(3)
        #2 验证打开 ‘wan口访问’ 可以从wan口访问smaba
        #1)打开
        ftpSmaba = NetworkSharingPage(self.driver, self.url)
        ftpSmaba.click_NetworkSharing()
        time.sleep(1)
        ftpSmaba.click_NetworkSharing2()  # 点击网络共享子页面
        time.sleep(1)
        self.driver.find_element_by_name('WANEnable').click()
        ftpSmaba.click_save()
        time.sleep(1)
        WANEnable = self.driver.find_element_by_name(
            'WANEnable').get_attribute('checked')
        self.assertEqual(WANEnable, 'true', msg='允许wan口访问 启用失败')
        #2) 更改pc 交换机接口与wan口/上联口通
        swconfig.test_LanToWan(self)
        # 重新获取地址 应获取到上层网关下发的地址
        pcaddr = str(socket.gethostbyname(socket.getfqdn(
            socket.gethostname())))
        # 调用bat脚本 IP地址释放
        os.system('%s' % (batpath + 'ipconfig_release.bat'))
        time.sleep(2)
        pcaddr1 = str(
            socket.gethostbyname(socket.getfqdn(socket.gethostname())))
        print(pcaddr1)
        if pcaddr1 != str(pcaddr):
            print('IP地址已释放')
        else:
            time.sleep(3)
        time.sleep(2)
        # 重新获取地址
        os.system('%s' % (batpath + 'ipconfig_renew.bat'))
        time.sleep(5)
        n = 0
        while n < 30:
            # 获取本机ip 默认有线地址,有线断开会显示无线
            pcaddr = socket.gethostbyname(socket.getfqdn(socket.gethostname()))
            print(pcaddr, n)
            if '192.168.' not in str(pcaddr):
                time.sleep(2)
                n += 1
            else:
                print('IP地址已自动获取成功', n)
                break
        else:
            raise Exception('未获取到地址')
        time.sleep(2)
        # 3)samba验证登陆
        try:
            smb.connect(remote_smb_IP, 139, timeout=3)
        except socket.timeout:
            raise Exception('samba服务无法访问')
        smb.close()

        self.driver.quit()
        logger.info('test_004_WanaAcess passed')
コード例 #24
0
    def test_002_backupLineSW(self):
        u'''双固定IP接入时的线路切换:主、备份线路'''
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        #1、获取wan1、wan2 网关及mac
        line1_mac = str(wan_config.getText_byXpath(wan_config.line1Mac))
        # print('WAN1_dns=',line1_mac)
        line2_mac = str(wan_config.getText_byXpath(wan_config.line2Mac))
        # print('WAN1_dns=',line2_mac)
        # 处理wan口的mac地址
        # 字母变大写
        line1_mac1 = line1_mac.upper()
        line2_mac1 = line2_mac.upper()
        # 加冒号
        line1_mac2 = line1_mac1[0:2] + ':' + line1_mac1[
            2:4] + ':' + line1_mac1[4:6] + ':' + line1_mac1[
                6:8] + ':' + line1_mac1[8:10] + ':' + line1_mac1[10:]
        line2_mac2 = line2_mac1[0:2] + ':' + line2_mac1[
            2:4] + ':' + line2_mac1[4:6] + ':' + line2_mac1[
                6:8] + ':' + line2_mac1[8:10] + ':' + line2_mac1[10:]
        print(line1_mac2, line2_mac2)

        #WAN1改为备份线路
        wan_config.click_line1edit()
        time.sleep(1)
        line_type = wan_config.selelement_byXpath(wan_config.line_type)
        Select(line_type).select_by_value('0')  #1为主 0为备份
        wan_config.click_save()
        time.sleep(10)
        n = 0
        while n < 20:
            ping = pingTestIP()
            if ping != 'Y':
                time.sleep(1)
                n += 1
            else:
                break
        self.driver.quit()

        # telnet获取接口名称及确认默认路由(wan1备份应该只剩下wan2默认路由)
        hostip = gettelnet('host')
        port = gettelnet('port')
        username = bytes(getweb('User'), encoding="utf8")
        password = bytes(getweb('Passwd'), encoding="utf8")
        # 获取接口名称
        tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
        tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        tn.read_until(b'login:'******'Password:'******'#')
        tn.write(b'ifconfig | grep eth' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 获取WAN口对应接口名称
        result1 = result[3:-9]
        # print(result1)
        result2 = result1.split(r'\r\n')
        print('result2:', result2)

        for i in range(len(result2)):
            if line1_mac2 in result2[i]:
                result2_num = (result2[i])
                print(result2[i])
                line1_Interface_name = result2_num.split()[0]
                print(line1_Interface_name)
            if line2_mac2 in result2[i]:
                result2_num = (result2[i])
                print(result2[i])
                line2_Interface_name = result2_num.split()[0]
                print(line2_Interface_name)
        if line1_Interface_name == None:
            raise Exception('获取wan1口对应接口名称失败')
        if line2_Interface_name == None:
            raise Exception('获取wan2口对应接口名称失败')
        # 确认默认路由情况
        roure1 = bytes(('ip route | grep "%s"') % line2_Interface_name,
                       encoding="utf8")
        tn.write(roure1 + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 获取WAN1对应接口名称
        result1 = result[2:-7]
        print('result1', result1)
        result2 = result1.split(r'\r\n')
        print('result2', result2)
        #wan1已备份,只剩wan2路由,这里只判断wan2的
        wan2route = 'dev ' + line2_Interface_name
        print('wan2route:', wan2route)

        for i in range(len(result2)):
            if 'default' in result2[i] and wan2route in result2[i]:
                wan2route_status = not None
                print('wan2路由在')
        if wan2route_status == None:
            raise Exception('wan2默认路由显示有误')
        #单线路默认路由变为:default via 192.168.11.1 dev eth2.3 equalize 不再有weight值
        # (高通没有equalize):default via 192.168.12.1 dev eth0.3
        #多线mtk
        # default equalize
        #    nexthop via 192.168.32.1  dev eth2.2 weight 1
        #    nexthop via 192.168.200.1  dev eth2.3 weight 1
        # 多线高通
        # default
        #    nexthop via 192.168.11.1  dev eth0.2 weight 1
        #    nexthop via 192.168.11.1  dev eth0.3 weight 1

        tn.close()  # tn.write('exit\n')

        #2、设置线路检测地址,验证线路切换
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        self.driver.maximize_window()
        wan_config = NetworkConfig_wanpage(self.driver, self.url)

        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        #配置线路检测 检测3s 检测 3次,地址为223.5.5.5
        wan_config.click_GlobalConfig()
        time.sleep(1)
        wan_config.input_KeepLive1('3')
        wan_config.input_RetryTimes1('3')
        sel1 = wan_config.selelement_byName(wan_config.PriAddrType1)
        Select(sel1).select_by_value('others')
        time.sleep(0.5)
        wan_config.input_DestIP1('223.5.5.5')

        wan_config.input_KeepLive2('3')
        wan_config.input_RetryTimes2('3')
        sel2 = wan_config.selelement_byName(wan_config.PriAddrType2)
        Select(sel2).select_by_value('others')
        time.sleep(0.5)
        wan_config.input_DestIP2('1.2.3.4')  #WAN2配一个ping不通的地址,测试线路切换
        wan_config.click_save()
        time.sleep(2)
        # 等待弹窗提示成功
        i = 0
        while i < 80:
            try:
                self.driver.implicitly_wait(1)
                wan_config.find_tipsshowin()
            except NoSuchElementException:
                time.sleep(1)
                i = i + 1
                print(i)
            else:
                tips = str(
                    wan_config.getAttribute_byClass(wan_config.tipsshowin,
                                                    'tip-sign'))
                print(tips, i)
                if tips != 'success':
                    CapPic(self.driver)
                    logger.info(u'线路检测保存 异常')
                    raise Exception(u'线路检测保存 异常')
                break
        else:
            raise Exception(u'线路检测保存 未弹出提示框')

        #切换标签页判断配置正确
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_GlobalConfig()
        time.sleep(1)
        KeepLive2 = str(
            wan_config.getAttribute_byName(wan_config.KeepLive2v, 'value'))
        RetryTimes2 = str(
            wan_config.getAttribute_byName(wan_config.RetryTimes2v, 'value'))
        DestIP2 = str(
            wan_config.getAttribute_byName(wan_config.DestIP2v, 'value'))
        self.assertEqual(KeepLive2, '3', msg='wan2检测间隔与设置不一致')
        self.assertEqual(RetryTimes2, '3', msg='wan2检测次数与设置不一致')
        self.assertEqual(DestIP2, '1.2.3.4', msg='wan2检测地址与设置不一致')

        # 确认默认路由情况
        # 单线路默认路由变为:default via 192.168.11.1 dev eth2.2 equalize 不再有weight值
        wan1route1 = 'dev ' + line1_Interface_name
        print('wan1route:', wan1route1)
        roure1 = bytes(('ip route | grep "%s"') % line1_Interface_name,
                       encoding="utf8")

        time.sleep(10)  # 等待检测,路由切换
        x = 0
        while x < 60:
            tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
            tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
            tn.read_until(b'login:'******'Password:'******'\n')
            # 输出结果,判断
            time.sleep(1)
            result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
            print('-------------------输出结果------------------------')
            # 命令执行结果
            # print('result:', result)
            result4 = result[1:]
            # print('result4', result4)
            result5 = result4.replace('\r\n', ' ')
            print('result5', result5)
            tn.close()
            # wan2、wan3检测不通,这里判断仅wan1在
            if 'default' in result5 and wan1route1 in result5:
                print('wan1路由在')
                break
            else:
                print(x)
                time.sleep(2)
                x += 1
        else:
            logger.info(u'wan1route1: %s' % wan1route1)
            logger.info(u'result5: %s' % result5)
            raise Exception('wan1默认路由显示有误')

        #3、将wan2检测目标改正确,线路、路由切换回来
        wan_config.input_DestIP2('223.5.5.5')  # WAN2检测地址改可ping通,测试线路切换
        wan_config.click_save()
        time.sleep(2)
        # 等待弹窗提示成功
        i = 0
        while i < 80:
            try:
                self.driver.implicitly_wait(1)
                wan_config.find_tipsshowin()
            except NoSuchElementException:
                time.sleep(1)
                i = i + 1
                print(i)
            else:
                tips = str(
                    wan_config.getAttribute_byClass(wan_config.tipsshowin,
                                                    'tip-sign'))
                print(tips, i)
                if tips != 'success':
                    CapPic(self.driver)
                    logger.info(u'线路检测保存 异常')
                    raise Exception(u'线路检测保存 异常')
                break
        else:
            raise Exception(u'线路检测保存 未弹出提示框')
        # 切换标签页判断配置正确
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_GlobalConfig()
        time.sleep(1)
        DestIP2 = str(
            wan_config.getAttribute_byName(wan_config.DestIP2v, 'value'))
        self.assertEqual(DestIP2, '223.5.5.5', msg='wan2检测地址与设置不一致')

        time.sleep(20)  # 等待检测,路由切换
        # 确认默认路由情况(wan2检测地址通,默认路由应切换成wan2)
        # 单线路默认路由变为:default via 192.168.11.1 dev eth2.2 equalize 不再有weight值
        wan2route1 = 'dev ' + line2_Interface_name
        print('wan2route1:', wan2route1)
        roure1 = bytes(('ip route | grep "%s"') % wan2route1, encoding="utf8")
        x = 0
        while x < 60:
            tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
            tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
            tn.read_until(b'login:'******'Password:'******'\n')
            # 输出结果,判断
            time.sleep(1)
            result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
            print('-------------------输出结果------------------------')
            # 命令执行结果
            # print('result:', result)
            result4 = result[1:]
            # print('result4', result4)
            result5 = result4.replace('\r\n', ' ')
            print('result5', result5)
            # wan2、wan3检测不通,这里只判断wan1的
            tn.close()
            if 'default' in result5 and wan2route1 in result5:
                print('wan2路由在')
                break
            else:
                print(x)
                time.sleep(2)
                x += 1
        else:
            logger.info(u'wan2route1: %s' % wan2route1)
            logger.info(u'result5: %s' % result5)
            raise Exception('wan2默认路由显示有误')

        #4、wan1口改回主线路
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_line1edit()
        time.sleep(1)
        line_type = wan_config.selelement_byXpath(wan_config.line_type)
        Select(line_type).select_by_value('1')  # 1为主 0为备份
        wan_config.click_save()
        time.sleep(10)  # 修改接口后 可能会回到登录页面 所以关闭,再打开
        self.driver.quit()

        # telnet获取接口名称及确认默认路由
        wan1route_2 = 'dev ' + line1_Interface_name + ' weight '
        wan2route_2 = 'dev ' + line2_Interface_name + ' weight '
        print('wan1route_2:', wan1route_2, 'wan2route_2:', wan2route_2)
        time.sleep(10)
        # 获取接口名称
        x = 0
        while x < 60:
            tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
            tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
            tn.read_until(b'login:'******'Password:'******'#')
            # 确认默认路由情况
            tn.write(b'ip route' + b'\n')
            # 输出结果,判断
            time.sleep(1)
            result9 = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
            print('-------------------输出结果------------------------')
            # 命令执行结果
            # print('result9:', result9)
            # 获取WAN1对应接口名称
            result10 = result9[1:]
            # print('result10', result10)
            result11 = result10.replace('\r\n', ' ')
            print('result11', result11)
            tn.close()
            if (wan1route_2 in result11) and (wan2route_2 in result11):
                print('wan1/wan2路由在')
                break
            else:
                print(x)
                time.sleep(2)
                x += 1
        else:
            logger.info(u'wan1route_2: %s' % wan1route_2)
            logger.info(u'wan2route_2: %s' % wan2route_2)
            logger.info(u'result11 %s' % result11)
            raise Exception('wan1/wan2默认路由显示有误')

        logger.info('test_002_backupLineSW passed')
コード例 #25
0
    def test_001_portRateWAN(self):
        u'''wan默认协商速率及端口速率修改 '''
        # 进入-系统监控-系统状态 获取型号判断是否支持千M
        sysmonitor = sysStaticPage(self.driver, self.url)
        sysmonitor.click_systemWatch()
        time.sleep(0.5)
        sysmonitor.click_sysStatic()
        time.sleep(1)
        Model = str(sysmonitor.getText_byXpath(sysmonitor.Model))
        print(Model)

        #判断速率wan口
        wanpage = NetworkConfig_wanpage(self.driver, self.url)
        wanpage.click_NetworkConfig()
        time.sleep(0.5)
        wanpage.click_WANconfig()
        time.sleep(1)
        wanpage.click_line1edit()
        time.sleep(1)
        connectionType = wanpage.selelement_byName(wanpage.connectionType)
        Select(connectionType).select_by_value('DHCP')
        time.sleep(1)
        WanMode_seled1 = str(
            wanpage.getAttribute_byXpath(wanpage.wanRateseled, 'value'))
        self.assertEqual(WanMode_seled1, '3', msg='WAN默认端口速率不为自动协商')
        WanMode_seled2 = str(
            wanpage.getAttribute_byXpath(wanpage.wanRateseled, 'selected'))
        self.assertEqual(WanMode_seled2, 'true', msg='WAN默认端口速率不为自动协商')
        WanMode = wanpage.selelement_byXpath(wanpage.selwanRate)
        time.sleep(1)
        # 0-10M全双工 1-100M全双工 2-1000M全双工 3-自动 4-10M半双工 5-100M半双工
        Select(WanMode).select_by_value('0')
        time.sleep(1)
        Select(WanMode).select_by_value('1')
        Select(WanMode).select_by_value('3')
        Select(WanMode).select_by_value('4')
        Select(WanMode).select_by_value('5')
        if 'G' in str(Model) or 'g' in str(Model):
            try:
                Select(WanMode).select_by_value('2')
            except NoSuchElementException:
                raise Exception('WAN口不支持千M协商速率')
        self.driver.quit()

        logger.info('test_001_portRateWAN passed')
コード例 #26
0
    def test_003_static_PPPoE(self):
        u'''固定+PPPoE 接入'''
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        ConnectState = getAssertText('ConnectState')
        # WAN1改成pppoe
        wan_config.click_line1edit()
        time.sleep(1)
        access_mode = wan_config.selelement_byName(wan_config.connectionType)
        Select(access_mode).select_by_value('PPPOE')
        time.sleep(1)
        wan_config.input_pppoeUser('111')
        wan_config.input_pppoePass('111')
        wan_config.click_save()
        time.sleep(10)
        self.driver.quit()  # 修改接口后 可能会回到登录页面 所以关闭,再打开

        login.loginWeb(self)  # admin账号登录
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        self.driver.implicitly_wait(10)
        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        #断言
        n = 0
        while n < 30:
            wan_config.click_refresh()
            time.sleep(1)
            list_connectState1 = wan_config.getText_byXpath(
                wan_config.connectState1)
            list_connectState2 = wan_config.getText_byXpath(
                wan_config.connectState2)
            print(str(list_connectState1), str(list_connectState2))
            list_connectState = [
                str(list_connectState1),
                str(list_connectState2)
            ]
            # 动态接入 未获取到地址/wan口线未接入 都是未连接
            if all(t == ConnectState for t in list_connectState):
                print('WAN口均已连接', n)
                break
            else:
                time.sleep(2)
                n += 1
        else:
            raise Exception('WAN口未已连接')
        #获取两个wan口IP、mac,pppoe接口通过IP判断接口名,固定通过mac地址判断接口名
        line1_ip = str(wan_config.getText_byXpath(wan_config.line1IP))
        print('line1_ip:', line1_ip)
        line2_mac = str(wan_config.getText_byXpath(wan_config.line2Mac))
        # print('WAN1_dns=',line2_mac)
        self.driver.quit()

        #处理wan口的mac地址
        #字母变大写
        line2_mac1 = line2_mac.upper()
        #加冒号
        line2_mac2 = line2_mac1[0:2] + ':' + line2_mac1[
            2:4] + ':' + line2_mac1[4:6] + ':' + line2_mac1[
                6:8] + ':' + line2_mac1[8:10] + ':' + line2_mac1[10:]
        print(line2_mac2)

        #telnet获取接口名称及确认默认路由
        hostip = gettelnet('host')
        port = gettelnet('port')
        username = bytes(getweb('User'), encoding="utf8")
        password = bytes(getweb('Passwd'), encoding="utf8")
        # 获取接口名称
        tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
        tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        tn.read_until(b'login:'******'Password:'******'#')
        tn.write(b'ifconfig | grep eth' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        #获取WAN口对应接口名称
        result1 = result[3:-9]
        # print(result1)
        result2 = result1.split(r'\r\n')
        print('result2:', result2)

        for i in range(len(result2)):
            if line2_mac2 in result2[i]:
                result2_num = (result2[i])
                print(result2[i])
                line2_Interface_name = result2_num.split()[0]
                print(line2_Interface_name)
        if line2_Interface_name == None:
            raise Exception('获取wan2口对应接口名称失败')

        # 通过IP获取wan1ppp接口名称 以及确认默认路由情况
        tn.write(b'ip route' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 获取WAN1对应接口名称
        result1 = result[2:-7]
        print('result1', result1)
        result2 = result1.split(r'\r\n')
        print('result2', result2)

        for x in range(len(result2)):
            if line1_ip in result2[x]:
                result2_num1 = (result2[x])
                print(result2_num1)
                line1_Interface_name = result2_num1.split()[2]
                print(line1_Interface_name)
        if line1_Interface_name == None:
            raise Exception('获取wan1口对应接口名称失败')

        #确认默认路由情况
        wan1route = 'nexthop dev ' + line1_Interface_name + ' weight '
        wan2route = 'dev ' + line2_Interface_name + ' weight '
        print('wan1route:', wan1route, 'wan2route:', wan2route)

        for i in range(len(result2)):
            if wan1route in result2[i]:
                wan1route_status = not None
                print('wan1路由在')
            if wan2route in result2[i]:
                wan2route_status = not None
                print('wan2路由在')
        if wan1route_status == None:
            raise Exception('wan1默认路由不存在')
        if wan2route_status == None:
            raise Exception('wan2默认路由不存在')
        tn.close()  # tn.write('exit\n')
        logger.info('test_003_static_PPPoE passed')
コード例 #27
0
    def test_002_staticSW(self):
        u'''五条线路固定接入线路切换'''
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 1、获取wan mac
        line1_mac = str(wan_config.getText_byXpath(wan_config.line1Mac))
        line2_mac = str(wan_config.getText_byXpath(wan_config.line2Mac))
        line3_mac = str(wan_config.getText_byXpath(wan_config.line3Mac))
        line4_mac = str(wan_config.getText_byXpath(wan_config.line4Mac))
        line5_mac = str(wan_config.getText_byXpath(wan_config.line5Mac))
        # 处理wan口的mac地址
        # 字母变大写
        line1_mac1 = line1_mac.upper()
        line2_mac1 = line2_mac.upper()
        line3_mac1 = line3_mac.upper()
        line4_mac1 = line4_mac.upper()
        line5_mac1 = line5_mac.upper()
        # 加冒号
        line1_mac2 = line1_mac1[0:2] + ':' + line1_mac1[2:4] + ':' + line1_mac1[4:6] + ':' + line1_mac1[
                                                                                             6:8] + ':' + line1_mac1[
                                                                                                          8:10] + ':' + line1_mac1[
                                                                                                                        10:]
        line2_mac2 = line2_mac1[0:2] + ':' + line2_mac1[2:4] + ':' + line2_mac1[4:6] + ':' + line2_mac1[
                                                                                             6:8] + ':' + line2_mac1[
                                                                                                          8:10] + ':' + line2_mac1[
                                                                                                                        10:]
        line3_mac2 = line3_mac1[0:2] + ':' + line3_mac1[2:4] + ':' + line3_mac1[4:6] + ':' + line3_mac1[
                                                                                             6:8] + ':' + line3_mac1[
                                                                                                          8:10] + ':' + line3_mac1[
                                                                                                                        10:]
        line4_mac2 = line4_mac1[0:2] + ':' + line4_mac1[2:4] + ':' + line4_mac1[4:6] + ':' + line4_mac1[
                                                                                             6:8] + ':' + line4_mac1[
                                                                                                          8:10] + ':' + line4_mac1[
                                                                                                                        10:]
        line5_mac2 = line5_mac1[0:2] + ':' + line5_mac1[2:4] + ':' + line5_mac1[4:6] + ':' + line5_mac1[
                                                                                             6:8] + ':' + line5_mac1[
                                                                                                          8:10] + ':' + line5_mac1[
                                                                                                                        10:]
        print('line1_mac2:', line1_mac2, 'line2_mac2:', line2_mac2, 'line3_mac2:', line3_mac2, 'line4_mac2:',
              line4_mac2, 'line5_mac2:', line5_mac2)
        self.driver.quit()
        # 2、设置线路检测地址,验证线路切换
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        self.driver.maximize_window()
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        # 配置线路检测 检测3s 检测 3次,地址为223.5.5.5
        wan_config.click_GlobalConfig()
        time.sleep(1)
        wan_config.input_KeepLive1('3')
        wan_config.input_RetryTimes1('3')
        sel1 = wan_config.selelement_byName(wan_config.PriAddrType1)
        Select(sel1).select_by_value('others')
        time.sleep(0.5)
        wan_config.input_DestIP1('223.5.5.5')

        wan_config.input_KeepLive2('3')
        wan_config.input_RetryTimes2('3')
        sel2 = wan_config.selelement_byName(wan_config.PriAddrType2)
        Select(sel2).select_by_value('others')
        time.sleep(0.5)
        wan_config.input_DestIP2('1.2.3.4')  # WAN2配一个ping不通的地址,测试线路切换

        wan_config.input_KeepLive3('3')
        wan_config.input_RetryTimes3('3')
        sel3 = wan_config.selelement_byName(wan_config.PriAddrType3)
        Select(sel3).select_by_value('others')
        time.sleep(0.5)
        wan_config.input_DestIP3('1.2.3.5')  # WAN3配一个ping不通的地址,测试线路切换

        wan_config.input_KeepLive4('3')
        wan_config.input_RetryTimes4('3')
        sel4 = wan_config.selelement_byName(wan_config.PriAddrType4)
        Select(sel4).select_by_value('others')
        time.sleep(0.5)
        wan_config.input_DestIP4('1.2.3.6')  # WAN4配一个ping不通的地址,测试线路切换

        wan_config.input_KeepLive5('3')
        wan_config.input_RetryTimes5('3')
        sel5 = wan_config.selelement_byName(wan_config.PriAddrType5)
        Select(sel5).select_by_value('others')
        time.sleep(0.5)
        wan_config.input_DestIP5('1.2.3.7')  # WAN5配一个ping不通的地址,测试线路切换
        wan_config.click_save()
        # 等待弹窗提示成功
        i = 0
        while i < 80:
            try:
                self.driver.implicitly_wait(1)
                wan_config.find_tipsshowin()
            except NoSuchElementException:
                time.sleep(1)
                i = i + 1
                print(i)
            else:
                tips = str(wan_config.getAttribute_byClass(wan_config.tipsshowin, 'tip-sign'))
                print(tips, i)
                if tips != 'success':
                    CapPic(self.driver)
                    logger.info(u'线路检测保存 异常')
                    raise Exception(u'线路检测保存 异常')
                break
        else:
            raise Exception(u'线路检测保存 未弹出提示框')
        # 切换标签页判断配置正确
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_GlobalConfig()
        time.sleep(1)
        KeepLive5 = str(self.driver.find_element_by_name('KeepLive5').get_attribute('value'))
        RetryTimes5 = str(self.driver.find_element_by_name('RetryTimes5').get_attribute('value'))
        DestIP5 = str(self.driver.find_element_by_name('DestIP5').get_attribute('value'))
        self.assertEqual(KeepLive5, '3', msg='wan5检测间隔与设置不一致')
        self.assertEqual(RetryTimes5, '3', msg='wan5检测次数与设置不一致')
        self.assertEqual(DestIP5, '1.2.3.7', msg='wan5检测地址与设置不一致')

        # telnet获取接口名称及确认默认路由(wan2/wan3检测不通,应只剩下wan1默认路由)
        # 获取接口名称
        hostip = gettelnet('host')
        port = gettelnet('port')
        username = bytes(getweb('User'), encoding="utf8")
        password = bytes(getweb('Passwd'), encoding="utf8")
        tn = telnetlib.Telnet(host=hostip, port=port,timeout=10)
        tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        tn.read_until(b'login:'******'Password:'******'#')
        tn.write(b'ifconfig | grep eth' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 获取WAN口对应接口名称
        result1 = result[3:-9]
        # print(result1)
        result2 = result1.split(r'\r\n')
        print('result2:', result2)

        for i in range(len(result2)):
            if line1_mac2 in result2[i]:
                result2_num = (result2[i])
                print(result2[i])
                line1_Interface_name = result2_num.split()[0]
                print(line1_Interface_name)
            if line2_mac2 in result2[i]:
                result2_num = (result2[i])
                print(result2[i])
                line2_Interface_name = result2_num.split()[0]
                print(line2_Interface_name)
            if line3_mac2 in result2[i]:
                result2_num = (result2[i])
                print(result2[i])
                line3_Interface_name = result2_num.split()[0]
                print(line3_Interface_name)
            if line4_mac2 in result2[i]:
                result2_num = (result2[i])
                print(result2[i])
                line4_Interface_name = result2_num.split()[0]
                print(line4_Interface_name)
            if line5_mac2 in result2[i]:
                result2_num = (result2[i])
                print(result2[i])
                line5_Interface_name = result2_num.split()[0]
                print(line5_Interface_name)
        if line1_Interface_name == None:
            raise Exception('获取wan1口对应接口名称失败')
        if line2_Interface_name == None:
            raise Exception('获取wan2口对应接口名称失败')
        if line3_Interface_name == None:
            raise Exception('获取wan3口对应接口名称失败')
        if line4_Interface_name == None:
            raise Exception('获取wan4口对应接口名称失败')
        if line5_Interface_name == None:
            raise Exception('获取wan5口对应接口名称失败')

        time.sleep(10)  # 等待检测,路由切换
        # 确认默认路由情况
        # 单线路默认路由变为:default via 192.168.11.1 dev eth2.2 equalize 不再有weight值
        wan1route1 = 'dev ' + line1_Interface_name
        print('wan1route:', wan1route1)
        roure1 = bytes(('ip route | grep "%s"') % line1_Interface_name, encoding="utf8")
        x = 0
        while x < 60:
            tn = telnetlib.Telnet(host=hostip, port=port,timeout=10)
            tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
            tn.read_until(b'login:'******'Password:'******'#')
            tn.write(roure1 + b'\n')
            # 输出结果,判断
            time.sleep(1)
            result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
            print('-------------------输出结果------------------------')
            # 命令执行结果
            # print('result:', result)
            result4 = result[1:]
            # print('result4', result4)
            result5 = result4.replace('\r\n', ' ')
            # print('result5', result5)
            tn.close()
            # wan2、wan3检测不通,这里只判断wan1的
            if 'default' in result5 and wan1route1 in result5:
                print('wan1路由在')
                break
            else:
                print(x)
                time.sleep(2)
                x += 1
        else:
            logger.info(u'wan1route1: %s' % wan1route1)
            logger.info(u'result5: %s' % result5)
            raise Exception('wan1默认路由显示有误')

        # 3、将wan2\wan3检测目标改正确,线路、路由切换回来
        wan_config.input_DestIP2('223.5.5.5')  # WAN2检测地址改可ping通,测试线路切换
        wan_config.input_DestIP3('223.5.5.5')  # WAN3检测地址改可ping通,测试线路切换
        wan_config.input_DestIP4('223.5.5.5')  # WAN4检测地址改可ping通,测试线路切换
        wan_config.input_DestIP5('223.5.5.5')  # WAN5检测地址改可ping通,测试线路切换
        wan_config.click_save()
        # 等待弹窗提示成功
        i = 0
        while i < 80:
            try:
                self.driver.implicitly_wait(1)
                wan_config.find_tipsshowin()
            except NoSuchElementException:
                time.sleep(1)
                i = i + 1
                print(i)
            else:
                tips = str(wan_config.getAttribute_byClass(wan_config.tipsshowin, 'tip-sign'))
                print(tips, i)
                if tips != 'success':
                    CapPic(self.driver)
                    logger.info(u'线路检测保存 异常')
                    raise Exception(u'线路检测保存 异常')
                break
        else:
            raise Exception(u'线路检测保存 未弹出提示框')
        # 切换标签页判断配置正确
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_GlobalConfig()
        time.sleep(1)
        DestIP5 = str(wan_config.getAttribute_byName(wan_config.DestIP5v, 'value'))
        self.assertEqual(DestIP5, '223.5.5.5', msg='wan5检测地址与设置不一致')

        # telnet获取接口名称及确认默认路由 检测通应该恢复5条默认路由
        wan1route_2 = 'dev ' + line1_Interface_name + ' weight '
        wan2route_2 = 'dev ' + line2_Interface_name + ' weight '
        wan3route_2 = 'dev ' + line3_Interface_name + ' weight '
        wan4route_2 = 'dev ' + line3_Interface_name + ' weight '
        wan5route_2 = 'dev ' + line3_Interface_name + ' weight '
        print('wan1route_2:', wan1route_2, 'wan2route_2:', wan2route_2, 'wan3route_2:', wan3route_2, 'wan4route_2:',
              wan4route_2, 'wan5route_2:', wan5route_2)
        time.sleep(10)  # 等待检测,路由切换
        # 获取接口名称
        x = 0
        while x < 60:
            tn = telnetlib.Telnet(host=hostip, port=port,timeout=10)
            tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
            tn.read_until(b'login:'******'Password:'******'#')
            # 确认默认路由情况
            tn.write(b'ip route' + b'\n')
            # 输出结果,判断
            time.sleep(1)
            result9 = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
            print('-------------------输出结果------------------------')
            # 命令执行结果
            # print('result9:', result9)
            result10 = result9[1:]
            # print('result10', result10)
            result11 = result10.replace('\r\n',' ')
            # print('result11', result11)
            tn.close()
            if (wan1route_2 in result11) and (wan2route_2 in result11) and (wan3route_2 in result11) and (
                    wan4route_2 in result11) and (wan5route_2 in result11):
                print('wan1/wan2/wan3/wan4/wan5路由在')
                break
            else:
                print(x)
                time.sleep(2)
                x += 1
        else:
            logger.info(u'wan1route_2: %s' % wan1route_2)
            logger.info(u'wan2route_2: %s' % wan2route_2)
            logger.info(u'wan3route_2: %s' % wan3route_2)
            logger.info(u'wan4route_2: %s' % wan4route_4)
            logger.info(u'wan5route_2: %s' % wan5route_4)
            logger.info(u'result11 %s' % result11)
            raise Exception('wan1/wan2/wan3/wan4/wan5默认路由显示有误')

        tn.close()  # tn.write('exit\n')
        self.driver.quit()
        logger.info('test_002_staticSW passed')
コード例 #28
0
    def test_004_PPPoEsw(self):
        u'''PPPOE+PPPOE接入上网以及线路切换'''
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        ConnectState = getAssertText('ConnectState')
        #1、 WAN2口改为pppoe接入
        wan_config.click_line2edit()
        time.sleep(1)
        access_mode = wan_config.selelement_byName(wan_config.connectionType)
        Select(access_mode).select_by_value('PPPOE')
        time.sleep(1)
        wan_config.input_pppoeUser('222')  # 输入上层网关配置的PPPoE账号密码
        wan_config.input_pppoePass('222')
        wan_config.click_save()
        time.sleep(10)
        self.driver.quit()  # 修改接口后 可能会回到登录页面 所以关闭,再打开

        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        # 断言
        n = 0
        while n < 30:
            wan_config.click_refresh()
            time.sleep(1)
            list_connectState1 = wan_config.getText_byXpath(
                wan_config.connectState1)
            list_connectState2 = wan_config.getText_byXpath(
                wan_config.connectState2)
            print(str(list_connectState1), str(list_connectState2))
            list_connectState = [
                str(list_connectState1),
                str(list_connectState2)
            ]
            # 动态接入 未获取到地址/wan口线未接入 都是未连接
            if all(t == ConnectState for t in list_connectState):
                print('WAN口均已连接', n)
                break
            else:
                time.sleep(2)
                n += 1
        else:
            raise Exception('WAN口未连接')
        # 获取两个wan口IP、mac,pppoe接口通过IP判断接口名,固定通过mac地址判断接口名
        line1_ip = str(wan_config.getText_byXpath(wan_config.line1IP))
        # print('line1_ip:', line1_ip)
        line2_ip = str(wan_config.getText_byXpath(wan_config.line2IP))
        # print('line2_ip:', line2_ip)

        time.sleep(10)  # 等待wan2路由生成

        # telnet获取接口名称及确认默认路由
        hostip = gettelnet('host')
        port = gettelnet('port')
        username = bytes(getweb('User'), encoding="utf8")
        password = bytes(getweb('Passwd'), encoding="utf8")
        # 获取接口名称
        tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
        tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        tn.read_until(b'login:'******'Password:'******'ip route' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 获取WAN1对应接口名称
        result1 = result[2:-7]
        print('result1', result1)
        result2 = result1.split(r'\r\n')
        print('result2', result2)

        for x in range(len(result2)):
            if line1_ip in result2[x]:
                result2_num1 = (result2[x])
                print(result2_num1)
                line1_Interface_name = result2_num1.split()[2]
                print(line1_Interface_name)
            if line2_ip in result2[x]:
                result2_num1 = (result2[x])
                print(result2_num1)
                line2_Interface_name = result2_num1.split()[2]
                print(line2_Interface_name)
        if line1_Interface_name == None:
            raise Exception('获取wan1口对应接口名称失败')
        if line2_Interface_name == None:
            raise Exception('获取wan2口对应接口名称失败')

        # 确认默认路由情况
        wan1route = 'nexthop dev ' + line1_Interface_name + ' weight '
        wan2route = 'nexthop dev ' + line2_Interface_name + ' weight '
        print('wan1route:', wan1route, 'wan2route:', wan2route)

        for i in range(len(result2)):
            if wan1route in result2[i]:
                wan1route_status = not None
                print('wan1路由在')
            if wan2route in result2[i]:
                wan2route_status = not None
                print('wan2路由在')
        if wan1route_status == None:
            raise Exception('wan1默认路由不存在')
        if wan2route_status == None:
            raise Exception('wan2默认路由不存在')
        tn.close()  # tn.write('exit\n')
        self.driver.quit()

        # 2、设置线路检测地址,验证线路切换
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        self.driver.maximize_window()
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        # 配置线路检测 检测3s 检测 3次,地址为223.5.5.5
        wan_config.click_GlobalConfig()
        time.sleep(1)
        wan_config.input_KeepLive1('3')
        wan_config.input_RetryTimes1('3')
        sel1 = wan_config.selelement_byName(wan_config.PriAddrType1)
        Select(sel1).select_by_value('others')
        time.sleep(0.5)
        wan_config.input_DestIP1('223.5.5.5')

        wan_config.input_KeepLive2('3')
        wan_config.input_RetryTimes2('3')
        sel2 = wan_config.selelement_byName(wan_config.PriAddrType2)
        Select(sel2).select_by_value('others')
        time.sleep(0.5)
        wan_config.input_DestIP2('1.2.3.4')  # WAN2配一个ping不通的地址,测试线路切换
        wan_config.click_save()
        time.sleep(2)
        # 等待弹窗提示成功
        i = 0
        while i < 80:
            try:
                self.driver.implicitly_wait(1)
                wan_config.find_tipsshowin()
            except NoSuchElementException:
                time.sleep(1)
                i = i + 1
                print(i)
            else:
                tips = str(
                    wan_config.getAttribute_byClass(wan_config.tipsshowin,
                                                    'tip-sign'))
                print(tips, i)
                if tips != 'success':
                    CapPic(self.driver)
                    logger.info(u'线路检测保存 异常')
                    raise Exception(u'线路检测保存 异常')
                break
        else:
            raise Exception(u'线路检测保存 未弹出提示框')
        # 切换标签页判断配置正确
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_GlobalConfig()
        time.sleep(1)
        KeepLive2 = str(
            wan_config.getAttribute_byName(wan_config.KeepLive2v, 'value'))
        RetryTimes2 = str(
            wan_config.getAttribute_byName(wan_config.RetryTimes2v, 'value'))
        DestIP2 = str(
            wan_config.getAttribute_byName(wan_config.DestIP2v, 'value'))
        self.assertEqual(KeepLive2, '3', msg='wan2检测间隔与设置不一致')
        self.assertEqual(RetryTimes2, '3', msg='wan2检测次数与设置不一致')
        self.assertEqual(DestIP2, '1.2.3.4', msg='wan2检测地址与设置不一致')

        # telnet确认默认路由(wan2检测地址不通,默认路由应切换成wan1)
        # wan2检测不通,这里只判断wan1的
        # 单线路默认路由变为ru:default dev ppp0 equalize  不再有weight值
        # (高通没有equalize):default via 192.168.12.1 dev eth0.3
        wan1route1 = 'default dev ' + line1_Interface_name
        print('wan1route:', wan1route1)
        roure1 = bytes(('ip route | grep "%s"') % line1_Interface_name,
                       encoding="utf8")
        time.sleep(10)  # 等待检测,路由切换
        x = 0
        while x < 60:
            tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
            tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
            tn.read_until(b'login:'******'Password:'******'\n')
            # 输出结果,判断
            time.sleep(1)
            result3 = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
            print('-------------------输出结果------------------------')
            # 命令执行结果
            # print('result3:', result3)
            # 获取WAN1对应接口名称
            result4 = result3[1:]
            # print('result4', result4)
            result5 = result4.replace('\r\n', ' ')
            # print('result5', result2)
            tn.close()
            if 'default' in result5 and wan1route1 in result5:
                print('wan1路由在')
                break
            else:
                print(x)
                time.sleep(2)
                x += 1
        else:
            logger.info(u'wan1route1: %s' % wan1route1)
            logger.info(u'result5 %s' % result5)
            raise Exception('wan1默认路由显示有误')

        # 3、将wan2检测目标改正确,线路、路由切换回来
        wan_config.input_DestIP2('223.5.5.5')  # WAN2检测地址改可ping通,测试线路切换
        wan_config.click_save()
        time.sleep(2)
        # 等待弹窗提示成功
        i = 0
        while i < 80:
            try:
                self.driver.implicitly_wait(1)
                wan_config.find_tipsshowin()
            except NoSuchElementException:
                time.sleep(1)
                i = i + 1
                print(i)
            else:
                tips = str(
                    wan_config.getAttribute_byClass(wan_config.tipsshowin,
                                                    'tip-sign'))
                print(tips, i)
                if tips != 'success':
                    CapPic(self.driver)
                    logger.info(u'线路检测保存 异常')
                    raise Exception(u'线路检测保存 异常')
                break
        else:
            raise Exception(u'线路检测保存 未弹出提示框')
        # 切换标签页判断配置正确
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_GlobalConfig()
        time.sleep(1)
        DestIP2 = str(
            wan_config.getAttribute_byName(wan_config.DestIP2v, 'value'))
        self.assertEqual(DestIP2, '223.5.5.5', msg='wan2检测地址与设置不一致')

        # 确认默认路由情况(wan2检测地址通,默认路由应切换成wan2)
        wan1route2 = 'nexthop dev ' + line1_Interface_name + ' weight '
        wan2route2 = 'nexthop dev ' + line2_Interface_name + ' weight '
        print('wan1route:', wan1route, 'wan2route:', wan2route)
        time.sleep(10)  # 等待检测,路由切换
        x = 0
        while x < 60:
            tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
            tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
            tn.read_until(b'login:'******'Password:'******'ip route' + b'\n')
            # 输出结果,判断
            time.sleep(1)
            result6 = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
            print('-------------------输出结果------------------------')
            # 命令执行结果
            # print('result6:', result6)
            # 获取WAN1对应接口名称
            result7 = result6[1:]
            # print('result7', result7)
            result8 = result7.replace('\r\n', ' ')
            # print('result8', result8)
            tn.close()
            if (wan1route2 in result8) and (wan2route2 in result8):
                print('wan1/wan2路由在')
                break
            else:
                print(x)
                time.sleep(2)
                x += 1
        else:
            logger.info(u'wan1route_2: %s' % wan1route2)
            logger.info(u'wan2route_2: %s' % wan2route2)
            logger.info(u'result8 %s' % result8)
            raise Exception('wan1/wan2默认路由显示有误')

        #取消线路检测
        wan_config.click_GlobalConfig()
        time.sleep(1)
        wan_config.input_KeepLive1('0')
        wan_config.input_KeepLive2('0')
        wan_config.click_save()
        # 等待弹窗提示成功
        i = 0
        while i < 80:
            try:
                self.driver.implicitly_wait(1)
                wan_config.find_tipsshowin()
            except NoSuchElementException:
                time.sleep(1)
                i = i + 1
                print(i)
            else:
                tips = str(
                    wan_config.getAttribute_byClass(wan_config.tipsshowin,
                                                    'tip-sign'))
                print(tips, i)
                if tips != 'success':
                    CapPic(self.driver)
                    logger.info(u'线路检测保存 异常')
                    raise Exception(u'线路检测保存 异常')
                break
        else:
            raise Exception(u'线路检测保存 未弹出提示框')
        # 切换标签页判断配置正确
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_GlobalConfig()
        time.sleep(1)
        KeepLive1 = str(
            wan_config.getAttribute_byName(wan_config.KeepLive1v, 'value'))
        KeepLive2 = str(
            wan_config.getAttribute_byName(wan_config.KeepLive2v, 'value'))
        self.assertEqual(KeepLive1, '0', msg='wan1检测间隔不为0')
        self.assertEqual(KeepLive2, '0', msg='wan2检测间隔不为0')
        # WAN1改回动态接入,得到正确的IP地址及网关地址
        wan_config.click_WANconfig()
        time.sleep(1)
        # WAN1
        wan_config.click_line1edit()
        time.sleep(1)
        access_mode = wan_config.selelement_byName(wan_config.connectionType)
        Select(access_mode).select_by_value('DHCP')
        wan_config.click_save()
        time.sleep(10)
        self.driver.quit()
        logger.info('test_004_PPPoEsw passed')
コード例 #29
0
    def test_003_5PPPoE(self):
        u'''五条线路PPPOE拨入'''
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        ConnectState = getAssertText('ConnectState')
        # WAN1改成pppoe
        wan_config.click_line1edit()
        time.sleep(1)
        access_mode = wan_config.selelement_byName(wan_config.connectionType)
        Select(access_mode).select_by_value('PPPOE')
        time.sleep(1)
        wan_config.input_pppoeUser('111')
        wan_config.input_pppoePass('111')
        wan_config.click_save()
        time.sleep(10)
        self.driver.quit()  # 修改接口后 可能会回到登录页面 所以关闭,再打开
        # WAN2口改为pppoe接入
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_line2edit()
        time.sleep(1)
        access_mode = wan_config.selelement_byName(wan_config.connectionType)
        Select(access_mode).select_by_value('PPPOE')
        time.sleep(1)
        wan_config.input_pppoeUser('222')  # 输入上层网关配置的PPPoE账号密码
        wan_config.input_pppoePass('222')
        wan_config.click_save()
        time.sleep(10)
        self.driver.quit()  # 修改接口后 可能会回到登录页面 所以关闭,再打开
        # WAN3口改为pppoe接入
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_line3edit()
        time.sleep(1)
        access_mode = wan_config.selelement_byName(wan_config.connectionType)
        Select(access_mode).select_by_value('PPPOE')
        time.sleep(1)
        wan_config.input_pppoeUser('333')  # 输入上层网关配置的PPPoE账号密码
        wan_config.input_pppoePass('333')
        wan_config.click_save()
        time.sleep(10)
        self.driver.quit()  # 修改接口后 可能会回到登录页面 所以关闭,再打开
        # WAN4口改为pppoe接入
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_line4edit()
        time.sleep(1)
        access_mode = wan_config.selelement_byName(wan_config.connectionType)
        Select(access_mode).select_by_value('PPPOE')
        time.sleep(1)
        wan_config.input_pppoeUser('444')  # 输入上层网关配置的PPPoE账号密码
        wan_config.input_pppoePass('444')
        wan_config.click_save()
        time.sleep(10)
        self.driver.quit()  # 修改接口后 可能会回到登录页面 所以关闭,再打开
        # WAN4口改为pppoe接入
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_line5edit()
        time.sleep(1)
        access_mode = wan_config.selelement_byName(wan_config.connectionType)
        Select(access_mode).select_by_value('PPPOE')
        time.sleep(1)
        wan_config.input_pppoeUser('555')  # 输入上层网关配置的PPPoE账号密码
        wan_config.input_pppoePass('555')
        wan_config.click_save()
        time.sleep(10)
        self.driver.quit()  # 修改接口后 可能会回到登录页面 所以关闭,再打开

        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        # 断言
        n = 0
        while n < 30:
            wan_config.click_refresh()
            time.sleep(1)
            list_connectState1 = wan_config.getText_byXpath(wan_config.connectState1)
            list_connectState2 = wan_config.getText_byXpath(wan_config.connectState2)
            list_connectState3 = wan_config.getText_byXpath(wan_config.connectState3)
            list_connectState4 = wan_config.getText_byXpath(wan_config.connectState4)
            list_connectState5 = wan_config.getText_byXpath(wan_config.connectState5)
            print(str(list_connectState1), str(list_connectState2), str(list_connectState3), str(list_connectState4),
                  str(list_connectState5))
            list_connectState = [str(list_connectState1), str(list_connectState2), str(list_connectState3),
                                 str(list_connectState4), str(list_connectState5)]
            # 动态接入 未获取到地址/wan口线未接入 都是未连接
            if all(t == ConnectState for t in list_connectState):
                print('WAN口均已连接', n)
                break
            else:
                time.sleep(2)
                n += 1
        else:
            raise Exception('WAN口未连接')
        time.sleep(2)

        # 获取两个wan口IP、mac,pppoe接口通过IP判断接口名,固定通过mac地址判断接口名
        line1_ip = str(wan_config.getText_byXpath(wan_config.line1IP))
        # print('line1_ip:', line1_ip)
        line2_ip = str(wan_config.getText_byXpath(wan_config.line2IP))
        # print('line2_ip:', line2_ip)
        line3_ip = str(wan_config.getText_byXpath(wan_config.line3IP))
        line4_ip = str(wan_config.getText_byXpath(wan_config.line4IP))
        line5_ip = str(wan_config.getText_byXpath(wan_config.line5IP))
        time.sleep(3)
        # telnet获取接口名称及确认默认路由
        # 获取接口名称
        hostip = gettelnet('host')
        port = gettelnet('port')
        username = bytes(getweb('User'), encoding="utf8")
        password = bytes(getweb('Passwd'), encoding="utf8")
        tn = telnetlib.Telnet(host=hostip, port=port,timeout=10)
        tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        tn.read_until(b'login:'******'Password:'******'ip route' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 获取WAN1对应接口名称
        result1 = result[2:-7]
        print('result1', result1)
        result2 = result1.split(r'\r\n')
        print('result2', result2)

        for x in range(len(result2)):
            if line1_ip in result2[x]:
                result2_num1 = (result2[x])
                print(result2_num1)
                line1_Interface_name = result2_num1.split()[2]
                print(line1_Interface_name)
            if line2_ip in result2[x]:
                result2_num1 = (result2[x])
                print(result2_num1)
                line2_Interface_name = result2_num1.split()[2]
                print(line2_Interface_name)
            if line3_ip in result2[x]:
                result2_num1 = (result2[x])
                print(result2_num1)
                line3_Interface_name = result2_num1.split()[2]
                print(line3_Interface_name)
            if line4_ip in result2[x]:
                result2_num1 = (result2[x])
                print(result2_num1)
                line4_Interface_name = result2_num1.split()[2]
                print(line4_Interface_name)
            if line5_ip in result2[x]:
                result2_num1 = (result2[x])
                print(result2_num1)
                line5_Interface_name = result2_num1.split()[2]
                print(line5_Interface_name)
        if line1_Interface_name == None:
            raise Exception('获取wan1口对应接口名称失败')
        if line2_Interface_name == None:
            raise Exception('获取wan2口对应接口名称失败')
        if line3_Interface_name == None:
            raise Exception('获取wan3口对应接口名称失败')
        if line4_Interface_name == None:
            raise Exception('获取wan4口对应接口名称失败')
        if line5_Interface_name == None:
            raise Exception('获取wan5口对应接口名称失败')

        # 确认默认路由情况
        wan1route = 'nexthop dev ' + line1_Interface_name + ' weight '
        wan2route = 'nexthop dev ' + line2_Interface_name + ' weight '
        wan3route = 'nexthop dev ' + line3_Interface_name + ' weight '
        wan4route = 'nexthop dev ' + line4_Interface_name + ' weight '
        wan5route = 'nexthop dev ' + line5_Interface_name + ' weight '
        print('wan1route:', wan1route, 'wan2route:', wan2route, 'wan3route:', wan3route, 'wan4route:', wan4route,
              'wan5route:', wan5route)

        for i in range(len(result2)):
            if wan1route in result2[i]:
                wan1route_status = not None
                print('wan1路由在')
            if wan2route in result2[i]:
                wan2route_status = not None
                print('wan2路由在')
            if wan3route in result2[i]:
                wan3route_status = not None
                print('wan3路由在')
            if wan4route in result2[i]:
                wan4route_status = not None
                print('wan4路由在')
            if wan5route in result2[i]:
                wan5route_status = not None
                print('wan5路由在')
        if wan1route_status == None:
            raise Exception('wan1默认路由不存在')
        if wan2route_status == None:
            raise Exception('wan2默认路由不存在')
        if wan3route_status == None:
            raise Exception('wan3默认路由不存在')
        if wan4route_status == None:
            raise Exception('wan4默认路由不存在')
        if wan5route_status == None:
            raise Exception('wan5默认路由不存在')

        tn.close()  # tn.write('exit\n')

        logger.info(u'五条线路PPPOE拨入 验证通过')

        # 取消线路检测
        wan_config.click_GlobalConfig()
        time.sleep(1)
        wan_config.input_KeepLive1('0')
        wan_config.input_KeepLive2('0')
        wan_config.input_KeepLive3('0')
        wan_config.input_KeepLive4('0')
        wan_config.input_KeepLive5('0')
        wan_config.click_save()
        # 等待弹窗提示成功
        i = 0
        while i < 80:
            try:
                self.driver.implicitly_wait(1)
                wan_config.find_tipsshowin()
            except NoSuchElementException:
                time.sleep(1)
                i = i + 1
                print(i)
            else:
                tips = str(wan_config.getAttribute_byClass(wan_config.tipsshowin, 'tip-sign'))
                print(tips, i)
                if tips != 'success':
                    CapPic(self.driver)
                    logger.info(u'线路检测保存 异常')
                    raise Exception(u'线路检测保存 异常')
                break
        else:
            raise Exception(u'线路检测保存 未弹出提示框')
        # 切换标签页判断配置正确
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_GlobalConfig()
        time.sleep(1)
        KeepLive1 = str(wan_config.getAttribute_byName(wan_config.KeepLive1v, 'value'))
        KeepLive2 = str(wan_config.getAttribute_byName(wan_config.KeepLive2v, 'value'))
        KeepLive3 = str(wan_config.getAttribute_byName(wan_config.KeepLive3v, 'value'))
        KeepLive4 = str(wan_config.getAttribute_byName(wan_config.KeepLive4v, 'value'))
        KeepLive5 = str(wan_config.getAttribute_byName(wan_config.KeepLive5v, 'value'))
        self.assertEqual(KeepLive1, '0', msg='wan1检测间隔不为0')
        self.assertEqual(KeepLive2, '0', msg='wan2检测间隔不为0')
        self.assertEqual(KeepLive3, '0', msg='wan3检测间隔不为0')
        self.assertEqual(KeepLive4, '0', msg='wan4检测间隔不为0')
        self.assertEqual(KeepLive5, '0', msg='wan5检测间隔不为0')
        # wan1改回动态接入,得到正确的IP地址及网关地址
        wan_config.click_WANconfig()
        time.sleep(1)
        # WAN1
        wan_config.click_line1edit()
        time.sleep(1)
        access_mode = wan_config.selelement_byName(wan_config.connectionType)
        Select(access_mode).select_by_value('DHCP')
        wan_config.click_save()
        time.sleep(10)
        self.driver.quit()
        logger.info('test_003_5PPPoE passed')
コード例 #30
0
    def test_002_static(self):
        u'''外网配置 - 固定接入'''
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        Staticline = getAssertText('Staticline')
        ConnectState = getAssertText('ConnectState')
        # 从外网配置页面获取WAN1口地址
        # 判断联网状态
        i = 0
        while i < 21:
            wan_config.click_refresh()
            time.sleep(1)
            list_conState = wan_config.getText_byXpath(
                wan_config.connectState1)
            print(str(list_conState), i)
            if str(list_conState) != ConnectState:
                time.sleep(3)
                i += 1
            else:
                break
        else:
            CapPic(self.driver)
            logger.info(u"WAN口未连接")
            raise Exception('WAN1 未连接')
        # WAN1 ip变量赋值,页面读取
        WAN1_ip = wan_config.getText_byXpath(wan_config.line1IP)
        # print('WAN1_ip=',WAN1_ip)
        WAN1_gw = wan_config.getText_byXpath(wan_config.line1gw)
        # print('WAN1_gw=',WAN1_gw)
        WAN1_dns = wan_config.getText_byXpath(wan_config.line1Dns)
        # print('WAN1_dns=',WAN1_dns)
        time.sleep(1)
        # 将wan1口的IP/网关/dns 拿来输入
        wan_config.click_line1edit()
        time.sleep(1)
        access_mode = wan_config.selelement_byName(wan_config.connectionType)
        Select(access_mode).select_by_value('STATIC')
        time.sleep(1)
        wan_config.input_staticIp(WAN1_ip)
        wan_config.input_staticGateway(WAN1_gw)
        wan_config.input_staticPriDns(WAN1_dns)
        wan_config.click_save()
        time.sleep(10)
        self.driver.quit()  # 修改接口后 可能会回到登录页面 所以关闭,再打开

        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 进入网络配置-外网配置
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        #断言
        list_lineType = wan_config.getText_byXpath(wan_config.line1Type)
        print('list_lineType', list_lineType)
        self.assertEqual(str(list_lineType), Staticline, msg='连接类型 不为 固定接入')
        # 判断联网状态
        i = 0
        while i < 21:
            wan_config.click_refresh_s()
            time.sleep(1)
            list_conState = wan_config.getText_byXpath(
                wan_config.connectState1)
            print(str(list_conState), i)
            if str(list_conState) != ConnectState:
                time.sleep(3)
                i += 1
            else:
                break
        else:
            CapPic(self.driver)
            logger.info(u"WAN口未连接")
            raise Exception('WAN1 未连接')
        i = 0
        while i < 21:
            # 判断联网 ,不能上网则报错
            # pingTestIP('114.114.114.114')
            p = pingTestIP('www.baidu.com')
            print(p, i)
            if p == 'N':
                i += 1
                time.sleep(3)
            else:
                break
        else:
            logger.info(u"connect failed")
            raise Exception('connect failed.')

        self.driver.quit()
        logger.info('test_002_static passed')