Пример #1
0
 def test_002_clearparametersFile(self):
     u'''删除生成的 参数文件'''
     parameterExcel = getpath('parameterExcel')
     file = parameterExcel
     path_xlsx= tmppath  # 配置文件存放(下载)路径
     sys.path.append(r'%s' % path_xlsx)
     files_cvs = os.listdir(r'%s' % path_xlsx)  # os.listdir(path) 返回path指定的文件夹包含的文件或文件夹的名字的列表
     for filename_cvs in files_cvs:
         portion_cvs = os.path.splitext(filename_cvs)  # splitext()用于返回 文件名和扩展名 元组
         # print(portion_cvs)
         if file.split(r'.')[0] == portion_cvs[0]:  # 如果文件名包含"流量监控20"
             if portion_cvs[1] == '.xlsx':  # 后缀是 .csv
                 # 重新组合文件名和后缀名,直接修改名称的话 程序和文件必须在一个目录下
                 filenamedir_cvs = (r'%s' % path_xlsx) + filename_cvs
                 os.remove(filenamedir_cvs)
     logger.info(u'参数表文件已删除')
     logger.info(u'test_002_clearparametersFile over')
Пример #2
0
def getExcelValue(parameter):
    excel = tmppath + getpath('parameterExcel')
    wb = load_workbook(excel)
    sheets = wb.get_sheet_names()
    sheets_first = sheets[0]
    ws = wb.get_sheet_by_name(sheets_first)

    location = 'A%s'
    y = []
    x = 1
    while x < 300:  # 假设有300行
        # print(ws[location % x].value)
        if ws[location % x].value != None:
            if str(ws[location % x].value).isspace():#判断末尾是否是空格
                y.append(u'%s' % str(ws[location % x].value).split(r' ')[0])
            else:
                y.append(u'%s' % str(ws[location % x].value))
            # y.append(str(ws[location % x].value))
        x += 1
    # print(y)

    i = 0
    # print(len(y))
    while i < (len(y)):
        # print('"%s"' % y[i],i)
        if str(parameter) == str(y[i]):
            # print(parameter,str(y[i]))
            parameter1 = ('A%s' % (i))
            # print(parameter1)
            value = ('B%s' % (i+1))
            # print(parameter,ws[value].value)
            # print(str(ws[value].value).isspace())
            # if str(ws[value].value).isspace():  # 判断末尾是否是空格
            #     return str(ws[value].value).split(r' ')[0]
            # else:
            #     return ws[value].value
            if parameter == '产品型号': #产品型号 名称一般有空格
                return str(ws[value].value)
            elif str(' ') in str(ws[value].value)[0]:  # 判断前是否是空格
                return str(ws[value].value).split(r' ')[1]
            else:
                return str(ws[value].value).split(r' ')[0]
        i += 1
Пример #3
0
    def test_001_Getallparameters(self):
        u'''生成 参数文件'''
        excel = getpath('parameterpath')
        excel2 = tmppath + getpath('parameterExcel')

        natsessionP = getParameter('natsessionP')
        memoryP = getParameter('memoryP')
        wifiload2Gp = getParameter('wifiload2Gp')
        wifiload5Gp = getParameter('wifiload5Gp')
        sessionLifep = getParameter('sessionLifep')
        passwdErrNumP = getParameter('passwdErrNumP')
        loginSpanP = getParameter('loginSpanP')
        licenseP = getParameter('licenseP')
        portTateWANp = getParameter('portTateWANp')
        portTateLANp = getParameter('portTateLANp')
        staticRp = getParameter('staticRp')
        policyP = getParameter('policyP')
        NetSniperP = getParameter('NetSniperP')
        staticMapP = getParameter('staticMapP')
        natRuleP = getParameter('natRuleP')
        bandingVPNp = getParameter('bandingVPNp')
        FirewallP = getParameter('FirewallP')
        addGroupP = getParameter('addGroupP')
        timePlanP = getParameter('timePlanP')
        actionMp = getParameter('actionMp')
        QQnumP = getParameter('QQnumP')
        alinumP = getParameter('alinumP')
        DomainFilerP = getParameter('DomainFilerP')
        FlowruleP = getParameter('FlowruleP')
        vlanPortP = getParameter('vlanPortP')
        portVlanP = getParameter('portVlanP')
        portmirrorP = getParameter('portmirrorP')
        L2tpP = getParameter('L2tpP')
        pptpP = getParameter('pptpP')
        ipsecP = getParameter('ipsecP')
        ibindingPp = getParameter('ibindingPp')
        vpnNumP = getParameter('vpnNumP')
        userNumP = getParameter('userNumP')
        ipmac = getParameter('ipmac')
        pppoeSp = getParameter('pppoeSp')
        webAutnp = getParameter('webAutnp')
        remoteAuthP = getParameter('remoteAuthP')
        BlacklistP = getParameter('BlacklistP')
        netShareP = getParameter('netShareP')
        FtpP = getParameter('FtpP')
        APnumP = getParameter('APnumP')
        RoamP = getParameter('RoamP')
        ssidnumP = getParameter('ssidnumP')
        line = [natsessionP, memoryP,wifiload2Gp,wifiload5Gp,sessionLifep,passwdErrNumP,loginSpanP,licenseP,portTateWANp
            ,portTateLANp,staticRp,policyP,NetSniperP,staticMapP,natRuleP,bandingVPNp,FirewallP,addGroupP,timePlanP
            ,actionMp,QQnumP,alinumP,DomainFilerP,FlowruleP,vlanPortP,portVlanP,portmirrorP,L2tpP,pptpP,ipsecP,ibindingPp
            ,vpnNumP,userNumP,ipmac,pppoeSp,webAutnp,remoteAuthP,BlacklistP,netShareP,FtpP,APnumP,RoamP,ssidnumP]

        wbb = Workbook()
        wsb = wbb.active
        wbb.save(excel2)

        wb = load_workbook(excel)
        sheets = wb.get_sheet_names()
        first = sheets[0]
        ws = wb.get_sheet_by_name(first)

        wb2 = load_workbook(excel2)
        sheets2 = wb2.get_sheet_names()
        first2 = sheets2[0]
        ws2 = wb2.get_sheet_by_name(first2)

        location = 'C%s'
        y = []
        x = 1
        while x < 300: #假设有300行
            # print(ws[location % x].value)
            if ws[location % x].value != None:
                y.append(ws[location % x].value)
            x += 1
        # print(y)
        i = 0
        n = 1
        while i < (len(y)):
            # print(y[i])
            for linex in line:
                if linex in y[i]:
                    # print(i,i + 8)
                    p = ('D%s' % (i + 1))
                    value0 = str(ws[p].value)
                    if '支持' in value0:
                        if '(' in value0:
                            valuex = str(value0).split(r'(')[1].split(r')')[0]
                        elif '(' in value0:
                            valuex = str(value0).split(r'(')[1].split(r')')[0]
                        # print('1', valuex)
                    elif 'DDR3 ' in value0:
                        valuex = str(value0).split(r' ')[1]
                        print('2', valuex)
                    else:
                        valuex = value0
                        print('3', value0)

                    ws2['A%s' % n] = y[i]
                    ws2['B%s' % n] = valuex
                    wb2.save(excel2)
                    n += 1
            i += 1
        # print(p,ws[p].value)
        logger.info(u'参数表文件已获取并生成')
        logger.info(u'test_001_Getallparameters over')
Пример #4
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、新建一条vpn 使生成syslog
        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('11.2.3.4')
        pptpl2tp.input_userNames('test')
        pptpl2tp.input_password('test')
        pptpl2tp.input_remoteInIp('11.2.3.4')
        pptpl2tp.input_remoteInIPMask('255.255.255.0')
        pptpl2tp.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'验证通过')
        #删除vpn 关闭syslog
        nodata = getAssertText('nodata')
        # 删除VPN
        pptpl2tp = pptpL2tpPage(self.driver, self.url)
        pptpl2tp.click_pptpL2tp()
        time.sleep(1)
        pptpl2tp.click_selall()
        time.sleep(0.2)
        pptpl2tp.click_delall()
        time.sleep(1)
        pptpl2tp.click_ok()
        time.sleep(2)
        list_nodata = pptpl2tp.getText_byXpath(pptpl2tp.list_nodata)
        if list_nodata == nodata:
            logger.info(u'VPN 已删除')
        else:
            CapPic(self.driver)
            logger.info(u'VPN删除失败')
            raise Exception(u'VPN删除失败')
        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_syslogC()
        syslog.click_save()
        time.sleep(1)
        syslogCs = syslog.getAttribute_byXpath(syslog.SyslogCs, 'checked')
        self.assertEqual(syslogCs, 'true', msg='syslog服务器关闭失败')

        self.driver.quit()
        logger.info('test_reboot1 passed')
Пример #5
0
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账号登录
        self.driver.implicitly_wait(10)
        status = Organization_userStatusPage(self.driver, self.url)
Пример #6
0
#coding=gbk
#@Time: 2019/4/17 0017 15:01
#@swzhou
'''
生成新的参数文件
'''
import os
import sys
from openpyxl import Workbook
from openpyxl import load_workbook
from common.ReadConfig import getpath,getParameter
from common.LogGen import LogGen
logger = LogGen(Logger = 'ParametersFile').getlog()
tmppath = os.path.dirname(os.path.abspath('.')) + '/tmp/'

excel = getpath('parameterpath1')
excel2 = tmppath + getpath('parameterExcel')

#1、删除/tmp/parameterTmp.xlsx文件
parameterExcel = getpath('parameterExcel')
file = parameterExcel
path_xlsx= tmppath  # 配置文件存放(下载)路径
sys.path.append(r'%s' % path_xlsx)
files_cvs = os.listdir(r'%s' % path_xlsx)  # os.listdir(path) 返回path指定的文件夹包含的文件或文件夹的名字的列表
for filename_cvs in files_cvs:
    portion_cvs = os.path.splitext(filename_cvs)  # splitext()用于返回 文件名和扩展名 元组
    # print(portion_cvs)
    if file.split(r'.')[0] == portion_cvs[0]:  # 如果文件名包含"流量监控20"
        if portion_cvs[1] == '.xlsx':  # 后缀是 .csv
            # 重新组合文件名和后缀名,直接修改名称的话 程序和文件必须在一个目录下
            filenamedir_cvs = (r'%s' % path_xlsx) + filename_cvs
Пример #7
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')