Exemple #1
0
    def test_005_cloundDownloadFile(self):
        u'''验证 支持云管理检测下发新版本'''
        # 连接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'cat  /sbin/lua/Router/genMqttPak.lua | grep DownloadFile' +
                 b'\n')
        # 输出结果,判断
        time.sleep(0.5)
        result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 判断
        if "function DownloadFile(msg)" in result:
            print('设备支持云管理检测下发新版本')
        else:
            raise Exception('设备支持云管理检测下发新版本方法未存在')  # 如果没有则报错

        tn.close()  # tn.write('exit\n')
        logger.info('test_005_cloundDownloadFile passed')
Exemple #2
0
    def test_003_MTKlibuClibc(self):
        u'''验证 MTK确认库版本升级'''
        # 连接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'ls /lib/|grep libuClibc | grep -v grep' + b'\n')
        # 输出结果,判断
        time.sleep(0.5)
        result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 判断
        if "libuClibc-0.9.33.2.so" in result:
            print('success')
        else:
            raise Exception('MTK确认库版本升级 验证失败')  # 如果没有则报错

        tn.close()  # tn.write('exit\n')
        logger.info('test_003_MTKlibuClibc passed')
Exemple #3
0
    def test_004_X86_CONFIG4KSTACKS(self):
        u'''验证 X86设备内核CONFIG_4KSTACKS关闭'''
        # 连接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'cat /sbin/config.sh | grep CONFIG_4KSTACKS' + b'\n')
        # 输出结果,判断
        time.sleep(0.5)
        result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 判断
        if "CONFIG_4KSTACKS=y" not in result:
            print('X86设备内核CONFIG_4KSTACKS已关闭')
        else:
            raise Exception('X86设备内核CONFIG_4KSTACKS未关闭')  # 如果没有则报错

        tn.close()  # tn.write('exit\n')
        logger.info('test_004_X86_CONFIG4KSTACKS passed')
    def test_005_telnet(self):
        u'''命令行登录:telnet(内部)'''

        # 连接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'ps | grep telnetd | grep -v grep' + b'\n')
        # 输出结果,判断
        time.sleep(0.5)
        result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 判断
        if ("telnetd -b %s " % hostip) in result:
            print('telnetd默认未仅对lan口开放 验证成功')
        else:
            raise Exception('telnetd默认未仅对lan口开放 验证失败')  # 如果没有则报错
        tn.close()  # tn.write('exit\n')
        self.driver.quit()
        logger.info('test_005_telnet passed')
Exemple #5
0
    def test_002_uttWaitSerch(self):
        u'''验证 自动激活保修期'''
        time.sleep(60)  #001中刚重启好,进程可能没有完全启动完毕,等待一下
        # 连接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'ps | grep uttWaitSerch | grep -v grep' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 判断
        if "uttWaitSerch -f" in result:
            print('success')
        else:
            raise Exception('自动激活保修期 验证失败')  #如果没有则报错

        tn.close()  # tn.write('exit\n')
        logger.info('test_002_uttWaitSerch passed')
Exemple #6
0
    def test_changeWAN2(self):
        u'''调整wan2 与上联口 互通'''
        ##交换机9、10、11、12、13分别与被测路由wan1 - wan5相连,15口与上级路由lan口相连
        #设置wan2 与 上联口 通

        # telnet交换机
        hostip = gettelnet('switchURL')
        port = gettelnet('switchport')
        password = bytes(gettelnet('switchPwd'), encoding="utf8")
        # 获取接口名称
        tn = telnetlib.Telnet(host=hostip, port=port)
        tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        tn.read_until(b'UTT>')
        tn.write(b'enable' + b"\n")
        tn.read_until(b'password:'******'UTT#')
        tn.write(b'configure terminal' + b'\n')
        # 10口与14口通(9口与1-13、15-26口隔离) #在初始化的基础上修改 不隔离15口
        tn.read_until(b'UTT(config)#')
        tn.write(b'interface gigabitEthernet 0/10' + b'\n')
        tn.read_until(b'UTT(config-if-gigaEthernet-0/10)#')
        tn.write(b'no isolate-port interface gigabitEthernet 0/15' + b'\n')
        tn.read_until(b'UTT(config-if-gigaEthernet-0/10)#')
        tn.write(b'end' + b'\n')

        # 输出结果,判断
        tn.read_until(b'UTT#')
        tn.write(b'show isolate-port' + b'\n')
        time.sleep(1)
        result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        # print('result:', result)
        # 获取WAN1对应接口名称
        result1 = result[1:]
        print('result1', result1)
        g9 = 'Gi 0/9 : Gi 0/1 Gi 0/2 Gi 0/3 Gi 0/4 Gi 0/5 Gi 0/6 Gi 0/7 Gi 0/8 Gi 0/10 Gi 0/11 Gi 0/12 Gi 0/13 ' \
             'Gi 0/14 Gi 0/16 Gi 0/17 Gi 0/18 Gi 0/19 Gi 0/20 Gi 0/21 Gi 0/22 Gi 0/23 Gi 0/24 Gi 0/25 Gi 0/26'
        g10 = 'Gi 0/10 : Gi 0/1 Gi 0/2 Gi 0/3 Gi 0/4 Gi 0/5 Gi 0/6 Gi 0/7 Gi 0/8 Gi 0/9 Gi 0/11 Gi 0/12 Gi 0/13 ' \
              'Gi 0/14 Gi 0/16 Gi 0/17 Gi 0/18 Gi 0/19 Gi 0/20 Gi 0/21 Gi 0/22 Gi 0/23 Gi 0/24 Gi 0/25 Gi 0/26'
        g11 = 'Gi 0/11 : Gi 0/1 Gi 0/2 Gi 0/3 Gi 0/4 Gi 0/5 Gi 0/6 Gi 0/7 Gi 0/8 Gi 0/9 Gi 0/10 Gi 0/12 Gi 0/13 ' \
              'Gi 0/14 Gi 0/15 Gi 0/16 Gi 0/17 Gi 0/18 Gi 0/19 Gi 0/20 Gi 0/21 Gi 0/22 Gi 0/23 Gi 0/24 Gi 0/25 Gi 0/26'
        g12 = 'Gi 0/12 : Gi 0/1 Gi 0/2 Gi 0/3 Gi 0/4 Gi 0/5 Gi 0/6 Gi 0/7 Gi 0/8 Gi 0/9 Gi 0/10 Gi 0/11 Gi 0/13 ' \
              'Gi 0/14 Gi 0/15 Gi 0/16 Gi 0/17 Gi 0/18 Gi 0/19 Gi 0/20 Gi 0/21 Gi 0/22 Gi 0/23 Gi 0/24 Gi 0/25 Gi 0/26'
        g13 = 'Gi 0/13 : Gi 0/1 Gi 0/2 Gi 0/3 Gi 0/4 Gi 0/5 Gi 0/6 Gi 0/7 Gi 0/8 Gi 0/9 Gi 0/10 Gi 0/11 Gi 0/12 ' \
              'Gi 0/14 Gi 0/15 Gi 0/16 Gi 0/17 Gi 0/18 Gi 0/19 Gi 0/20 Gi 0/21 Gi 0/22 Gi 0/23 Gi 0/24 Gi 0/25 Gi 0/26'
        g15 = 'Gi 0/15 : Gi 0/1 Gi 0/2 Gi 0/3 Gi 0/4 Gi 0/5 Gi 0/6 Gi 0/7 Gi 0/8 Gi 0/11 Gi 0/12 Gi 0/13 ' \
              'Gi 0/14 Gi 0/16 Gi 0/17 Gi 0/18 Gi 0/19 Gi 0/20 Gi 0/21 Gi 0/22 Gi 0/23 Gi 0/24 Gi 0/25 Gi 0/26'
        Interface = [g9, g10, g11, g12, g13, g15]
        if all(t in result1 for t in Interface):
            logger.info(u'交换机changeWAN2 完成')
        else:
            logger.info(u'Interface: %s' % Interface)
            logger.info(u'result1: %s' % result1)
            raise Exception(u'调整wan2与上联口 互通异常')
        tn.close()

        logger.info(u'调整wan2 与上联口 互通 完成')
    def test_002_unMount(self):
        u'''U盘弹出 显示'''

        sharing = NetworkSharingPage(self.driver, self.url)
        # 弹出设备
        sharing.click_Eject()
        time.sleep(1)
        sharing.click_ok()
        time.sleep(2)
        #弹出后使用率、容量等都为0
        # U盘使用率
        UsageRate = sharing.getText_byXpath(sharing.UsageRate)
        self.assertEqual(UsageRate, '0', msg='弹出后U盘使用率 显示异常')
        # U盘总容量 已使用容量 剩余容量 三个值+提示是一个元素,判断条件特殊
        # U盘总容量 后元素(所有)
        Total = sharing.getText_byXpath(sharing.Total)
        # “已使用容量”提示
        Usedtext = sharing.getText_byXpath(sharing.Usedtext)
        # “剩余容量”提示
        Residualtext = sharing.getText_byXpath(sharing.Residualtext)
        Total1 = '0' + Usedtext + ' 0' + Residualtext + ' 0'
        if Total == Total1:
            print('弹出后U盘总容量信息 显示正常')
        else:
            raise Exception('弹出后U盘总容量信息 显示异常')
        # 连接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'mount | grep /media/' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 后台实际应有的结果
        result1 = 'codepage=cp437,iocharset=utf8'
        # 判断
        if result1 not in result:
            print('卸载后mount显示 验证成功')
        else:
            raise Exception('卸载后mount显示 验证失败')  # 如果没有则报错
        tn.close()  # tn.write('exit\n')

        self.driver.quit()
        logger.info('test_002_unMount passed')
    def test_001_Mount(self):
        u'''U盘挂载 显示'''

        sharing = NetworkSharingPage(self.driver, self.url)
        # U盘使用率
        UsageRate = sharing.getText_byXpath(sharing.UsageRate)
        self.assertIn('%', UsageRate, msg='U盘使用率 显示异常')
        # U盘总容量 已使用容量 剩余容量 三个值+提示是一个元素,判断条件特殊
        # U盘总容量 后元素(所有)
        Total = sharing.getText_byXpath(sharing.Total)
        # “已使用容量”提示
        Usedtext = sharing.getText_byXpath(sharing.Usedtext)
        Usedtext1 = 'M' + Usedtext
        # “剩余容量”提示
        Residualtext = sharing.getText_byXpath(sharing.Residualtext)
        Residualtext1 = 'M' + Residualtext
        if Usedtext1 in Total and Residualtext1 in Total:
            print('U盘总容量信息 显示正常')
        else:
            raise Exception('U盘总容量信息 显示异常')
        # 连接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'mount | grep /media/' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 后台实际应有的结果
        result1 = 'codepage'
        result2 = 'iocharset=utf8'
        # 判断
        if result1 in result and result2 in result:
            print('挂载mount显示 验证成功')
        else:
            raise Exception('挂载mount显示 验证失败')  # 如果没有则报错
        tn.close()  # tn.write('exit\n')

        self.driver.quit()
        logger.info('test_001_Mount passed')
Exemple #9
0
    def test_WanToLan(self):
        u'''PC口改回与lan口 互通'''
        ##交换机9、10、11、12、13分别与被测路由wan1 - wan5相连,14口与上级路由lan口相连,19口与测试pc相连
        # 设置19口 与 lan口 通

        # telnet交换机
        hostip = gettelnet('switchURL')
        port = gettelnet('switchport')
        password = bytes(gettelnet('switchPwd'), encoding="utf8")
        # 获取接口名称
        tn = telnetlib.Telnet(host=hostip, port=port)
        tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        tn.read_until(b'UTT>')
        tn.write(b'enable' + b"\n")
        tn.read_until(b'password:'******'UTT#')
        tn.write(b'configure terminal' + b'\n')
        # 19口与AP1-8/14/17口通(19口与9-13、15-16、18、19-26口隔离)
        tn.read_until(b'UTT(config)#')
        tn.write(b'interface gigabitEthernet 0/19' + b'\n')
        tn.read_until(b'UTT(config-if-gigaEthernet-0/19)#')
        tn.write(b'no isolate-port interface gigabitEthernet 0/1-0/26' + b'\n')
        tn.read_until(b'UTT(config-if-gigaEthernet-0/19)#')
        tn.write(
            b'isolate-port interface gigabitEthernet 0/9-0/13,0/15-0/16,0/18,0/20-0/26'
            + b'\n')
        tn.read_until(b'UTT(config-if-gigaEthernet-0/19)#')
        tn.write(b'end' + b'\n')

        # 输出结果,判断
        tn.read_until(b'UTT#')
        tn.write(b'show isolate-port' + b'\n')
        time.sleep(1)
        result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        # print('result:', result)
        # 获取WAN1对应接口名称
        result1 = result[1:]
        print('result1', result1)
        g19 = 'Gi 0/19 : Gi 0/9 Gi 0/10 Gi 0/11 Gi 0/12 Gi 0/13 Gi 0/15 Gi 0/16 Gi 0/18 Gi 0/20 Gi 0/21 ' \
              'Gi 0/22 Gi 0/23 Gi 0/24 Gi 0/25 Gi 0/26 '

        if g19 in result1:
            logger.info(u'调整PC接线口 与上联口/wan1口 互通完成')
        else:
            logger.info(u'g19: %s' % g19)
            logger.info(u'result1: %s' % result1)
            raise Exception(u'调整PC接线口 与上联口/wan1口 互通异常')
        tn.close()
        logger.info(u'pc口改回与lan口 互通 完成')
    def tearDown(self):
        # 设置了指定IP,这里增加一个判断联网
        host = gettelnet('host').split(r'.')
        host1 = host[0] + '.' + host[1] + '.' + host[2] + '.'
        pcaddr = socket.gethostbyname(socket.getfqdn(socket.gethostname()))
        print(pcaddr)
        pingTestIP()  # 避免判断失误
        p = pingTestIP()
        if p == 'N' or host1 not in pcaddr:  # 如果不通 or 地址不为lan口网段
            # 1、改回DHCP, 调用bat脚本
            os.system('%s' % (batpath + 'changeDhcpIp.bat'))
            time.sleep(5)
            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('未获取到地址')

        logger.info('tearDown over')
        logger.info('%s' % ('=' * 50))
    def test_003_samba(self):
        u'''samba服务器(部分型号暂未支持)'''

        host = gettelnet('host')
        ftpSmaba = NetworkSharingPage(self.driver, self.url)
        #1、未开启验证无法登录
        user_name = "anonymous"
        pass_word = ""
        my_name = "anyname"
        domain_name = ""
        remote_smb_IP = host
        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 无法访问 验证通过')

        #2、打开samba
        sambaEn = ftpSmaba.getAttribute_byName(ftpSmaba.sambaEnS, 'checked')
        if sambaEn != 'true':
            ftpSmaba.click_sambaEn()
            ftpSmaba.click_save()
        time.sleep(13)
        sambaEn = str(
            ftpSmaba.getAttribute_byName(ftpSmaba.sambaEnS, 'checked'))
        self.assertEqual(sambaEn, 'true', msg='samba开启 失败')
        #samba登录
        smb = SMBConnection(user_name,
                            pass_word,
                            my_name,
                            domain_name,
                            use_ntlm_v2=True)
        try:
            smb.connect(remote_smb_IP, 139, timeout=3)
        except socket.timeout:
            raise Exception('samba服务无法访问')
        shareslist = smb.listShares()  # 列出共享目录 这里只能看到1级菜单“1”
        smb.close()
        n = []
        for i in shareslist:
            n.append(i.name)
        print(n)
        nn = []
        for x in n:
            if '$' not in x:
                nn.append(x)
                print(nn)
        #3、打开验证
        if '1' in nn:
            pass
        else:
            raise Exception('samba验证失败')  # 如果没有则报错

        self.driver.quit()
        logger.info('test_003_samba passed')
Exemple #12
0
    def test_001_openWebAuth(self):
        u'''web认证开启'''
        host = gettelnet('host').split(r'.')
        host1 = host[0] + '.' + host[1] + '.' + host[2] +'.'
        # 006中设置了指定IP,这里增加一个判断联网
        pcaddr = socket.gethostbyname(socket.getfqdn(socket.gethostname()))
        print(pcaddr)
        pingTestIP()  # 避免判断失误

        p = pingTestIP()
        if p == 'N' or host1 not in pcaddr:  # 如果不通 or 地址不为lan口网段
            # 1、改回DHCP, 调用bat脚本
            os.system('%s' % (batpath + 'changeDhcpIp.bat'))
            time.sleep(5)
            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('未获取到地址')

        if Support == '√':
            logger.info(u'参数支持本地认证')
            organization_group.import_empty_template(self)  # 判断组织架构是否有其他组 有则清空

            # 打开用户管理 - 用户认证
            login.loginWeb(self)  # admin账号登录
            self.driver.implicitly_wait(10)
            webauth = Organization_userAuthPage(self.driver, self.url)
            # 打开用户管理 - 用户认证
            webauth.click_UserManage()
            time.sleep(0.5)
            webauth.click_userAuth()
            time.sleep(1)
            #开启web认证
            webauth.click_WebAuthEn()
            time.sleep(1)
            # 断言 提示信息是否有误
            status = str(webauth.getAttribute_byXpath(webauth.WebAuthEs,'checked'))
            time.sleep(1)
            self.assertEqual(status,'true',msg='web认证开启出错')
            self.driver.quit()
        elif Support == '×':
            logger.info(u'参数不支持本地认证')
        logger.info('test_001_openWebAuth passed')
Exemple #13
0
def getCPUmodel():
    host = gettelnet('host')
    port = gettelnet('port')
    username = bytes(getweb('User'), encoding="utf8")
    password = bytes(getweb('Passwd'), encoding="utf8")

    tn = telnetlib.Telnet(host=host, port=port, timeout=10)
    tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
    # 输入登录用户名
    tn.read_until(b'login:'******'Password:'******'#')
    tn.write(b"cat /proc/cpuinfo" + b'\n')
    # 输出结果,判断
    time.sleep(1)
    result = str(tn.read_very_eager())  # 只会存最后一条命令的结果
    print('-------------------输出结果------------------------')
    # 命令执行结果
    print('result:', result)
    # 判断
    if "system type             : MT762" in result:
        CPUmodel = 'MTK'
    elif "model name      : Intel" in result:
        CPUmodel = 'X86'
    elif "platform        : P1010" in result:
        CPUmodel = 'P1010'
    elif "system type             : Qualcomm" in result:
        CPUmodel = 'Qualcomm'
    else:
        raise Exception('平台判断出错')
    tn.close()  # tn.write('exit\n')

    return CPUmodel


# print(getCPUmodel())
    def test_002_close(self):
        u'''关闭负载均衡'''
        v1APname = getweb('v1APname')
        port = gettelnet('port')
        username = bytes(getweb('User'), encoding="utf8")
        password = bytes(getweb('Passwd'), encoding="utf8")
        device = deviceMgmtPage(self.driver, self.url)
        device.click_wirelessExtension()
        time.sleep(0.5)
        device.click_deviceMgmt()
        time.sleep(1)
        device.input_search(v1APname)
        device.click_searchB()
        list_ip1 = device.getText_byXpath(device.list_IP1)

        load = loadBalancingPage(self.driver, self.url)
        load.click_loadBalancing()
        time.sleep(1)
        load.click_checkOpen()
        time.sleep(1)
        checkOpens = load.getAttribute_byId(load.checkOpens, 'checktype')
        self.assertEqual(checkOpens, '0', msg='负载均衡 关闭失败')
        time.sleep(8)

        tn = telnetlib.Telnet(host=list_ip1, port=port)
        tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        # 输入登录用户名
        tn.read_until(b'login:'******'Password:'******'#')
        tn.write(b'iwpriv ra0 get Config | grep uttMaxStaNum' + b'\n')  # 无线隔离
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        # print('result:', result)
        # 判断
        if "uttMaxStaNum:       32" in result:
            logger.info('负载均衡关闭 AP资源数正常')
        else:
            logger.info('负载均衡关闭 AP资源数异常')
            logger.info('result:', result)
            raise Exception('负载均衡关闭 AP资源数异常')
        tn.close()  # tn.write('exit\n')

        self.driver.quit()
        logger.info('test_002_close passed')
Exemple #15
0
 def tearDown(self):
     host = gettelnet('host')
     port = gettelnet('port')
     try:
         telnetlib.Telnet(host, port= port, timeout=10)
     except socket.timeout:
         # 将IP改回自动获取(设置dns为自动获取)
         os.system('%s' % (batpath + 'changeDhcpIp.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('未获取到地址')
     login.loginWeb(self)  # admin账号登录
     self.driver.implicitly_wait(10)
     accesscontrol = ManagementPolicyPage(self.driver, self.url)
     # 进入系统配置-网管策略-内网访问控制
     accesscontrol.click_sysConfig()
     time.sleep(0.5)
     accesscontrol.click_ManagementPolicy()
     time.sleep(1)
     accesscontrol.click_lanAccessControl()
     time.sleep(1)
     accesscontrol.click_innerAccessControlC()
     accesscontrol.click_save()
     time.sleep(1)
     self.driver.quit()
     logger.info('tearDown over')
     logger.info('%s' % ('=' * 50))
    def test_001_AccessMode(self):
        u'''https模式登录'''
        host = gettelnet('host')
        RouteUrls = 'https://' + host + '/'

        # 修改网管模式,端口切换到443,https模式下可登录设备
        accessStrategy = ManagementPolicyPage(self.driver, self.url)
        accessStrategy.click_httpswebEn()
        accessStrategy.click_save()
        # 加个判断 某些型号等待时间长(6550G)
        time.sleep(1)
        x = 0
        while x < 15:
            now_url = str(self.driver.current_url)
            print(now_url, x)
            if '/noAuth/login.html' not in now_url:  # 如果不同
                time.sleep(2)
            else:
                break
            x += 1
        self.driver.quit()

        #https模式下验证登录设备
        login.test_enableLoginWeb(self, url=RouteUrls)  #https登录
        accessStrategy = ManagementPolicyPage(self.driver, self.url)
        # 改回http 方式登录
        accessStrategy.click_sysConfig()
        time.sleep(0.5)
        accessStrategy.click_ManagementPolicy()
        time.sleep(1)
        accessStrategy.click_AccessPolicy()
        time.sleep(1)
        accessStrategy.click_httpwebEn()
        accessStrategy.click_save()
        time.sleep(1)
        i = 0
        while i < 30:
            url = self.driver.current_url
            if '/login.html' in url:
                break
            else:
                time.sleep(2)
            i += 1

        self.driver.quit()
        logger.info('test_001_AccessMode passed')
    def test_001_ServerStatus(self):
        u'''DHCP服务器功能默认开启'''
        host = gettelnet('host')

        #即插即用中修改了IP 这里加一个判断联网
        pingTestIP()  #避免失误
        p = pingTestIP()
        if p == 'N':
            # 将IP改回自动获取(设置dns为自动获取)
            # 调用bat脚本
            os.system('%s' % (batpath + 'changeDhcpIp.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:
                    logger.info(u'IP地址已自动获取成功')
                    break
            else:
                raise Exception('未获取到地址')
        pcaddr = socket.gethostbyname(socket.getfqdn(socket.gethostname()))
        logger.info(u'IP地址为:%s' % pcaddr)
        login.loginWeb(self)
        self.driver.implicitly_wait(10)
        dhcpserver = DHCPserverpage(self.driver, self.url)
        # 打开网络配置 - 内网配置
        dhcpserver.click_NetworkConfig()
        time.sleep(0.5)
        dhcpserver.click_DHCPserver()
        time.sleep(1)
        #确认 DHCP服务器功能 是否 默认开启
        dhcp_status = dhcpserver.getAttribute_byXpath(dhcpserver.dhcpEn,
                                                      'checked')
        self.assertEqual(str(dhcp_status), 'true', msg='DHCP服务器功能默认未开启')
        self.driver.quit()
        logger.info('test_001_ServerStatus passed')
    def tearDown(self):
        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)
                time.sleep(2)
                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('未获取到地址')
        logger.info('tearDown over')
        logger.info('%s' % ('=' * 50))
Exemple #19
0
import time
import unittest
import os.path
import telnetlib
import socket
from selenium import webdriver
from common.LogGen import LogGen
from common.CapPic import CapPic
from common.ReadConfig import getweb,gettelnet
from common.loginRoute import login
from common.organization_edit import organization_group
from pages.sysConfig_001_ManagementPolicyPage import ManagementPolicyPage
logger = LogGen(Logger = 'sysConfig_004_LANAccessControl').getlog()
batpath = os.path.dirname(os.path.abspath('.')) + '/script/'
batSameIP = getweb('batSameIP')
host = gettelnet('host')

class LanAccessControl(unittest.TestCase):

    def setUp(self):
        logger.info('setUp start')
        login.loginWeb(self) #admin账号登录
        self.driver.implicitly_wait(10)
        accesscontrol = ManagementPolicyPage(self.driver,self.url)
        #进入系统配置-网管策略-内网访问控制
        accesscontrol.click_sysConfig()
        time.sleep(0.5)
        accesscontrol.click_ManagementPolicy()
        time.sleep(1)
        accesscontrol.click_lanAccessControl()
        time.sleep(1)
Exemple #20
0
'''

import time
import unittest
import telnetlib
from selenium.webdriver.support.select import Select
from common.LogGen import LogGen
from common.CapPic import CapPic
from common.ReadConfig import gettelnet, getweb
from common.GetRouteCPU import getCPUmodel
from common.loginRoute import login
from pages.NetConfig_002_LANpage import NetworkConfig_LANpage
from pages.NetConfig_003_DHCPserverpage import DHCPserverpage
from pages.wifiConfig_001_BasicConfigPage import BasicConfigPage
logger = LogGen(Logger='WIFIconfig_002_BasicSet').getlog()
host = gettelnet('host')
port = gettelnet('port')
username = bytes(getweb('User'), encoding="utf8")
password = bytes(getweb('Passwd'), encoding="utf8")
cpumodel = getCPUmodel()


class BasicSet(unittest.TestCase):
    def setUp(self):
        logger.info('setUp start')
        login.loginWeb(self)  #admin账号登录
        self.driver.implicitly_wait(10)
        # pass

    def test_001_wifi2(self):
        u'''2.4G无线加密、限速、无线vlan'''
    def test_006_binding(self):
        u'''启用ip/mac绑定生效;删除组织架构中的成员,查看绑定是否生效(是否可上网)'''
        host = gettelnet('host')
        # 判断联网 ,不能上网则报错
        p = pingTestIP('www.163.com')
        if p == 'N':
            raise Exception('connect failed.')

        # # 获取本机ip 默认有线地址,有线断开会显示无线
        # pcaddr = socket.gethostbyname(socket.getfqdn(socket.gethostname()))

        # 调用bat脚本 地址修改为非绑定地址 192.168.1.39 网关192.168.1.1
        if '192.168.1.1' in host:
            os.system(('%s' % batpath + 'changeStaticIP2_1duan.bat'))
        elif '192.168.16.1' in host:
            os.system(('%s' % batpath + 'changeStaticIP2_16duan.bat'))
        else:
            raise Exception('lan口非 1网段、16网段')
        time.sleep(5)
        n = 0
        while n < 30:
            # 获取本机ip 默认有线地址,有线断开会显示无线
            pcaddr1 = socket.gethostbyname(socket.getfqdn(
                socket.gethostname()))
            print(pcaddr1, n)
            if str(pcaddr1) != batSameIP:
                time.sleep(2)
                n += 1
            else:
                print('地址已修改为非绑定地址 192.168.1.39', n)
                break
        else:
            raise Exception('地址修改为非绑定地址 192.168.1.39失败')

        # 判断联网 ,切换非绑定IP后应该不能上网
        time.sleep(5)
        pingTestIP('114.114.114.114')
        pingTestIP('www.baidu.com')
        time.sleep(2)
        p = pingTestIP('www.baidu.com')
        if p == 'Y':
            logger.info('非绑定IP 依旧可以上网')
            logger.info(u'pc当前mac为:%s' % pcaddr1)
            raise Exception('非绑定IP 依旧可以上网')

        # 将IP改回自动获取(设置dns为自动获取)
        # 调用bat脚本
        os.system(('%s' % batpath + 'changeDhcpIp.bat'))
        time.sleep(5)
        n = 0
        while n < 30:
            # 获取本机ip 默认有线地址,有线断开会显示无线
            pcaddr1 = socket.gethostbyname(socket.getfqdn(
                socket.gethostname()))
            print(pcaddr1, n)
            if '192.168.' not in str(pcaddr1):
                time.sleep(2)
                n += 1
            else:
                print('IP地址已自动获取成功', n)
                break
        else:
            raise Exception('未获取到地址')

        #删除绑定绑定 清空组
        organization_group.group_delete(self)

        # 调用bat脚本 地址修改为非绑定地址 192.168.1.39 网关192.168.1.1
        if '192.168.1.1' in host:
            os.system(('%s' % batpath + 'changeStaticIP2_1duan.bat'))
        elif '192.168.16.1' in host:
            os.system(('%s' % batpath + 'changeStaticIP2_16duan.bat'))
        else:
            raise Exception('lan口非 1网段、16网段')
        time.sleep(5)
        n = 0
        while n < 30:
            # 获取本机ip 默认有线地址,有线断开会显示无线
            pcaddr1 = socket.gethostbyname(socket.getfqdn(
                socket.gethostname()))
            print(pcaddr1, n)
            if str(pcaddr1) != batSameIP:
                time.sleep(2)
                n += 1
            else:
                print('地址已修改为非绑定地址 192.168.1.39', n)
                break
        else:
            raise Exception('地址修改为非绑定地址 192.168.1.39失败')

        # 判断联网 ,删除绑定后 切换非绑定IP后应该能上网
        time.sleep(3)
        p = pingTestIP('www.163.com')
        if p == 'N':
            raise Exception('connect failed.')

        # 将IP改回自动获取(设置dns为自动获取)
        # 调用bat脚本
        os.system(('%s' % batpath + 'changeDhcpIp.bat'))
        time.sleep(5)
        n = 0
        while n < 30:
            # 获取本机ip 默认有线地址,有线断开会显示无线
            pcaddr1 = socket.gethostbyname(socket.getfqdn(
                socket.gethostname()))
            print(pcaddr1, n)
            if '192.168.' not in str(pcaddr1):
                time.sleep(2)
                n += 1
            else:
                print('IP地址已自动获取成功', n)
                break
        else:
            raise Exception('未获取到地址')
        logger.info('test_006_binding passed')
Exemple #22
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')
Exemple #23
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')
Exemple #24
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')
    def test_007_passwdAcessSAMBA(self):
        u'''启用/取消 密码访问samba'''
        host = gettelnet('host')
        User = getweb('User')
        Passwd = getweb('Passwd')
        account = NetworkSharingPage(self.driver, self.url)
        account.click_AccountSettings()
        time.sleep(1)
        open_pswd = str(
            account.getAttribute_byId(account.open_pswds, 'checked'))
        if open_pswd != 'true':
            account.click_open_pswd()
            time.sleep(2)
            open_pswd = str(
                account.getAttribute_byId(account.open_pswds, 'checked'))
        self.assertEqual(open_pswd, 'true', msg='启用密码访问 开启失败')
        time.sleep(5)
        # samba登录
        user_name = "anonymous"
        pass_word = ""
        my_name = "anyname"
        domain_name = ""
        remote_smb_IP = host
        #1 无密码登录(应该失败)
        smb = SMBConnection(user_name,
                            pass_word,
                            my_name,
                            domain_name,
                            use_ntlm_v2=True)
        try:
            smb.connect(remote_smb_IP, 139, timeout=3)
        except socket.timeout:
            raise Exception('samba服务无法访问')
        try:
            smb.listShares()
        except NotReadyError:
            print('启用密码访问后 samba无密码无法登录 验证通过')
        else:
            raise Exception('启用密码访问后 samba无密码依旧可以登录')
        smb.close()
        # 2 admin密码登录
        smb = SMBConnection(User,
                            Passwd,
                            my_name,
                            domain_name,
                            use_ntlm_v2=True)
        try:
            smb.connect(remote_smb_IP, 139, timeout=3)
        except socket.timeout:
            raise Exception('samba服务无法访问')
        try:
            smb.listShares()
        except NotReadyError:
            raise Exception('启用密码访问后 samba使用admin登录验证失败')
        smb.close()
        print('启用密码访问后 samba使用admin登录 验证通过')
        # 3 guest账号登录
        smb = SMBConnection('guest',
                            'guest',
                            my_name,
                            domain_name,
                            use_ntlm_v2=True)
        try:
            smb.connect(remote_smb_IP, 139, timeout=3)
        except socket.timeout:
            raise Exception('samba服务无法访问')
        try:
            smb.listShares()
        except NotReadyError:
            raise Exception('启用密码访问后 samba使用guest登录验证失败')
        smb.close()
        print('启用密码访问后 samba使用guest登录 验证通过')
        # 4 新增账号登录
        smb = SMBConnection('1', '1', my_name, domain_name, use_ntlm_v2=True)
        try:
            smb.connect(remote_smb_IP, 139, timeout=3)
        except socket.timeout:
            raise Exception('samba服务无法访问')
        try:
            smb.listShares()
        except NotReadyError:
            raise Exception('启用密码访问后 samba使用新增账号登录验证失败')
        smb.close()
        print('启用密码访问后 samba使用新增登录 验证通过')

        #取消密码访问
        account.click_open_pswd()
        time.sleep(10)
        open_pswd = str(
            account.getAttribute_byId(account.open_pswds, 'checked'))
        self.assertEqual(open_pswd, 'None', msg='启用密码访问 取消失败')
        # samba无密码登录
        smb = SMBConnection(user_name,
                            pass_word,
                            my_name,
                            domain_name,
                            use_ntlm_v2=True)
        try:
            smb.connect(remote_smb_IP, 139, timeout=3)
        except socket.timeout:
            raise Exception('samba服务无法访问')
        try:
            smb.listShares()
        except NotReadyError:
            raise Exception('取消密码访问后 samba无密码无法登录')
        else:
            print('启用密码访问后 samba无密码登录 验证通过')
        smb.close()

        # 删除账号
        account.click_listdel3()
        time.sleep(1)
        account.click_ok()
        time.sleep(1)
        list3_nodata = account.getText_byXpath(account.list3_nodata)
        self.assertEqual(list3_nodata, ' ', msg='第3行账号删除失败')
        print('账号删除')

        self.driver.quit()
        logger.info('test_006_passwdAcessSAMBA passed')
    def test_006_passwdAcessFTP(self):
        u'''启用/取消 密码访问ftp'''
        roleA = getAssertText('roleA')
        host = gettelnet('host')
        User = getweb('User')
        Passwd = getweb('Passwd')
        account = NetworkSharingPage(self.driver, self.url)
        account.click_AccountSettings()
        time.sleep(1)
        open_pswd = str(
            account.getAttribute_byId(account.open_pswds, 'checked'))
        if open_pswd != 'true':
            account.click_open_pswd()
            time.sleep(2)
            open_pswd = str(
                account.getAttribute_byId(account.open_pswds, 'checked'))
        self.assertEqual(open_pswd, 'true', msg='启用密码访问 开启失败')
        # 操作删除 以访已有规则
        account.click_allsel()
        time.sleep(0.2)
        account.click_delete()
        time.sleep(2)
        try:
            self.driver.implicitly_wait(2)
            account.find_ok()
        except NoSuchElementException:
            try:
                account.find_tips_show_inf()
                time.sleep(1)
            except NoSuchElementException:
                pass
        except AttributeError:
            try:
                account.find_tips_show_inf()
                time.sleep(1)
            except NoSuchElementException:
                pass
        else:
            time.sleep(1)
            print('账号列表为空')
        # 新增一个账号
        account.click_add()
        time.sleep(1)
        account.input_username('1')
        account.input_passwd1('1')
        account.input_passwd2('1')
        authority = account.selelement_byName(account.authority)
        Select(authority).select_by_value('1')  # 0 读 1 读写
        account.click_add_modal()

        # self.driver.find_element_by_xpath('//*[@id="modal-add"]/div/div/div[3]/ul/li[1]/button').click()
        time.sleep(3)
        Acc3 = str(account.getText_byXpath(account.Acc3))
        auth3 = str(account.getText_byXpath(account.auth3))
        self.assertEqual(Acc3, '1', msg='新增账号失败')
        self.assertEqual(auth3, roleA, msg='新增账号权限失败')
        time.sleep(5)
        #ftp验证
        # ftp尝试使用无密码登录(应该失败)
        IP = host
        ftp = ftplib.FTP()
        ftp.encoding = 'utf-8'
        try:
            ftp.connect(host=IP, port=21, timeout=5)
        except socket.error or socket.gaierror:
            raise Exception("无法访问FTP服务")
        try:
            ftp.login(user='******')  # 相当于没有验证账号密码
        except ftplib.error_perm:
            print('启用密码访问后 ftp无密码无法登录 验证通过')
        else:
            raise Exception("启用密码访问后 ftp无密码依旧可以登录")
        ftp.quit()
        # ftp尝试使用admin登录
        try:
            ftp.connect(host=IP, port=21, timeout=5)
        except socket.error or socket.gaierror:
            raise Exception("无法访问FTP服务")
        try:
            ftp.login(user=User, passwd=Passwd)  # admin账号密码
        except ftplib.error_perm:
            raise Exception("FTP账号密码验证错误")
        else:
            print("启用密码访问后 ftp使用admin可以登录")
        ftpFile = ftp.nlst('1')  # 获取指定目录下的文件
        print('ftpFile', ftpFile)
        ftp.quit()
        # ftp尝试使用guest登录
        try:
            ftp.connect(host=IP, port=21, timeout=5)
        except socket.error or socket.gaierror:
            raise Exception("无法访问FTP服务")
        try:
            ftp.login(user='******', passwd='guest')  # guest账号密码
        except ftplib.error_perm:
            raise Exception("FTP账号密码验证错误")
        else:
            print("启用密码访问后 ftp使用修改过guest密码的账号可以登录")
        ftpFile = ftp.nlst('1')  # 获取指定目录下的文件
        print('ftpFile', ftpFile)
        ftp.quit()
        # ftp尝试使用新增账号1登录
        try:
            ftp.connect(host=IP, port=21, timeout=5)
        except socket.error or socket.gaierror:
            raise Exception("无法访问FTP服务")
        try:
            ftp.login(user='******', passwd='1')  # 新增账号密码
        except ftplib.error_perm:
            raise Exception("FTP账号密码验证错误")
        else:
            print("启用密码访问后 ftp使用新增账号可以登录")
        ftpFile = ftp.nlst('1')  # 获取指定目录下的文件
        print('ftpFile', ftpFile)
        ftp.quit()

        #取消密码访问
        account = NetworkSharingPage(self.driver, self.url)
        account.click_AccountSettings()
        time.sleep(1)
        account.click_open_pswd()
        time.sleep(10)
        open_pswd = str(
            account.getAttribute_byId(account.open_pswds, 'checked'))
        self.assertEqual(open_pswd, 'None', msg='启用密码访问 取消失败')
        # ftp尝试使用无密码登录
        ftp = ftplib.FTP()
        ftp.encoding = 'utf-8'
        try:
            ftp.connect(host=IP, port=21, timeout=5)
        except socket.error or socket.gaierror:
            raise Exception("无法访问FTP服务")
        try:
            ftp.login(user='******')  # 相当于没有验证账号密码
        except ftplib.error_perm:
            raise Exception("取消密码访问后 ftp无密码无法登录")
        else:
            print('启用密码访问后 ftp无密码无法登录 验证通过')
        ftp.quit()

        # # 删除账号
        # account.click_listedit3()
        # time.sleep(1)
        # account.click_ok()
        # time.sleep(1)
        # list3_nodata = account.getText_byXpath(account.list3_nodata)
        # self.assertEqual(list3_nodata, ' ', msg='第3行账号删除失败')
        # print('账号删除')

        self.driver.quit()
        logger.info('test_005_passwdAcessFTP passed')
    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')
    def test_001_ftpServer(self):
        u'''ftp服务器基本设置,ftp查看'''
        host = gettelnet('host')
        ftpSmaba = NetworkSharingPage(self.driver, self.url)
        # 1、设置ftp基本信息
        ftpSmaba.click_choosml()
        time.sleep(1)
        ftpSmaba.input_names('1')
        ftpSmaba.click_FTP_DIR_1_check()
        ftpSmaba.click_modal_FTP()
        time.sleep(1)
        try:  #以访第一次选中后 第二次点击被取消 从而未选中共享目录
            self.driver.implicitly_wait(1)
            ftpSmaba.find_tips_show_inf()
        except NoSuchElementException:
            pass
        else:
            ftpSmaba.click_FTP_DIR_1_check()
            ftpSmaba.click_modal_FTP()
            time.sleep(3)
        self.driver.implicitly_wait(10)
        ftpEn = ftpSmaba.getAttribute_byName(ftpSmaba.ftpEns, 'checked')
        print(ftpEn)
        if ftpEn != 'true':
            ftpSmaba.click_ftpEn()
            time.sleep(1)
        defaultPort = str(
            ftpSmaba.getAttribute_byName(ftpSmaba.ftpports, 'value'))
        self.assertEqual(defaultPort, '21', msg='ftp默认端口不为21')
        ftpSmaba.click_save()
        time.sleep(1)
        enableDevice = ftpSmaba.getAttribute_byId(ftpSmaba.enableDevices,
                                                  'checktype')
        print(enableDevice)
        if enableDevice != '1':  #1为打开网络共享
            ftpSmaba.click_enableDevice()
            time.sleep(3)
        ftpEn = ftpSmaba.getAttribute_byName(ftpSmaba.ftpEns, 'checked')
        enableDevice = ftpSmaba.getAttribute_byId(ftpSmaba.enableDevices,
                                                  'checktype')
        self.assertEqual(ftpEn, 'true', msg='启用FTP服务器 失败')
        self.assertEqual(enableDevice, '1', msg='网络共享 启用失败')
        time.sleep(10)
        #2、ftp查看目录文件
        IP = host
        Port = 21
        ftp = ftplib.FTP()
        ftp.encoding = 'utf-8'
        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()
        #过滤掉中文和带空格的
        zhmodel = re.compile(u'[\u4e00-\u9fa5]')  # 检查中文
        ftpFile2 = []
        for file in ftpFile:
            if ' ' not in file:
                ftpFile2.append(file[2:])
        for i in ftpFile2:
            if zhmodel.search(i):
                ftpFile2.remove(i)
        # print('ftpFile2:',ftpFile2)
        # 3、telnet后台查看目录文件
        # 连接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'cd /ftpRoot/1 ; ls' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        # print('result:', result)
        tn.close()  # tn.write('exit\n')

        #4、判断对比 ftp查看内容在telnet查看的目录中
        for i in ftpFile2:
            if result.count(i):
                pass
            else:
                raise Exception(' 验证失败')  # 如果没有则报错

        self.driver.quit()
        logger.info('test_001_ftpServer passed')
    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')
    def test_002_ftpPort(self):
        u'''FTP端口'''

        host = gettelnet('host')
        portwarnA = getAssertText('portwarnA')
        ftpSmaba = NetworkSharingPage(self.driver, self.url)

        # defaultPort=str(self.driver.find_element_by_name('ftpport').get_attribute('value'))
        # self.assertEqual(defaultPort,'21',msg='ftp默认端口不为21') #001已验证

        #修改端口为22
        ftpSmaba.input_ftpport('22')
        ftpSmaba.click_save()
        time.sleep(10)
        Port1 = str(ftpSmaba.getAttribute_byName(ftpSmaba.ftpports, 'value'))
        self.assertEqual(Port1, '22', msg='ftp修改端口不为22')
        # ftp验证端口
        IP = host
        ftp = ftplib.FTP()
        ftp.encoding = 'utf-8'
        try:
            ftp.connect(host=IP, port=22, 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()
        # 修改端口为65534
        ftpSmaba.input_ftpport('65534')
        ftpSmaba.click_save()
        time.sleep(10)
        Port1 = str(ftpSmaba.getAttribute_byName(ftpSmaba.ftpports, 'value'))
        self.assertEqual(Port1, '65534', msg='ftp修改端口不为65534')
        # ftp验证端口
        ftp = ftplib.FTP()
        ftp.encoding = 'utf-8'
        try:
            ftp.connect(host=IP, port=65534, 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()
        # 修改端口为1
        ftpSmaba.input_ftpport('1')
        ftpSmaba.click_save()
        time.sleep(10)
        Port1 = str(ftpSmaba.getAttribute_byName(ftpSmaba.ftpports, 'value'))
        self.assertEqual(Port1, '1', msg='ftp修改端口不为1')
        # ftp验证端口
        ftp = ftplib.FTP()
        ftp.encoding = 'utf-8'
        try:
            ftp.connect(host=IP, port=1, 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()

        #验证提示信息
        ftpSmaba.input_ftpport('65536')
        ftpSmaba.click_save()
        time.sleep(1)
        tipsport = str(ftpSmaba.getText_byXpath(ftpSmaba.tipsport))
        if portwarnA not in tipsport:
            CapPic(self.driver)
            logger.info(u'FTP端口范围提示有误')
            raise Exception('FTP端口范围提示有误')

        # 将端口改回21
        ftpSmaba.input_ftpport('21')
        ftpSmaba.click_save()
        time.sleep(2)

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