예제 #1
0
        GetParameters(getpath(parameterF))  #生成新参数文件
        import time
        import HTMLTestRunner
        import unittest
        import sys
        from common.ReadConfig import getweb, getParameter

        from common.GetRouteCPU import getCPUmodel
        from common.swconfig import swconfig
        from common.initTestPC import initTestPC
        from common.GetWanNum import getWanNum
        # from common.ParametersFileU import parametersFile
        from common.SoftwareReplace import softwareReplac
        if testCount > 1:
            ReplaceVersion = 'ReplaceVersion' + str(testCount - 1)
            print('更换到的版本号:', getweb(ReplaceVersion))
            softwareReplac(getweb(ReplaceVersion))  # telnet更换路由器软件

        #1、性能参数
        from test_case import Parameter_010_DefaultInfo  #出厂信息(包含了恢复出厂)
        from test_case import Parameter_011_ManagementStyle
        from test_case import Parameter_012_SysManage
        from test_case import Parameter_013_NetworkPortSet
        from test_case import Parameter_014_DHCPserver
        from test_case import Parameter_015_basicFunction
        from test_case import Parameter_016_natRules
        from test_case import Parameter_017_PolicyRoute
        from test_case import Parameter_018_netSecurity
        from test_case import Parameter_019_actionManagement
        from test_case import Parameter_020_BandwidthManagement
        from test_case import Parameter_021_switchConfig
예제 #2
0
#@swzhou
'''
系统配置-网管策略-系统管理员配置
'''

import time
import unittest

from selenium.webdriver.support.select import Select
from common.LogGen import LogGen
logger = LogGen(Logger='administrator').getlog()
from common.CapPic import CapPic
from common.ReadConfig import getAssertText, getweb
from common.loginRoute import login
from pages.sysConfig_001_ManagementPolicyPage import ManagementPolicyPage
RouteUrl = getweb('RouteUrl')


class administrator(unittest.TestCase):
    def setUp(self):
        print('sysConfig_001_administrator start')

    def test_001_test1(self):
        u'''添加管理员账号'''
        roleA = getAssertText('roleA')
        # 添加管理员账号test/test,读写权限
        login.loginWeb(self)  #admin账号登录
        self.driver.implicitly_wait(10)
        administrator = ManagementPolicyPage(self.driver, self.url)
        #进入系统配置-网管策略-系统管理员
        administrator.click_sysConfig()
예제 #3
0
#! -*-conding:utf-8 -*-
#@Time: 2019/6/14 0014 13:35
#@swzhou
'''
判断设备的wan、lan对应的 交换机端口

'''
import time
import telnetlib
from configparser import NoOptionError

from common.ReadConfig import getweb,gettelnet
host = gettelnet('host')
port = gettelnet('port')
username = bytes(getweb('User'), encoding="utf8")
password = bytes(getweb('Passwd'), encoding="utf8")

mtk7620Llist = ['nv518GV2', 'ER742GV2', 'nv518GP', 'nv521GV3', 'ER745GV2', 'nv840GV3', 'nv810G', 'ER1500G',
                    'nv850G', 'nv1200GWV2', 'ER758GWV2','TL-BWR-21']
mtkOtherlist = ['nv510v5', 'nv510v6.1', 'ER741v2', 'ER741V3', 'ER741v3.1', 'nv510G', 'ER741G', 'nv520V4', 'nv520V5',
                'nv528GP', 'nv810V6', 'nv518GV3', 'ER742GV3', 'nv512Wv4', 'ER741Wv2', 'nv518WV5', 'nv518Wv4', 'ER748W','nv750Wv2',
                'ER742Wv2', 'nv1200W', 'ER758W', 'mv1200WV2','A908V3','nv512Wv4.2', 'nv810Gv2', 'ER1500GV2','nv510GV2','ER741GV2',
                'nvA655W']
QCAlist = ['512Wv5', 'ER741Wv3', '750Wv3', 'mv1200WV2', 'ER758Wv2', 'mv1250GW', 'ER762GW', 'mv1250GWv2']
p1010list = ['QV1210G', 'QV1220G', 'QV2620G', 'er1520G', 'QV3320Gv2', 'QV2610G', 'QV4220G', 'QV4240G', 'er5240G',
             'QV3640G', 'QV4840GV2.0', 'QVU3000', 'QVU4000', 'QVN800', 'QVNE1200V3.0', 'QVN1800V3.0','er5220G',
             'QV2620GS1', 'er1520GS1','QV4240GS1', 'er5240GS1', 'QV4220GS1', 'er5520GS1']
j1800list = ['lv4250G', 'ER5250G', 'lv4330Gv2', 'lv6530Gv5', 'ER5530Gv2']
# 支持license的j1800
j1800list2 = ['lv5830GV5', 'lv6830GV5', 'lvU5000V2', 'lvU6000V2', 'lvNE2200V4', 'lvNE4000V4', 'lvNE6000V5']
D525list = ['lv4330GV1', 'lv6530GV4', 'ER5530G', 'lv5830GV4', 'lv6830GV4', 'lvU5000V3', 'lvU6000V3',
예제 #4
0
from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.common.exceptions import NoSuchElementException
from common.LogGen import LogGen
from common.CapPic import CapPic
from common.pingTest import pingTestIP
from common.ReadConfig import gettelnet, getweb, getAssertText
from common.loginRoute import login
from common.swconfig import swconfig
from common.GetRouteCPU import getCPUmodel
from pages.PortMapping_002_staticMappingPage import staticMappingPage
from pages.Organization_002_userStatuspage import Organization_userStatusPage
from pages.NetConfig_001_WANpage import NetworkConfig_wanpage
logger = LogGen(Logger='PortMapping_002_staticMapping').getlog()
batpath = os.path.dirname(os.path.abspath('.')) + '/script/'
serverPcMac = getweb('serverPcMac')
CPUmodel = getCPUmodel()
ConnectState = getAssertText('ConnectState')


class staticMapping(unittest.TestCase):
    def setUp(self):
        logger.info('setUp start')
        # pass

    def test_001_tcp80(self):
        u'''验证tcp80 映射'''

        # #改用另外设置的server pc
        # # 打开Everthing,Evering充当80server(需事先设置开启相关http服务)
        # handle = win32process.CreateProcess("D:\Program Files\Everything\Everything.exe", '', None,
예제 #5
0
    def test_003_ProtocolSW(self):
        u'''开启、关闭 兼容模式 '''
        netname = netNamePage(self.driver, self.url)
        netname.click_netName()
        time.sleep(1)
        # 兼容模式 默认关闭
        ManageProtocol = netname.getAttribute_byId(netname.ManageProtocolss,'checktype')
        self.assertEqual(ManageProtocol, '0', msg='兼容模式未关闭')  # 0关闭,1打开
        # 打开兼容模式
        netname.click_ManageProtocols()
        time.sleep(5)
        ManageProtocol = netname.getAttribute_byId(netname.ManageProtocolss, 'checktype')
        self.assertEqual(ManageProtocol, '1', msg='兼容模式未打开')  # 0关闭,1打开
        # 确认打开后有acd进程
        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)
        tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        # 输入登录用户名
        tn.read_until(b'login:'******'Password:'******'#')
        tn.write(b'ps | grep -v grep |grep acd' + b'\n')  # SSID加密密码
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 判断
        if "/sbin/acd_guard.sh " in result:
            print('acd进程存在')
        else:
            raise Exception('打开兼容模式后 acd进程未存在')  # 如果没有则报错
        tn.close()  # tn.write('exit\n')

        #关闭兼容模式
        netname.click_ManageProtocols()
        time.sleep(2)
        ManageProtocol = netname.getAttribute_byId(netname.ManageProtocolss, 'checktype')
        self.assertEqual(ManageProtocol, '0', msg='兼容模式未关闭')  # 0关闭,1打开
        # 确认关闭后没有acd进程
        tn = telnetlib.Telnet(host=hostip, port=port)
        tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        # 输入登录用户名
        tn.read_until(b'login:'******'Password:'******'#')
        tn.write(b'ps | grep -v grep |grep acd' + b'\n')  # SSID加密密码
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 判断
        if "/sbin/acd_guard.sh " not in result:
            print('acd进程不存在')
        else:
            raise Exception('关闭兼容模式后 acd进程依旧存在')  # 如果没有则报错
        tn.close()  # tn.write('exit\n')

        # 再打开兼容模式
        netname.click_ManageProtocols()
        time.sleep(2)
        ManageProtocol = netname.getAttribute_byId(netname.ManageProtocolss, 'checktype')
        self.assertEqual(ManageProtocol, '1', msg='兼容模式未打开')  # 0关闭,1打开

        self.driver.quit()
        logger.info('test_003_ProtocolSW passed')
예제 #6
0
    def test_003_3PPPoE(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()  # 修改接口后 可能会回到登录页面 所以关闭,再打开

        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)
            print(str(list_connectState1), str(list_connectState2),
                  str(list_connectState3))
            list_connectState = [
                str(list_connectState1),
                str(list_connectState2),
                str(list_connectState3)
            ]
            # 动态接入 未获取到地址/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))
        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)
        route_result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('route_result:', route_result)
        # 获取WAN1对应接口名称
        route_result1 = route_result[2:-7]
        print('route_result1', route_result1)
        route_result2 = route_result1.split(r'\r\n')
        print('route_result2', route_result2)

        for x in range(len(route_result2)):
            if line1_ip in route_result2[x]:
                result2_num1 = (route_result2[x])
                print(result2_num1)
                line1_Interface_name = result2_num1.split()[2]
                print(line1_Interface_name)
            if line2_ip in route_result2[x]:
                result2_num1 = (route_result2[x])
                print(result2_num1)
                line2_Interface_name = result2_num1.split()[2]
                print(line2_Interface_name)
            if line3_ip in route_result2[x]:
                result2_num1 = (route_result2[x])
                print(result2_num1)
                line3_Interface_name = result2_num1.split()[2]
                print(line3_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口对应接口名称失败')

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

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

        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.click_save()
        time.sleep(2)
        # 等待弹窗提示成功
        i = 0
        while i < 80:
            try:
                self.driver.implicitly_wait(1)
                wan_config.find_tipsshowin()
            except NoSuchElementException:
                time.sleep(1)
                i = i + 1
                print(i)
            else:
                tips = str(
                    wan_config.getAttribute_byClass(wan_config.tipsshowin,
                                                    'tip-sign'))
                print(tips, i)
                if tips != 'success':
                    CapPic(self.driver)
                    logger.info(u'线路检测保存 异常')
                    raise Exception(u'线路检测保存 异常')
                break
        else:
            raise Exception(u'线路检测保存 未弹出提示框')
        # 切换标签页判断配置正确
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_GlobalConfig()
        time.sleep(1)
        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'))
        self.assertEqual(KeepLive1, '0', msg='wan1检测间隔不为0')
        self.assertEqual(KeepLive2, '0', msg='wan2检测间隔不为0')
        self.assertEqual(KeepLive3, '0', msg='wan3检测间隔不为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_3PPPoE passed')
예제 #7
0
'''
import subprocess
import time
import unittest
import os.path
import socket
from common.LogGen import LogGen
from common.CapPic import CapPic
from common.pingTest import pingTestIP
from common.ReadConfig import getAssertText, getweb
from common.loginRoute import login
from common.organization_edit import organization_group
from pages.Organization_001_Memberspage import OrganizationMembersPage
logger = LogGen(Logger='Members_003_binding').getlog()
batpath = os.path.dirname(os.path.abspath('.')) + '/script/'
PcMac = getweb('PcMac')
savesucess = getAssertText('savesucess')


class onlyBinding(unittest.TestCase):
    def setUp(self):
        logger.info('setUp start')
        # pass

    def test_001_IPMACBinding(self):
        u'''仅IP/MAC绑定用户 上网'''
        organization_group.import_empty_template(self)  # 判断是否有组织架构,有则清空

        # 获取本机ip 默认有线地址,有线断开会显示无线
        pcaddr = socket.gethostbyname(socket.getfqdn(socket.gethostname()))
예제 #8
0
import socket
import time
import unittest
import subprocess
from common.LogGen import LogGen
from selenium.common.exceptions import NoSuchElementException
from common.CapPic import CapPic
from common.pingTest import pingTestIP
from common.ReadConfig import getAssertText, getweb, gettelnet
from common.loginRoute import login
from pages.VPNconfig_IPsecPage import IPsecPage
from pages.NetConfig_001_WANpage import NetworkConfig_wanpage
from common.organization_edit import organization_group

logger = LogGen(Logger='VPNconfig_001_ipsec').getlog()
vpnRouteWan = getweb('vpnRouteWan')
vpnRouteUrl = 'http://' + vpnRouteWan + ':8081'
batpath = os.path.dirname(os.path.abspath('.')) + '/script/'
ConnectState = getAssertText('ConnectState')


class ipsec(unittest.TestCase):
    def setUp(self):
        logger.info('setUp start')
        # pass

    def test_001_ipsec(self):
        u'''ipsec VPN'''
        vpnRouteLan = getweb('vpnRouteLan')
        host = gettelnet('host')
        StateVPN1 = getAssertText('StateVPN1')
예제 #9
0
def softwareReplac(version=getweb('ReplaceVersion1')):
    # ReplaceVersion1 = getweb('ReplaceVersion1')
    hostip = gettelnet('host')
    port = gettelnet('port')
    licenseSN = getweb('licenseSN')
    username = bytes(getweb('User'), encoding="utf8")
    password = bytes(getweb('Passwd'), encoding="utf8")
    pcaddr = socket.gethostbyname(socket.getfqdn(socket.gethostname()))
    CPUmodel = getCPUmodel()
    license = IFlicense(version)
    # print(license)

    # 打开tftp32.exe,
    # 注意:tftp32打开后的目录是由 由哪个脚本执行 所在的路径决定
    # 直接运行该脚本,则tftp32的目录是‘test_003_udp69’所在的‘D:\python\SEWEB\3.1.1Router\test_case\Port_mapping’
    # 由all_test.py或者ProductModel_test.py调用执行,则目录为‘D:\python\SEWEB\3.1.1Router\run’
    # 因此 需把握好 对应目录中包含上传的文件,此脚本设定上传的文件为'tftpd32.exe'
    handle = win32process.CreateProcess(
        r"D:\python\SEWEB\3.1.1Router\test_case\tftpd32.exe", '', None,
        None, 0, win32process.CREATE_NO_WINDOW, None, None,
        win32process.STARTUPINFO())  # 打开tftp32.exe,获得其句柄
    time.sleep(2)
    if CPUmodel == 'X86':
        if '.img' not in version:
            raise Exception(u'X86设备需要 img文件')
    elif '.bin' not in version:
        version = version + '.bin'
    VersionCmd = bytes(('tftp -gr ' + version + ' ' + pcaddr + ' 69'),
                       encoding='utf8')

    tn = telnetlib.Telnet(host=hostip, port=port, timeout=10)
    tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
    tn.read_until(b'login:'******'Password:'******'#')
    tn.write(VersionCmd + b'\n')
    tn.read_until(b'#')
    if CPUmodel == 'MTK' or CPUmodel == 'Qualcomm':
        mtdwriteCmd = bytes(('mtd_write write ' + version + ' Kernel'),
                            encoding='utf8')
        tn.write(mtdwriteCmd + b'\n')
        tn.read_until(b'#')
    elif CPUmodel == 'P1010':
        mtdCmd = bytes(('tftp -gr mtd_write_p1010 ' + pcaddr + ' 69'),
                       encoding='utf8')
        tn.write(mtdCmd + b'\n')
        tn.write(b'chmod 777 mtd_write_p1010' + b'\n')
        tn.read_until(b'#')
        mtdwriteCmd = bytes(('./mtd_write_p1010 write ' + version + ' Kernel'),
                            encoding='utf8')
        tn.write(mtdwriteCmd + b'\n')
        tn.read_until(b'#')
    elif CPUmodel == 'X86':
        writeCmd = bytes(('dd if=' + version + ' of=/dev/sda'),
                         encoding='utf8')
        tn.write(writeCmd + b'\n')
        tn.read_until(b'#')
    tn.write(b'ls' + b'\n')
    tn.read_until(b'#')
    #如果支持license 重置license分区且修改序列号为 licenseSN
    if license == '1':
        mtdwriteCmd = bytes(('tftp -gr license ' + pcaddr + ' 69'),
                            encoding='utf8')
        tn.write(mtdwriteCmd + b'\n')
        tn.read_until(b'#')
        tn.write(b'dd if=license of=/dev/sda3' + b'\n')
        tn.read_until(b'#')
        mtdwriteCmd = bytes(('tftp -gr uttsn_x86_new ' + pcaddr + ' 69'),
                            encoding='utf8')
        tn.write(mtdwriteCmd + b'\n')
        tn.read_until(b'#')
        tn.write(b'chmod 777 uttsn_x86_new' + b'\n')
        tn.read_until(b'#')
        mtdwriteCmd = bytes(('./uttsn_x86_new ' + licenseSN), encoding='utf8')
        tn.write(mtdwriteCmd + b'\n')
        tn.read_until(b'#')
    tn.write(b'reboot' + b'\n')
    time.sleep(40)

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

    i = 0
    while i < 30:
        p = pingTestIP()
        if p == 'N':
            time.sleep(1)
            print(i)
            i += 1
        else:
            time.sleep(10)  # 多等待10s
            break

    else:
        logger.info(u'telnet更换软件后无法ping通 设备')
        raise Exception(u'telnet更换软件后无法ping通 设备')
예제 #10
0
    def test_001_easyIP(self):
        u'''验证 easyIP,后台telnet验证iptables规则'''
        #新增
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        natRule = natRulePage(self.driver, self.url)
        # 配置映射
        natRule.click_NetworkConfig()
        time.sleep(0.5)
        natRule.click_portMapping()
        time.sleep(1)
        natRule.click_natRule()
        time.sleep(1)
        natRule.click_add()
        time.sleep(1)
        natRule.input_RuleIDs('easyIPtest')
        natRule.input_InFromIPs(host2 + '200')
        natRule.input_InEndIPs(host2 + '202')
        natRule.input_OutIPs('192.169.122.250')
        time.sleep(1)
        natRule.click_save()
        time.sleep(1)
        #断言
        InFromIPs = str(natRule.getText_byXpath(natRule.list_InFromIPs))
        self.assertEqual(InFromIPs, host2 + '200', msg='内网起始IP地址 与设置的不一致')
        InEndIPs = str(natRule.getText_byXpath(natRule.list_InEndIPs))
        self.assertEqual(InEndIPs, host2 + '202', msg='内网结束IP地址 与设置的不一致')
        OutIPs = str(natRule.getText_byXpath(natRule.list_OutIPs))
        self.assertEqual(OutIPs, '192.169.122.250', msg='外网起始IP地址 与设置的不一致')
        print('easyIP规则 已添加')

        # 连接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'iptables -t nat  -L wan1_nat_rule_loop' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        #后台实际应有的结果
        result1='SNAT       all  --  anywhere             anywhere            source IP range %s200-%s202 to:192.169.122.250' \
                % (host2,host2)
        # 判断
        if result1 in result:
            print('easyIP规则 验证成功')
        else:
            raise Exception('easyIP规则 验证失败')  # 如果没有则报错
        tn.close()  # tn.write('exit\n')

        self.driver.quit()
        logger.info('test_001_easyIP passed')
예제 #11
0
    def test_syslog(self):
        u'''日志服务器'''
        pcNetworkID = getweb('pcNetworkID')
        wiresharkpath = getpath('wiresharkpath')
        host = gettelnet('host')

        #0、清理tmp下的syslog.pcapng\log文件
        call_Firefox.del_syslog_log(self)
        #1、开启syslog server
        pcaddr = socket.gethostbyname(socket.getfqdn(socket.gethostname()))
        login.loginWeb(self)
        self.driver.implicitly_wait(10)
        syslog = syslogPage(self.driver, self.url)
        syslog.click_sysConfig()
        time.sleep(0.5)
        syslog.click_Syslog()
        time.sleep(1)
        syslog.click_SyslogServer()
        time.sleep(1)
        syslog.click_syslogEn()
        syslog.input_ServerIp(pcaddr)
        syslog.input_ServerPort('514')
        syslog.click_save()
        time.sleep(1)
        syslogEs = syslog.getAttribute_byXpath(syslog.syslogEs, 'checked')
        self.assertEqual(syslogEs, 'true', msg='syslog服务器启用失败')

        #2、wan口改为dhcp 使生成syslog
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        wan_config.click_NetworkConfig()
        time.sleep(0.5)
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_line1edit()
        time.sleep(1)
        access_mode = wan_config.selelement_byName(wan_config.connectionType)
        Select(access_mode).select_by_value('DHCP')
        wan_config.click_save()
        time.sleep(0.5)

        # 3、调用wireshark 开启抓包,必须要抓到包之后才会进行下一步,因此放在设置vpn之后,通过抓下一次的log
        packetfile = tmppath + 'syslogtest.pcapng'
        dir = wiresharkpath[0:2]
        getpacket = ('tshark -i%s -f "udp port 514" -w %s -c 2' %
                     (pcNetworkID, packetfile))
        os.system('%s && cd %s && %s' % (dir, wiresharkpath, getpacket))

        #4、读取抓包显示 并存为log文件
        logfile = tmppath + 'syslogtest.log'
        savepacket = (
            'tshark -r %s -T fields -e "ip.src" -e ip.dst -Y "syslog" > %s ' %
            (packetfile, logfile))
        os.system('%s && cd %s && %s' % (dir, wiresharkpath, savepacket))

        #5、读取判断syslog生效
        with open(logfile, 'r') as file_to_read:
            while True:
                lines = file_to_read.readline()  # 整行读取数据
                print(lines)
                if not lines:
                    break
                if host + pcaddr in lines:
                    print(u'验证通过')

        self.driver.quit()
        logger.info('test_reboot1 passed')
예제 #12
0
    def test_004_L2tpclient(self):
        u'''L2tpclient'''

        vpnRouteLan = getweb('vpnRouteLan')
        host = gettelnet('host')
        StateVPN2 = getAssertText('StateVPN2')
        login.loginWeb(self)
        self.driver.implicitly_wait(10)
        pptpl2tp = pptpL2tpPage(self.driver, self.url)
        pptpl2tp.click_VPNConfig()
        time.sleep(0.5)
        pptpl2tp.click_pptpL2tp()
        time.sleep(1)
        # 操作删除 以访已有规则
        pptpl2tp.click_selall()
        time.sleep(0.2)
        pptpl2tp.click_delall()
        time.sleep(2)
        try:
            self.driver.implicitly_wait(2)
            pptpl2tp.find_ok()
        except NoSuchElementException:
            try:
                pptpl2tp.find_tipsshowin()
                time.sleep(1)
            except NoSuchElementException:
                pass
        else:
            time.sleep(1)
            print('VPN隧道列表为空')

        pptpl2tp.click_add()
        time.sleep(2)
        pptpl2tp.click_workMode2()
        pptpl2tp.click_workModel2tp()
        pptpl2tp.input_TunNames('testC')
        pptpl2tp.input_TunNamesIP(vpnRouteWan)
        pptpl2tp.input_userNames('test')
        pptpl2tp.input_password('test')
        pptpl2tp.input_remoteInIp(vpnRouteLan)
        pptpl2tp.input_remoteInIPMask('255.255.255.0')
        pptpl2tp.click_save()
        time.sleep(2)
        self.driver.quit()

        # 另外一台路由器 配置pptp Server
        login.test_enableLoginWeb(self, url=vpnRouteUrl)
        pptpl2tp = pptpL2tpPage(self.driver, self.url)
        pptpl2tp.click_VPNConfig()
        time.sleep(0.5)
        pptpl2tp.click_pptpL2tp()
        time.sleep(1)
        # 操作删除 以访已有规则
        pptpl2tp.click_selall()
        time.sleep(0.2)
        pptpl2tp.click_delall()
        time.sleep(2)
        try:
            self.driver.implicitly_wait(2)
            pptpl2tp.find_ok()
        except NoSuchElementException:
            try:
                pptpl2tp.find_tipsshowin()
                time.sleep(1)
            except NoSuchElementException:
                pass
        else:
            time.sleep(1)
            print('VPN隧道列表为空')

        pptpl2tp.click_l2tpGlobalSet()  #语言问题待修改成xpath
        time.sleep(0.5)
        pptpl2tp.click_L2tpserverEn()
        pptpl2tp.input_priDns('114.114.114.114')
        pptpl2tp.click_save()
        time.sleep(1)
        pptpl2tp.click_l2tpGlobalSet()
        time.sleep(0.5)
        l2tpSs = pptpl2tp.getAttribute_byXpath(pptpl2tp.L2tpserverEs,
                                               'checked')
        if l2tpSs == 'true':
            logger.info(u'L2tpserver已开启')
        else:
            CapPic(self.driver)
            logger.info(u'L2tpserver未开启')
            return Exception(u'L2tpserver未开启')

        pptpl2tp.click_Tunnellist()
        time.sleep(0.5)
        pptpl2tp.click_add()
        time.sleep(1)
        pptpl2tp.click_workMode1()
        pptpl2tp.click_workModel2tp()
        pptpl2tp.input_TunNames('testC')
        seluserType = pptpl2tp.selelement_byName(pptpl2tp.seluserType)
        Select(seluserType).select_by_value('lantolan')
        pptpl2tp.input_userNames('test')
        pptpl2tp.input_password('test')
        pptpl2tp.input_remoteInIp(host)
        pptpl2tp.input_remoteInIPMask('255.255.255.0')
        pptpl2tp.click_saveS()
        time.sleep(2)

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

        logger.info('test_004_L2tpclient passed')
예제 #13
0
    def test_001_PPTPserver(self):
        u'''PPTPserver'''

        vpnRouteLan = getweb('vpnRouteLan')
        host = gettelnet('host')
        StateVPN2 = getAssertText('StateVPN2')
        login.loginWeb(self)
        self.driver.implicitly_wait(10)
        pptpl2tp = pptpL2tpPage(self.driver, self.url)
        pptpl2tp.click_VPNConfig()
        time.sleep(0.5)
        pptpl2tp.click_pptpL2tp()
        time.sleep(1)
        # 操作删除 以访已有规则
        pptpl2tp.click_selall()
        time.sleep(0.2)
        pptpl2tp.click_delall()
        time.sleep(2)
        try:
            self.driver.implicitly_wait(2)
            pptpl2tp.find_ok()
        except NoSuchElementException:
            try:
                pptpl2tp.find_tipsshowin()
                time.sleep(1)
            except NoSuchElementException:
                pass
        else:
            time.sleep(1)
            print('VPN隧道列表为空')

        pptpl2tp.click_PPTPGlobalSet()
        time.sleep(0.5)
        pptpl2tp.click_pptpserverEn()
        pptpl2tp.input_priDns('114.114.114.114')
        pptpl2tp.click_save()
        time.sleep(1)
        pptpSs = pptpl2tp.getAttribute_byXpath(pptpl2tp.pptpserverEs,
                                               'checked')
        if pptpSs == 'true':
            logger.info(u'pptpserver已开启')
        else:
            CapPic(self.driver)
            logger.info(u'pptpserver未开启')
            return Exception(u'pptpserver未开启')

        pptpl2tp.click_add()
        time.sleep(1)
        pptpl2tp.click_workMode1()
        pptpl2tp.click_workModepptp()
        pptpl2tp.input_TunNames('testS')
        seluserType = pptpl2tp.selelement_byName(pptpl2tp.seluserType)
        Select(seluserType).select_by_value('lantolan')
        pptpl2tp.input_userNames('test')
        pptpl2tp.input_password('test')
        pptpl2tp.input_remoteInIp(vpnRouteLan)
        pptpl2tp.input_remoteInIPMask('255.255.255.0')
        pptpl2tp.click_saveS()
        time.sleep(2)

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

        # 另外一台路由器 配置pptp Client
        login.test_enableLoginWeb(self, url=vpnRouteUrl)
        pptpl2tp = pptpL2tpPage(self.driver, self.url)
        pptpl2tp.click_VPNConfig()
        time.sleep(0.5)
        pptpl2tp.click_pptpL2tp()
        time.sleep(1)
        # 操作删除 以访已有规则
        pptpl2tp.click_selall()
        time.sleep(0.2)
        pptpl2tp.click_delall()
        time.sleep(2)
        try:
            self.driver.implicitly_wait(2)
            pptpl2tp.find_ok()
        except NoSuchElementException:
            try:
                pptpl2tp.find_tipsshowin()
                time.sleep(1)
            except NoSuchElementException:
                pass
        else:
            time.sleep(1)
            print('VPN隧道列表为空')

        pptpl2tp.click_add()
        time.sleep(2)
        pptpl2tp.click_workMode2()
        pptpl2tp.click_workModepptp()
        pptpl2tp.input_TunNames('testS')
        pptpl2tp.input_TunNamesIP(WAN1_ip)
        pptpl2tp.input_userNames('test')
        pptpl2tp.input_password('test')
        pptpl2tp.input_remoteInIp(host)
        pptpl2tp.input_remoteInIPMask('255.255.255.0')
        pptpl2tp.click_save()
        time.sleep(2)

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

        logger.info('test_001_PPTPserver passed')
예제 #14
0
    def test_oldSoftware1(self, oldversion1=getweb('oldversion1')):
        u'''软件升级 - 更新旧版本测试'''
        # oldversion1 = getweb('oldversion1')
        self.oldversion1 = oldversion1
        UploadingTips = getAssertText('UploadingTips')
        WillReboottips = getAssertText('WillReboottips')

        num = 0
        Expect_Version = ''
        oldversioa1 = oldversion1.split(r'-')
        if len(oldversioa1) == 2:  # eg:'nv640Ev1.5.0-130918'
            Expect_Version = oldversioa1[0] + '-' + oldversioa1[1]
        else:  #eg:'nvA655Wv3.0.0-200116-142208' ; 'TL-BWR-21v3.2.1-200304-171146'
            while num < len(oldversioa1) - 1:
                Expect_Version += oldversioa1[num] + '-'
                num += 1
            else:
                Expect_Version = Expect_Version[:-1]
        # print(Expect_Version)

        # if '.bin' in oldversioa1[1]:
        #     oldversioa2 = oldversioa1[0] + '-' + oldversioa1[1]
        #     Expect_Version = oldversioa2[:-4]
        # else:
        #     Expect_Version = oldversioa1[0] + '-' + oldversioa1[1]

        # 版本上传
        oldSoftware = (str(tmppath) + str(oldversion1) + '.bin')

        self.driver.implicitly_wait(10)
        software = MaintenancePage(self.driver, self.url)
        # 选择文件上传
        self.driver.find_element_by_name('updatesoftware').send_keys(
            oldSoftware)
        # software.input_updatesoftware(oldSoftware)
        time.sleep(1)
        software.click_update()
        time.sleep(1)
        software.click_ok()
        time.sleep(3)
        # 小设备 上传时间较长,判断sleep时间
        tips = str(software.getText_byClass(software.u_tim_str))
        if UploadingTips in tips:
            time.sleep(50)
        elif tips == WillReboottips:
            time.sleep(3)
        # 设备重启时间不一致,做个判断
        time.sleep(30)
        i = 0
        while i < 20:
            now_url = str(self.driver.current_url)
            print(now_url, i)
            if '/noAuth/login.html' not in now_url:  # 如果不同
                time.sleep(5)
            else:
                break
            i += 1
        self.driver.quit()

        #判断是否升级成功
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        software = MaintenancePage(self.driver, self.url)
        # 进入系统配置-系统维护-系统升级
        software.click_sysConfig()
        time.sleep(0.5)
        software.click_Maintenance()
        time.sleep(1)
        now_Version = str(software.getText_byXpath(software.version))
        if Expect_Version != now_Version:
            CapPic(self.driver)
            logger.info(u"升级旧版本 升级后版本号与升级版本号不一致")
            raise Exception('升级旧版本 升级后版本号与升级版本号不一致')
        else:
            print('更新 旧型号版本 验证通过')
        self.driver.quit()
예제 #15
0
 def Firefox_login_web(self):
     u'''配置备份'''
     # 配置备份(因为chrome配置导出提示'损害计算机'问题,这里使用Firefox导出配置文件)
     # Firedownpath = r'%s' %getpath('Firedownpath')
     # Firefoxpath = getpath('tempfilepath')
     self.url = getweb('RouteUrl')
     self.user = getweb('User')
     self.passwd = getweb('Passwd')
     #设置Firefox的Profile
     profile = webdriver.FirefoxProfile()
     #指定下载路径
     profile.set_preference('browser.download.dir',
                            r'D:\python\SEWEB\3.1.1Router\tmp')
     #设置成 2 表示使用自定义下载路径;设置成 0 表示下载到桌面;设置成 1 表示下载到默认路径
     profile.set_preference('browser.download.folderList', 2)
     #在开始下载时是否显示下载管理器
     profile.set_preference('browser.download.manager.showWhenStarting',
                            False)
     #对所给出文件类型不再弹出框进行询问
     profile.set_preference('browser.helperApps.neverAsk.saveToDisk',
                            'application/octet-stream')
     #登录web
     #引用设置的Profile
     self.driver = webdriver.Firefox(firefox_profile=profile)
     # self.driver.maximize_window()
     self.driver.implicitly_wait(10)
     self.driver.get(self.url)
     time.sleep(1)
     now_url = self.driver.current_url
     if 'https://' in str(now_url):
         time.sleep(3)
     login_page = LoginPage(self.driver, self.url)
     login_page.input_username(self.user)
     login_page.input_password(self.passwd)
     login_page.click_login()
     time.sleep(3)
     try:
         self.driver.implicitly_wait(1)
         login_page.find_passwd1()
     except NoSuchElementException:
         pass
     else:
         login_page.input_passwd1(self.passwd)
         login_page.input_passwd2(self.passwd)
         login_page.click_cfm()
         # 加个判断 某些型号等待时间长(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
         login_page.input_username(self.user)
         login_page.input_password(self.passwd)
         login_page.click_login()
         time.sleep(3)
     self.driver.implicitly_wait(10)
     #断言url变更
     url = self.driver.current_url
     try:
         self.assertIn('/index.html', url, msg='未登陆成功')
     except AssertionError:
         CapPic(self.driver)
         logger.info(u"未登录成功")
         raise Exception('未登陆成功')
     print('Firefox_login_web success')
예제 #16
0
suite.addTest(Parameter_100_Parameter.Parameter('test_010_VPNnum'))
suite.addTest(Parameter_100_Parameter.Parameter('test_011_userNum'))
suite.addTest(Parameter_100_Parameter.Parameter('test_012_IPMACbinding'))
suite.addTest(Parameter_100_Parameter.Parameter('test_013_PPPoE'))
suite.addTest(Parameter_100_Parameter.Parameter('test_014_blacklist'))
suite.addTest(Parameter_100_Parameter.Parameter('test_015_maxAp'))
suite.addTest(Parameter_100_Parameter.Parameter('test_016_loadBalance'))
suite.addTest(Parameter_100_Parameter.Parameter('test_017_ssidNum'))


# 最后加个注释 以访报告中没有包含最后一项记录


if __name__=='__main__':
    now = time.strftime("%Y-%m-%d %H_%M_%S")
    SoftVersion1 = getweb('SoftVersion1')

    path_png = os.path.dirname(os.path.abspath('.')) + '/picture/'
    sys.path.append(r'%s' % path_png)
    files_gz = os.listdir(r'%s' % path_png)
    for filename_gz in files_gz:
        portion_gz = os.path.splitext(filename_gz)
        if SoftVersion1 in portion_gz[0]:
            if portion_gz[1] == '.png':
                filenamedir_gz = (r'%s' % path_png) + filename_gz
                os.remove(filenamedir_gz)

    filename = os.path.dirname(
        os.path.abspath('.')) + '/report/report_' + SoftVersion1 + '版本' + now + '性能参数核对测试_result.html'

    fp = open(filename, 'wb')
예제 #17
0
import os
import time
import unittest
import telnetlib
from selenium.webdriver.support.select import Select
from selenium.common.exceptions import NoSuchElementException
from common.LogGen import LogGen
from common.CapPic import CapPic
from common.ReadConfig import gettelnet,getweb,getAssertText,getpath
from common.loginRoute import login
from pages.PortMapping_003_natRulePage import natRulePage
from pages.Organization_002_userStatuspage import Organization_userStatusPage
from pages.NetConfig_001_WANpage import NetworkConfig_wanpage
logger = LogGen(Logger = 'PortMapping_003_natRule').getlog()
tmppath = os.path.dirname(os.path.abspath('.')) + '/tmp/'
serverPcMac = getweb('serverPcMac')
pcNetworkID = getweb('pcNetworkID')
wiresharkpath = getpath('wiresharkpath')
ConnectState = getAssertText('ConnectState')

class natRule(unittest.TestCase):

    def setUp(self):
        logger.info('setUp start')
        # pass

    def test_001_easyIP(self):
        u'''验证 easyIP,后台telnet验证iptables规则'''

        # 通过用户状态获取httpserver的IP地址
        login.loginWeb(self)  # admin账号登录
예제 #18
0
    def test_001_ipsec(self):
        u'''ipsec VPN'''
        vpnRouteLan = getweb('vpnRouteLan')
        host = gettelnet('host')
        StateVPN1 = getAssertText('StateVPN1')
        WillReboottips = getAssertText('WillReboottips')

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

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

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

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

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

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

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

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

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

        self.driver.quit()
        logger.info('test_001_ipsec passed')
예제 #19
0
    def test_002_one2one(self):
        u'''验证 one2one,后台telnet验证iptables规则'''
        nodata = getAssertText('nodata')
        #修改上一条规则
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        natRule = natRulePage(self.driver, self.url)
        # 配置映射
        natRule.click_NetworkConfig()
        time.sleep(0.5)
        natRule.click_portMapping()
        time.sleep(1)
        natRule.click_natRule()
        time.sleep(1)
        natRule.click_edit()
        time.sleep(1)
        natRule.input_RuleIDs('one2onetest')
        natRule.click_typeOne2one()
        natRule.input_InFromIPs('192.168.1.200')
        natRule.input_InEndIPs('192.168.1.201')
        natRule.input_OutIPs('192.169.122.250')
        time.sleep(1)
        natRule.click_save()
        time.sleep(1)
        #断言
        InFromIPs = str(natRule.getText_byXpath(natRule.list_InFromIPs))
        self.assertEqual(InFromIPs, '192.168.1.200', msg='内网起始IP地址 与设置的不一致')
        InEndIPs = str(natRule.getText_byXpath(natRule.list_InEndIPs))
        self.assertEqual(InEndIPs, '192.168.1.201', msg='内网结束IP地址 与设置的不一致')
        OutIPs = str(natRule.getText_byXpath(natRule.list_OutIPs))
        self.assertEqual(OutIPs, '192.169.122.250', msg='外网起始IP地址 与设置的不一致')
        print('easyIP规则 已添加')

        # 连接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)
        tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
        # 输入登录用户名
        tn.read_until(b'login:'******'Password:'******'#')
        tn.write(b'iptables -t nat  -L wan1_nat_rule_loop' + b'\n')
        # 输出结果,判断
        time.sleep(1)
        result = str(tn.read_very_eager())  # 只会存最后一条命令执行结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('result:', result)
        # 后台实际应有的结果
        result1 = 'SNAT       all  --  anywhere             192.168.1.200       UTTDEV match --is-lan-in to:192.168.1.1'
        result2 = 'SNAT       all  --  192.168.1.200        anywhere            to:192.169.122.250'
        result3 = 'SNAT       all  --  anywhere             192.168.1.201       UTTDEV match --is-lan-in to:192.168.1.1'
        result4 = 'SNAT       all  --  192.168.1.201        anywhere            to:192.169.122.251'
        result_list=[result1,result2,result3,result4]
        # 判断
        if all(t in result for t in result_list):
            print('one2one规则 验证成功')
        else:
            raise Exception('one2one规则 验证失败')  # 如果没有则报错
        tn.close()  # tn.write('exit\n')

        #删除NAT规则
        natRule.click_delete()
        time.sleep(1)
        natRule.click_ok()
        time.sleep(1)
        listtips=str(natRule.getText_byXpath(natRule.listtips))
        self.assertEqual(listtips,nodata,msg='删除规则有误')

        self.driver.quit()
        logger.info('test_002_one2one passed')
예제 #20
0
    def test_002_staticSW(self):
        u'''三条线路固定接入线路切换'''
        wan_config = NetworkConfig_wanpage(self.driver, self.url)
        # 1、获取wan1、wan2 网关及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))
        # 处理wan口的mac地址
        # 字母变大写
        line1_mac1 = line1_mac.upper()
        line2_mac1 = line2_mac.upper()
        line3_mac1 = line3_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:]
        print(line1_mac2, line2_mac2, line3_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.click_save()
        time.sleep(2)
        # 等待弹窗提示成功
        i = 0
        while i < 80:
            try:
                self.driver.implicitly_wait(1)
                wan_config.find_tipsshowin()
            except NoSuchElementException:
                time.sleep(1)
                i = i + 1
                print(i)
            else:
                tips = str(
                    wan_config.getAttribute_byClass(wan_config.tipsshowin,
                                                    'tip-sign'))
                print(tips, i)
                if tips != 'success':
                    CapPic(self.driver)
                    logger.info(u'线路检测保存 异常')
                    raise Exception(u'线路检测保存 异常')
                break
        else:
            raise Exception(u'线路检测保存 未弹出提示框')
        # 切换标签页判断配置正确
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_GlobalConfig()
        time.sleep(1)
        KeepLive3 = str(
            wan_config.getAttribute_byName(wan_config.KeepLive3v, 'value'))
        RetryTimes3 = str(
            wan_config.getAttribute_byName(wan_config.RetryTimes3v, 'value'))
        DestIP3 = str(
            wan_config.getAttribute_byName(wan_config.DestIP3v, 'value'))
        self.assertEqual(KeepLive3, '3', msg='wan3检测间隔与设置不一致')
        self.assertEqual(RetryTimes3, '3', msg='wan3检测次数与设置不一致')
        self.assertEqual(DestIP3, '1.2.3.5', msg='wan3检测地址与设置不一致')

        # 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 line1_Interface_name == None:
            raise Exception('获取wan1口对应接口名称失败')
        if line2_Interface_name == None:
            raise Exception('获取wan2口对应接口名称失败')
        if line3_Interface_name == None:
            raise Exception('获取wan3口对应接口名称失败')

        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('route_result:', result)
            result4 = result[1:]
            # print('route_result4', result4)
            result5 = result4.replace('\r\n', ' ')
            # print('route_result5', result5)
            # wan2、wan3检测不通,这里只判断wan1的
            if 'default' in result5 and wan1route1 in result5:
                print('wan1路由在')
                break
                tn.close()
            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.click_save()
        time.sleep(2)
        # 等待弹窗提示成功
        i = 0
        while i < 80:
            try:
                self.driver.implicitly_wait(1)
                wan_config.find_tipsshowin()
            except NoSuchElementException:
                time.sleep(1)
                i = i + 1
                print(i)
            else:
                tips = str(
                    wan_config.getAttribute_byClass(wan_config.tipsshowin,
                                                    'tip-sign'))
                print(tips, i)
                if tips != 'success':
                    CapPic(self.driver)
                    logger.info(u'线路检测保存 异常')
                    raise Exception(u'线路检测保存 异常')
                break
        else:
            raise Exception(u'线路检测保存 未弹出提示框')
        # 切换标签页判断配置正确
        wan_config.click_WANconfig()
        time.sleep(1)
        wan_config.click_GlobalConfig()
        time.sleep(1)
        DestIP3 = str(
            wan_config.getAttribute_byName(wan_config.DestIP3v, 'value'))
        self.assertEqual(DestIP3, '223.5.5.5', msg='wan3检测地址与设置不一致')

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

        self.driver.quit()
        logger.info(u'三条线路固定IP地址接入线路切换 验证通过')
예제 #21
0
    def test_002_localDMZ(self):
        u'''验证局部DMZ'''
        # #获取本机地址
        # pcaddr=socket.gethostbyname(socket.gethostname())

        # 通过用户状态获取httpserver的IP地址
        login.loginWeb(self)  # admin账号登录
        self.driver.implicitly_wait(10)
        status = Organization_userStatusPage(self.driver, self.url)
        status.click_UserManage()
        time.sleep(0.5)
        status.click_userstatus()
        time.sleep(1)
        # 将页面刷新按钮改成“手动”
        sel = status.selelement_byXpath(status.selmanual)
        Select(sel).select_by_value('manual')
        time.sleep(1)
        status.click_refreshtable()
        time.sleep(1)
        status.input_search(serverPcMac)
        status.click_searchb()
        time.sleep(1)
        try:
            serverIP = status.getText_byXpath(status.list_IP1)
            # print(serverIP)
        except NoSuchElementException:
            raise Exception(u'用户状态中未找到server IP')

        #局部DMZ
        dmz = DMZPage(self.driver, self.url)
        dmz.click_NetworkConfig()
        time.sleep(0.5)
        dmz.click_portMapping()
        time.sleep(1)
        dmz.click_DMZ()
        time.sleep(1)
        dmz.click_DMZEn()
        dmz.input_GlobalDMZ('0.0.0.0')  #防止已经有过全局DMZ设置
        dmz.input_WAN1DMZ(serverIP)
        dmz.click_save()
        time.sleep(1)
        #断言
        dmz.click_DMZ()  #相当于刷新下界面,否则on依旧没有checked参数
        time.sleep(1)
        DMZ_status = str(dmz.getAttribute_byXpath(dmz.DMZEs, 'checked'))
        print(DMZ_status)
        self.assertEqual(DMZ_status, 'true', msg='DMZ 开启有问题')
        print('局部DMZ 已开启')

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

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

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

        try:
            telnetlib.Telnet(str(WAN1_ip), port=3389, timeout=10)
            print('局部DMZ 验证成功')
        except socket.timeout:
            logger.info(u'局部DMZ 验证失败')
            raise Exception(u'局部DMZ 验证失败')
        self.driver.quit()
        logger.info('test_002_localDMZ passed')
예제 #22
0
    def test_001_static(self):
        u'''三条线路固定IP地址接入'''
        # 获取3条外线的链接类型
        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)
        # 先改为动态接入,得到正确的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 动态接入')

        # 断言
        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)
            print(str(list_connectState1), str(list_connectState2),
                  str(list_connectState3))
            list_connectState = [
                str(list_connectState1),
                str(list_connectState2),
                str(list_connectState3)
            ]
            # 动态接入 未获取到地址/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)
        print('WAN1_ip=', WAN1_ip, 'WAN2_ip=', WAN2_ip, 'WAN3_ip=', WAN3_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)
        # 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)
        # 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)
        # self.driver.quit()

        # 改为固定接入
        # 将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()  # 修改接口后 可能会回到登录页面 所以关闭,再打开

        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)
            print(str(list_connectState1), str(list_connectState2),
                  str(list_connectState3))
            list_connectState = [
                str(list_connectState1),
                str(list_connectState2),
                str(list_connectState3)
            ]
            # 动态接入 未获取到地址/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()
        # 加冒号
        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:]
        print(line1_mac2, line2_mac2, line3_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 line1_Interface_name == None:
            raise Exception('获取wan1口对应接口名称失败')
        if line2_Interface_name == None:
            raise Exception('获取wan2口对应接口名称失败')
        if line3_Interface_name == None:
            raise Exception('获取wan3口对应接口名称失败')
        tn.close()
        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)
        route_result = str(tn.read_very_eager())  # 执行多条命令时只会存最后一条命令的结果
        print('-------------------输出结果------------------------')
        # 命令执行结果
        print('route_result:', route_result)
        # 获取WAN1对应接口名称
        route_result1 = route_result[2:-7]
        print('route_result1', route_result1)
        route_result2 = route_result1.split(r'\r\n')
        print('route_result2', route_result2)

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

        for i in range(len(route_result2)):
            if wan1route in route_result2[i]:
                wan1route_status = not None
                print('wan1路由在')
            if wan2route in route_result2[i]:
                wan2route_status = not None
                print('wan2路由在')
            if wan3route in route_result2[i]:
                wan3route_status = not None
                print('wan3路由在')
        if wan1route_status == None:
            raise Exception('wan1默认路由不存在')
        if wan2route_status == None:
            raise Exception('wan2默认路由不存在')
        if wan3route_status == None:
            raise Exception('wan3默认路由不存在')
        tn.close()
        self.driver.quit()
        logger.info('test_001_static passed')
예제 #23
0
    def test_001_openRemote(self):
        u'''开启远程管理'''
        # 开启远程管理
        remoteManage = ManagementPolicyPage(self.driver, self.url)
        remoteManage.click_httpEn()
        time.sleep(0.5)
        remoteManage.click_save()
        time.sleep(1)

        #检查admin的映射是否开启
        staticMapping = staticMappingPage(self.driver, self.url)
        staticMapping.click_NetworkConfig()
        time.sleep(0.5)
        staticMapping.click_portMapping()
        time.sleep(1)
        list_Ens = staticMapping.getAttribute_byXpath(staticMapping.list1_Ens,
                                                      'checked')
        if list_Ens != 'true':
            CapPic(self.driver)
            logger.info(u'开启远程管理 静态映射未打开')
            raise Exception(u'远程管理 静态映射未打开')

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

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

        #更改pc 交换机接口与wan口/上联口通
        swconfig.test_LanToWan(self)
        if CPUmodel == 'Qualcomm':
            time.sleep(110)  # 等待计划任务执行
        #重新获取地址 应获取到上层网关下发的地址
        pcaddr = str(socket.gethostbyname(socket.getfqdn(
            socket.gethostname())))
        # 调用bat脚本 IP地址释放
        os.system('%s' % (batpath + 'ipconfig_release.bat'))
        time.sleep(2)
        pcaddr1 = str(
            socket.gethostbyname(socket.getfqdn(socket.gethostname())))
        print(pcaddr1)
        if pcaddr1 != str(pcaddr):
            print('IP地址已释放')
        else:
            time.sleep(3)
        time.sleep(2)
        # 将IP改回自动获取(设置dns为自动获取)
        # 调用bat脚本
        os.system('%s' % (batpath + 'ipconfig_renew.bat'))
        time.sleep(5)
        n = 0
        while n < 60:
            # 获取本机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('未获取到地址')
        n = 0
        while n < 30:
            ping = pingTestIP(WAN1_ip)
            if ping != "Y":
                time.sleep(1)
                n += 1
            else:
                break
        else:
            logger.info(u'切换IP后wan口方向 无法ping通wan口')
            logger.info(u'pcIP地址为 %s' % pcaddr)
            raise Exception(u'切换IP后wan口方向 无法ping通wan口')
        logger.info(u'pcIP地址为 %s' % pcaddr)
        WANURL = str('http://' + str(WAN1_ip) + ':8081')
        #使用页面获取的WAN1 ip验证登录
        login.test_enableLoginWeb(self, url=WANURL)
        self.driver.quit()

        #改回lan口方向
        # 调用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口通
        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('test_001_openRemote passed')
예제 #24
0
def swNum1():
    #下一个要升级的型号对应的lan/wan

    #1、判断当前路由器版本
    tn = telnetlib.Telnet(host=host, port=port)
    tn.set_debuglevel(5)  # 级别越高输出的调试信息越多,并没有看出区别
    # 输入登录用户名
    tn.read_until(b'login:'******'Password:'******'#')
    tn.write(b"uname -a" + b'\n')
    # 输出结果,判断
    time.sleep(1)
    result = str(tn.read_very_eager())  # 只会存最后一条命令的结果
    print('-------------------输出结果------------------------')
    # 命令执行结果
    # print('result:', result)
    nowVersion = result.split(r'\r\n')[1].split(r' ')[4]
    print(nowVersion)
    tn.close()  # tn.write('exit\n')
    #2、对比判断当前版本 是测试型号中的第几个
    n = 1
    while True:
        try:
            SoftVersion = getweb('SoftVersion' + str(n))
        except NoOptionError:
            raise Exception('未在config中找到对应版本')
        if nowVersion in SoftVersion:
            num = n + 1
            break
        else:
            n += 1
    print(n)
    SoftVersion = getweb('SoftVersion' + str(num))
    if 'v3.0.' in SoftVersion:
        SoftVersion1 = str(SoftVersion).split(r'v3.0.')[0]
    elif 'v3.1.' in SoftVersion:
        SoftVersion1 = str(SoftVersion).split(r'v3.1.')[0]
    elif 'v3.2.' in SoftVersion:
        SoftVersion1 = str(SoftVersion).split(r'v3.2.')[0]
    else:
        raise Exception('版本号超出当前设定')

    if SoftVersion1 in mtk7620Llist: #nv810Gv2为other、nv810G为-L,如果设备是nv810G可能会被误认为是oter,所以-l放前
        print('zu2')
        # Rport = [19, 20, 21, 22, 23, 24]
        return '192021222324'
    elif SoftVersion1 in mtkOtherlist:
        print('zu1')
        # Rport = [13, 14, 15, 16, 17, 18]
        return '131415161718'
    elif SoftVersion1 in QCAlist:
        print('zu3')
        # Rport = [25, 26, 27, 28, 29, 30]
        return '252627282930'
    elif SoftVersion1 in p1010list:
        print('zu4')
        # Rport = [31, 32, 33, 34, 35, 36]
        return '313233343536'
    elif SoftVersion1 in D525list:
        print('zu5')
        # Rport = [37, 38, 39, 40, 41, 42]
        return '373839404142'
    elif SoftVersion1 in j1800list or SoftVersion1 in j1800list2 or SoftVersion1 in i3list:
        print('zu6')
        # Rport = [43, 44, 45, 46, 47, 48]
        return '434445464748'
    else:
        raise Exception('未找到该型号对应的接口')
예제 #25
0
#! -*-conding:utf-8 -*-
#@Time: 2019/4/17 0017 18:48
#@swzhou
'''
清理chrome 进程,释放内存占用
'''


import os
import socket
import time
import unittest
from common.ReadConfig import getweb
batpath = os.path.dirname(os.path.abspath('.')) + '/script/'
batSameIP = getweb('batSameIP')

class initTestPC(unittest.TestCase):

    def setUp(self):
        print('initTestPC start')
        # pass

    def test_initTestPC(self):
        #清理进程
        os.system('taskkill /im chromedriver.exe /F')
        os.system('taskkill /im chrome.exe /F')

        os.system('taskkill /im geckodriver.exe /F')
        os.system('taskkill /im Firefox.exe /F')

        os.system('taskkill /im "tftpd32.exe" /F')
예제 #26
0
    def test_001_tcp80(self):
        u'''验证tcp80 映射'''

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

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

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

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

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

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

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

        # win32process.TerminateProcess(handle[0], 0)  # 关闭Everying,没有能关闭掉就不关了
        logger.info('test_001_tcp80 passed')
예제 #27
0
    def test_001_open(self):
        u'''启用负载均衡'''
        v1APname = getweb('v1APname')
        OnlineA = getAssertText('OnlineA')
        port = gettelnet('port')
        username = bytes(getweb('User'), encoding="utf8")
        password = bytes(getweb('Passwd'), encoding="utf8")
        device = deviceMgmtPage(self.driver, self.url)
        #1 查看未启用负载均衡
        device.click_wirelessExtension()
        time.sleep(0.5)
        device.click_deviceMgmt()
        time.sleep(1)
        # 点击管理通讯协议,v2在上
        device.click_Priorityv2()
        time.sleep(1)
        # 先确认AP均上线
        x = 0
        while x < 100:
            device.click_refreshtable()
            time.sleep(1)
            list_status1 = device.getText_byXpath(device.list_status1)
            list_status2 = device.getText_byXpath(device.list_status2)
            list_status3 = device.getText_byXpath(device.list_status3)
            list_status4 = device.getText_byXpath(device.list_status4)
            print(list_status1, list_status2, list_status3, list_status4, x)
            if list_status1 == OnlineA and list_status2 == OnlineA and list_status3 == OnlineA and list_status4 == OnlineA:
                print('4台AP均在线', x)
                channel1 = str(device.getAttribute_byXpath(device.list_channel1, 'data-local'))
                channel2 = str(device.getAttribute_byXpath(device.list_channel2, 'data-local'))
                channel3 = str(device.getAttribute_byXpath(device.list_channel3, 'data-local'))
                channel4 = str(device.getAttribute_byXpath(device.list_channel4, 'data-local'))
                print('channel1=', channel1, 'channel2=', channel2, 'channel3=', channel3, 'channel4=', channel4, x)
                if channel1 != '' and channel2 != '' and channel3 != '' and channel4 != '':
                    print('4台AP2.4G无线接口已同步', x)
                    break
                else:
                    time.sleep(3)
            else:
                time.sleep(3)
            x = x + 1
        else:
            CapPic(self.driver)
            logger.info(u'AP  未能同步2.4G无线接口')
            raise Exception('AP  未能同步2.4G无线接口')
        #获取 wa3000N的IP
        device.input_search(v1APname)
        device.click_searchB()
        list_ip1 = device.getText_byXpath(device.list_IP1)
        #telnet
        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:       0"  in result) or( "uttMaxStaNum:       32") in result:
            logger.info(u'负载均衡未开启 AP资源数正常')
        else:
            logger.info(u'负载均衡未开启 AP资源数异常')
            logger.info('result:', result)
            raise Exception('负载均衡未开启 AP资源数异常')
        tn.close()  # tn.write('exit\n')

        #2 开启负载均衡
        enableA = getAssertText('enableA')
        load = loadBalancingPage(self.driver, self.url)
        load.click_loadBalancing()
        time.sleep(1)
        load.click_add()
        time.sleep(1)
        load.input_loadBalanceNames('test')
        load.click_selAP1()
        load.click_toright()
        time.sleep(0.5)
        load.click_selAP1()
        load.click_toright()
        time.sleep(0.5)
        load.click_selAP1()
        load.click_toright()
        time.sleep(0.5)
        load.click_selAP1()
        load.click_toright()
        time.sleep(0.5)
        load.click_save()
        time.sleep(1)
        liststate = load.getText_byXpath(load.list_state)
        self.assertEqual(liststate,enableA,msg='AP负载均衡未启用')
        checkOpens = load.getAttribute_byId(load.checkOpens,'checktype') #1开启,0关闭
        self.assertEqual(checkOpens,'0',msg='负载均衡 开关默认未关闭')
        load.click_checkOpen()
        time.sleep(1)
        checkOpens = load.getAttribute_byId(load.checkOpens, 'checktype')
        self.assertEqual(checkOpens, '1', msg='负载均衡 开启失败')
        time.sleep(10)

        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:       0") not in result and ("uttMaxStaNum:       32") not in result:
            logger.info('负载均衡开启 AP资源数正常')
        else:
            logger.info('负载均衡开启 AP资源数异常')
            print('result:', result)
            logger.info('result:', result)
            raise Exception('负载均衡开启 AP资源数异常')
        tn.close()  # tn.write('exit\n')

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