def teardown_method(self): self.clr_met = clr_env.clear_met for i in self.clr_met: fun.cmd(i, 'gw') fun.pid_kill(self.cap_pcap)
def teardown_method(self): self.clr_met = clr_env.clear_met for i in self.clr_met: fun.cmd(i, 'gw') # 判断抓包程序是否停止,如果进程还在则停止 fun.pid_kill(self.cap_pcap1)
def teardown_class(self): # 回收环境 clr_env.clear_env() fun.pid_kill('8889', process='python3', gw='vlanA') fun.pid_kill('8889', process='python3', gw='gw') fun.send(rbmExc, message.delvlan['SetVlan'], rbmDomain, base_path) fun.rbm_close() fun.ssh_close('gw') fun.ssh_close('vlanA') fun.ssh_close('vlanB')
def teardown_method(self): clr_env.clear_met_acl() # 判断抓包程序是否停止,如果进程还在则停止 fun.pid_kill(self.cap_pcap1) fun.pid_kill(self.cap_pcap2) fun.pid_kill(self.cap_pcap3) fun.pid_kill(self.cap_pcap4)
def teardown_method(self): clr_env.clear_env() fun.pid_kill(self.cap_pcap1, 'python', 's') fun.pid_kill(self.cap_pcap3, 'python', 's') fun.pid_kill(self.cap_pcap4, 'python', 's') fun.pid_kill(self.cap_pcap5, 'python', 's') fun.cmd(f"rm -rf /opt/pkt/*pcap", 'gw') re = fun.cmd(f"ls /opt/pkt/", 'gw') print('teardown_method_re:', re)
def teardown_method(self): self.clr_met = clr_env.clear_met for i in self.clr_met: fun.cmd(i, 'gw') fun.cmd(f"rm -rf /opt/pkt/*pcap", 'gw') re = fun.cmd(f"ls /opt/pkt/ | grep pcap", 'gw') print('re:', re) fun.pid_kill(self.cap_pcap1,'pyhton','s') fun.pid_kill(self.cap_pcap2, 'pyhton', 's') fun.pid_kill(self.cap_pcap3,'pyhton','s')
def teardown_method(self): self.clr_met = clr_env.clear_met for i in self.clr_met: fun.cmd(i, 'gw') fun.pid_kill(self.cap_pcap1, 'pyhton', 's') fun.pid_kill(self.hping3_1, 'hping3', 'c') fun.pid_kill(self.http_1, 'python2.7', 's') fun.pid_kill(self.cap_pcap2, 'pyhton', 's') fun.pid_kill(self.hping3_2, 'hping3', 'c') fun.pid_kill(self.http_2, 'python2.7', 's')
def teardown_method(self): clr_env.clear_met_acl() fun.pid_kill(self.cap_pcap1, 'python', 's') fun.pid_kill(self.cap_pcap3, 'python', 's')
def test_vlan_bond_a2(self): # 开启switch开关并检查是否开启成功 for key in self.case1_step1: fun.cmd(self.case1_step1[key][0], 'gw') re = fun.cmd(self.case1_step1[key][1], 'gw') assert self.case1_step1[key][2] in re # 下发vlan配置 fun.send(rbmExc, message.setvlan['SetVlan'], rbmDomain, base_path) # 检查配置下发是否成功 for key in self.case1_step2: re = fun.wait_data(self.case1_step2[key][0], 'gw', self.case1_step2[key][1], 'vlan', 100) assert self.case1_step2[key][1] in re # 测试从设备端ping vlanA设备正常 print('测试从设备端ping vlanA设备正常') resA_cmd = 'ping ' + vlanAOpeIp + ' -c 4' print('从设备端ping vlanA设备的命令是:{}'.format(resA_cmd)) resA = fun.cmd(resA_cmd, 'gw') print('从设备端ping vlanA的结果为:{}'.format(resA)) assert '0% packet loss' in resA # 测试从vlanB ping设备正常 dutB_cmd = 'ping ' + gwInternetIp + ' -c 4' print('从vlanB ping设备的命令是:{}'.format(dutB_cmd)) dutB = fun.cmd(dutB_cmd, 'vlanB') print('从vlanB ping设备的结果为:{}'.format(dutB)) assert '0% packet loss' in dutB # 测试从vlanA scp传输文件到设备上,应该可以传输成功 print('测试从vlanA scp传输文件到设备上,应该可以传输成功') # 在vlanA的/opt/pkt/路径下创建一个10M大小的文件10M.pdf touch_file_cmd = [ 'cd /opt/pkt', 'dd if=/dev/zero of=vlanA.pdf bs=1M count=10' ] fun.cmd(touch_file_cmd, 'vlanA', list_flag=True) # 检查设备文件是否创建成功 touch_file = fun.search('/opt/pkt', 'pdf', 'vlanA') print('检查服务端/opt/pkt/目录下所有以pdf结尾的文件列表为:{}'.format(touch_file)) assert 'vlanA.pdf' in touch_file # 验证从vlanA发送scp命令上传 scp_cmd = f'sshpass -p {gwPwd} scp /opt/pkt/vlanA.pdf root@{gwInternetIp}:/opt/pkt/' print('从vlanA scp传输文件到设备为:{}'.format(scp_cmd)) fun.cmd(scp_cmd, 'vlanA') # 检查文件是否上传成功到设备 touch_file = fun.search('/opt/pkt', 'pdf', 'gw') print('检查客户端/opt/pkt/目录下所有以pdf结尾的文件列表为:{}'.format(touch_file)) assert 'vlanA.pdf' in touch_file # 下载完成后,还原环境,清掉上传到设备的文件 fun.cmd('rm -f /opt/pkt/vlanA.pdf ', 'gw') check_file = fun.search('/opt/pkt', 'pdf', 'gw') print('还原环境,vlanA.pdf文件应该不在列表内,列表为{}'.format(check_file)) # 测试设备scp获取vlanB上的文件,应该可以传输成功 print('测试设备scp获取vlanB上的文件,应该可以传输成功') # 在vlanB的/opt/pkt/路径下创建一个10M大小的文件vlanB.txt touch_file_cmd = [ 'cd /opt/pkt', 'dd if=/dev/zero of=vlanB.txt bs=1M count=10' ] fun.cmd(touch_file_cmd, 'vlanB', list_flag=True) # 检查vlanB文件是否创建成功 touch_file = fun.search('/opt/pkt', 'txt', 'vlanB') print('检查服务端/opt/pkt/目录下所有以txt结尾的文件列表为:{}'.format(touch_file)) assert 'vlanB.txt' in touch_file # 验证从设备端发送scp命令下载 scp_cmd = f'sshpass -p {vlanBPwd} scp root@{vlanBOpeIp}:/opt/pkt/vlanB.txt /opt/pkt/' print('scp下载的命令为:{}'.format(scp_cmd)) fun.cmd(scp_cmd, 'gw') # 检查文件是否下载成功到设备 touch_file = fun.search('/opt/pkt', 'txt', 'gw') print('检查客户端/opt/pkt/目录下所有以txt结尾的文件列表为:{}'.format(touch_file)) assert 'vlanB.txt' in touch_file # 下载完成后,还原环境,清掉从vlanB下载的文件 fun.cmd('rm -f /opt/pkt/vlanB.txt ', 'gw') check_file = fun.search('/opt/pkt', 'txt', 'gw') print('还原环境,vlanB.txt文件应该不在列表内,列表为{}'.format(check_file)) # 测试从vlanB往设备上发起http的get请求,应该可以请求成功 print('测试从vlanB往设备上发起http的get请求,应该可以请求成功') # 在设备的/opt/pkt/路径下创建一个10M大小的文件gw.txt touch_file_cmd = [ 'cd /opt/pkt', 'dd if=/dev/zero of=gw.txt bs=1M count=10' ] fun.cmd(touch_file_cmd, 'gw', list_flag=True) # 检查gw文件是否创建成功 touch_file = fun.search('/opt/pkt', 'txt', 'gw') print('检查设备/opt/pkt/目录下所有以txt结尾的文件列表为:{}'.format(touch_file)) assert 'gw.txt' in touch_file # 在设备上开启端口占用服务 port_listen_cmd = ['cd /opt/pkt', 'python3 -m http.server 8889'] fun.cmd(port_listen_cmd, 'gw', thread=1, list_flag=True) # 从vlanB往设备发送get请求,验证vlan下的http协议 vlanB_url = 'wget -P /opt/pkt/ http://' + gwInternetIp + ':8889/gw.txt' print('vlanB请求设备的请求地址为{}'.format(vlanB_url)) resA = fun.cmd(vlanB_url, 'vlanB') print('设备wget请求vlanA.pdf文件的结果是{}:'.format(resA)) # 检查文件是否下载成功到vlanB wget_file = fun.search('/opt/pkt', 'txt', 'gw') print('检查vlanB设备/opt/pkt/目录下所有以txt结尾的文件列表为:{}'.format(wget_file)) assert 'gw.txt' in wget_file # 下载完成后,还原环境,清掉vlanB下载的文件 fun.cmd('rm -f /opt/pkt/gw.txt ', 'vlanB') check_file = fun.search('/opt/pkt', 'txt', 'vlanB') print('还原环境,gw.txt文件应该不在vlanB设备的列表内,列表为{}'.format(check_file)) # 测试从设备wget请求下载vlanA的vlanA.pdf文件,应该可以请求成功 print('测试从设备wget请求下载vlanA的vlanA.pdf文件,应该可以请求成功') # 在vlanA上开启端口占用服务 port_listen_cmd = ['cd /opt/pkt', 'python3 -m http.server 8889'] fun.cmd(port_listen_cmd, 'vlanA', thread=1, list_flag=True) # 发送get请求,验证vlan下的http协议 vlanA_url = 'wget -P /opt/pkt/ http://' + vlanAOpeIp + ':8889/vlanA.pdf' print('设备请求vlanA的请求地址为{}'.format(vlanA_url)) fun.cmd(vlanA_url, 'gw') time.sleep(2) # 检查文件是否下载成功到设备 vlanA_file = fun.search('/opt/pkt', 'pdf', 'gw') print('检查客户端/opt/pkt/目录下所有以pdf结尾的文件列表为:{}'.format(vlanA_file)) assert 'vlanA.pdf' in vlanA_file # 下载完成后,还原环境,清掉从vlanA下载的文件 fun.cmd('rm -f /opt/pkt/vlanA.pdf ', 'gw') check_file = fun.search('/opt/pkt', 'pdf', 'gw') print('还原环境,vlanA.pdf文件应该不在列表内,列表为{}'.format(check_file)) # 还原环境,杀掉端口占用的进程,移除vlan的配置,且关闭vlan的开关 fun.pid_kill('8889', process='python3', gw='vlanA') fun.pid_kill('8889', process='python3', gw='gw') # 关闭switch开关并检查是否关闭成功 for key in self.case1_step11: fun.cmd(self.case1_step11[key][0], 'gw') re = fun.cmd(self.case1_step11[key][1], 'gw') assert self.case1_step11[key][2] in re # 清空vlan配置 fun.send(rbmExc, message.delvlan['SetVlan'], rbmDomain, base_path) # 检查配置下发是否成功 for key in self.case1_step2: re = fun.wait_data(self.case1_step2[key][0], 'gw', self.case1_step2[key][1], 'vlan', 100, flag='不存在') assert self.case1_step2[key][1] not in re
def teardown_method(self): clr_env.clear_met_acl() fun.pid_kill(self.cap_pcap)
def teardown_method(self): self.clr_met = clr_env.clear_met for i in self.clr_met: fun.cmd(i, 'gw') fun.pid_kill(self.cap_pcap1) fun.pid_kill(self.cap_pcap2) fun.pid_kill(self.cap_pcap3) fun.pid_kill(self.cap_pcap4) fun.pid_kill(self.cap_pcap5) fun.pid_kill(self.cap_pcap6) fun.pid_kill(self.cap_pcap7) fun.pid_kill(self.cap_pcap8)
def teardown_method(self): clr_env.clear_met_acl() fun.pid_kill(self.cap_pcap1) fun.pid_kill(self.cap_pcap2) fun.pid_kill(self.cap_pcap3) fun.pid_kill(self.cap_pcap4) fun.pid_kill(self.cap_pcap5) fun.pid_kill(self.cap_pcap6) fun.pid_kill(self.cap_pcap7) fun.pid_kill(self.cap_pcap8)
def test_acl_drop_a1(self): # 初始化 cap_iface, cap_filter, cap_num, cap_pcap1, cap_pcap2, cap_pcap3 = self.pkt1_cfg["capture"][0], \ self.pkt1_cfg["capture"][1], \ self.pkt1_cfg["capture"][2], \ self.pkt1_cfg["capture"][3], \ self.pkt1_cfg['capture'][4], \ self.pkt1_cfg['capture'][5] c_iface, c_num, c_pcap = self.pkt1_cfg["send"][0], self.pkt1_cfg["send"][1], self.pkt1_cfg["send"][2] read_name1, read_name2, read_name3, read_id = self.pkt1_cfg["read"][0], self.pkt1_cfg["read"][1], \ self.pkt1_cfg['read'][2], self.pkt1_cfg['read'][3] # 下发配置并检查结果 for key in self.case1_step1: fun.cmd(self.case1_step1[key][0], 'gw') re = fun.cmd(self.case1_step1[key][1], 'gw') assert self.case1_step1[key][2] in re # 服务端抓取报文 pre_cfg1 = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap1) print(pre_cfg1) fun.cmd(pre_cfg1, 's', thread=1) print('step wait') time.sleep(20) # 发送报文 send_cmd = fun.pkt_send(c_iface, c_num, c_pcap) fun.cmd(send_cmd, 'c') # 检查报文是否存在 pcap_file = fun.search('/opt/pkt', 'pcap', 's') fun.pid_kill(cap_pcap1) assert cap_pcap1 in pcap_file # 读包 read_cmd = fun.pkt_read(read_name1, read_id) read_re = fun.cmd(read_cmd, 's') print('read_re: ', read_re) # 获取期望结果 exp = self.pkt1_cfg["expect"][0] assert exp == read_re # 再次下发配置并检查结果 for key in self.case1_step2: fun.cmd(self.case1_step2[key][0], 'gw') re = fun.cmd(self.case1_step2[key][1], 'gw') assert self.case1_step2[key][2] in re pre_cfg2 = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap2) print(pre_cfg2) fun.cmd(pre_cfg2, 's', thread=1) print('step wait') time.sleep(20) # 发送报文 send_cmd = fun.pkt_send(c_iface, c_num, c_pcap) fun.cmd(send_cmd, 'c') # 检查报文是否存在 pcap_file = fun.search('/opt/pkt', 'pcap', 's') fun.pid_kill(cap_pcap2) assert cap_pcap2 in pcap_file # 读包 read_cmd = fun.pkt_read(read_name2, read_id) read_re = fun.cmd(read_cmd, 's') print('read_re: ', read_re) # 获取期望结果 exp = self.pkt1_cfg["expect"][0] assert exp == read_re # 再次下发配置并检查结果 for key in self.case1_step3: fun.cmd(self.case1_step3[key][0], 'gw') re = fun.cmd(self.case1_step3[key][1], 'gw') assert self.case1_step3[key][2] in re pre_cfg3 = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap3) print(pre_cfg3) fun.cmd(pre_cfg3, 's', thread=1) print('step wait') time.sleep(20) # 发送报文 send_cmd = fun.pkt_send(c_iface, c_num, c_pcap) fun.cmd(send_cmd, 'c') # 检查报文是否存在 pcap_file = fun.search('/opt/pkt', 'pcap', 's') fun.pid_kill(cap_pcap3) assert cap_pcap3 in pcap_file # 读包 read_cmd = fun.pkt_read(read_name3, read_id) read_re = fun.cmd(read_cmd, 's') print('read_re: ', read_re) # 获取期望结果 exp = self.pkt1_cfg["expect"][0] assert exp == read_re
def teardown_method(self): clr_env.clear_env() fun.pid_kill(self.cap_pcap1, 'pyhton', 's') fun.pid_kill(self.cap_pcap2, 'pyhton', 's') fun.pid_kill(self.cap_pcap3, 'pyhton', 's')