def test_traffic_icmp_failure(login_ip1, login_ip5): status = True print "After Blocking ICMP Traffic in FW-Builder" c1 = SSHConnection(IP=login_ip1, username="******", password="******") c5 = SSHConnection(IP=login_ip5, username="******", password="******") if c1.connect() and c5.connect(): c5.execute_command("ifconfig ens4") eth1_detail = c5.conn.rc.before c5_ens4_ip = util_findhost.search_host(eth1_detail) print "c5_ens4_ip :", c5_ens4_ip cmd = "ping -c 3 " + c5_ens4_ip pat = "100% packet loss" check2 = run_check_cmd(c1, cmd, pat) print "the value of icmp check2 is:", check2 if check2: print "Verification of Ping test after disabling icmp -- Successful" else: status = False print "Verification of Ping test after disabling icmp -- Failed." c1.disconnect() c5.disconnect() return status
def test_traffic_http_failure(login_ip1, login_ip5): status = True print "After Blocking HTTP Traffic in FW-Builder" c1 = SSHConnection(IP=login_ip1, username="******", password="******") c5 = SSHConnection(IP=login_ip5, username="******", password="******") if c1.connect() and c5.connect(): c5.execute_command("ifconfig ens4") eth1_detail = c5.conn.rc.before c5_eth1_ip = util_findhost.search_host(eth1_detail) c1.execute_command("ifconfig ens4") eth1_detail = c1.conn.rc.before c1_eth1_ip = util_findhost.search_host(eth1_detail) print "c5_eth1_ip :", c5_eth1_ip #cmd = "i=0; while [ $i -lt 10 ]; do wget http://" + c5_eth1_ip + ";sleep 1; $i=$i+1;done" cmd = "wget http://" + c5_eth1_ip print "cmd", cmd #pat = "HTTP request sent, awaiting response... 200 OK" pat = "200 OK" cmd1 = 'sudo tcpdump -nqt -s 0 -A -i ens4 port 80 | grep "IP ' + c1_eth1_ip + '"' pat1 = c1_eth1_ip check1 = run_nt_check_cmd(c1, cmd, pat) print "check1", check1 check2 = run_nt_check_cmd(c5, cmd1, pat1) print "check2", check2 if check1 and check2: print "Verification of traffic test after disabling http -- Successful" else: status = False print "Verification of traffic test after disabling http -- Failed." c1.disconnect() c5.disconnect() return status
def validate_ip_vnf(stack_name): server_name = parse_json('stackShow', stack_name, "server_name") ip_set = parse_json('serverShow', server_name, "addresses") print ip_set if ';' in ip_set: ip2 = ip_set.split(';')[0].split("=")[1] ip_set = ip_set.split(';')[1] else: ip2 = None ip = ip_set.split(',')[0].split("=")[1] ip_float = ip_set.split(',')[1] if ip2: subprocess.call(["sudo", "dhclient", "eth1"]) subprocess.call(["cp", "/dev/null", "/home/test/.ssh/known_hosts"]) c1 = SSHConnection(IP=ip_float, username="******", ssh_key="/home/test/automation/lcm/key234demo.pem") try: c1.connect() except: print "first connection failed" time.sleep(180) c1 = SSHConnection(IP=ip_float, username="******", ssh_key="/home/test/automation/lcm/key234demo.pem") c1.connect() c1.execute_command("ifconfig br-lan") intf_v = c1.conn.rc.before ip_eth0 = util_findhost.search_host(intf_v) if ip2: c1.execute_command("sudo ifconfig eth1") intf_v = c1.conn.rc.before ip_eth1 = util_findhost.search_host(intf_v) c1.disconnect() if ip2: assert ip_eth1 == ip2 return ip_eth0 == ip
def test_conf_vm(login_ip1, login_ip2, login_ip3, login_ip4, login_ip5, login_ip6, conf_ip_vm1, conf_ip1_vm2, conf_ip2_vm2, conf_ip3_vm2, conf_ip1_vm3, conf_ip2_vm3, conf_ip3_vm3, conf_ip_vm4, conf_ip_vm5, conf_ip_vm6, vm1_name, vm2_name, vm3_name, vm4_name, vm5_name, vm6_name): c1 = SSHConnection(IP=login_ip1, username="******", password="******") #c2 = SSHConnection(IP=login_ip2, username="******", ssh_key="/home/execution/mykey.pem") #c3 = SSHConnection(IP=login_ip3, username="******", ssh_key="/home/execution/mykey.pem") c2 = SSHConnection(IP=login_ip2, username="******", password="******") c3 = SSHConnection(IP=login_ip3, username="******", password="******") c4 = SSHConnection(IP=login_ip4, username="******", password="******") c5 = SSHConnection(IP=login_ip5, username="******", password="******") c6 = SSHConnection(IP=login_ip6, username="******", password="******") time.sleep(30) con_handle = [c1, c2, c3, c4, c5, c6] if c1.connect() and c2.connect() and c3.connect() and c4.connect( ) and c5.connect() and c6.connect(): time.sleep(30) c2.execute_command("ifconfig -a | grep ^e") print "intf detail 2 ::: ", c2.conn.rc.before intf_v2 = c2.conn.rc.before intf_list_v2 = util_findhost.get_intf(intf_v2) print "intf_list_v2 ::: ", intf_list_v2 time.sleep(5) c3.execute_command("ifconfig -a | grep ^e") print "intf detail 3 ::: ", c3.conn.rc.before intf_v3 = c3.conn.rc.before intf_list_v3 = util_findhost.get_intf(intf_v3) print "intf_list_v3 ::: ", intf_list_v3 time.sleep(5) vm1_set_eth1 = "sudo ifconfig eth1 " + conf_ip_vm1 + " netmask 255.255.255.0 up" vm2_set_eth1 = "sudo ifconfig " + intf_list_v2[ 1] + " " + conf_ip1_vm2 + " netmask 255.255.255.0 up" vm2_set_eth2 = "sudo ifconfig " + intf_list_v2[ 2] + " " + conf_ip2_vm2 + " netmask 255.255.255.0 up" vm2_set_eth3 = "sudo ifconfig " + intf_list_v2[ 3] + " " + conf_ip3_vm2 + " netmask 255.255.255.0 up" vm3_set_eth1 = "sudo ifconfig " + intf_list_v3[ 1] + " " + conf_ip1_vm3 + " netmask 255.255.255.0 up" vm3_set_eth2 = "sudo ifconfig " + intf_list_v3[ 2] + " " + conf_ip2_vm3 + " netmask 255.255.255.0 up" vm3_set_eth3 = "sudo ifconfig " + intf_list_v3[ 3] + " " + conf_ip3_vm3 + " netmask 255.255.255.0 up" vm4_set_eth1 = "sudo ifconfig eth1 " + conf_ip_vm4 + " netmask 255.255.255.0 up" vm5_set_eth1 = "sudo ifconfig eth1 " + conf_ip_vm5 + " netmask 255.255.255.0 up" vm6_set_eth1 = "sudo ifconfig eth1 " + conf_ip_vm6 + " netmask 255.255.255.0 up" for con in con_handle: setup_vnf_vm(con) time.sleep(5) set_intf(c1, vm1_set_eth1) set_intf(c2, vm2_set_eth1) set_intf(c2, vm2_set_eth2) set_intf(c2, vm2_set_eth3) set_intf(c3, vm3_set_eth1) set_intf(c3, vm3_set_eth2) set_intf(c3, vm3_set_eth3) set_intf(c4, vm4_set_eth1) set_intf(c5, vm5_set_eth1) set_intf(c6, vm6_set_eth1) time.sleep(5) vm1_rt = [ "sudo route add -net 192.168.1.0/24 gw " + conf_ip2_vm2, "sudo route add -net 192.168.2.0/24 gw " + conf_ip2_vm2, "sudo route add -net 192.168.3.0/24 gw " + conf_ip2_vm2, "sudo route add -net 192.168.5.0/24 gw " + conf_ip2_vm2 ] vm2_rt = [ "sudo route add -net 192.168.2.0/24 gw " + conf_ip1_vm3, "sudo route add -net 192.168.3.0/24 gw " + conf_ip1_vm3, "sudo service fwbuilder restart" ] vm3_rt = [ "sudo route add -net 192.168.4.0/24 gw " + conf_ip1_vm2, "sudo route add -net 192.168.5.0/24 gw " + conf_ip1_vm2 ] vm4_rt = [ "sudo route add -net 192.168.1.0/24 gw " + conf_ip3_vm2, "sudo route add -net 192.168.2.0/24 gw " + conf_ip3_vm2, "sudo route add -net 192.168.3.0/24 gw " + conf_ip3_vm2, "sudo route add -net 192.168.4.0/24 gw " + conf_ip3_vm2 ] vm5_rt = [ "sudo route add -net 192.168.1.0/24 gw " + conf_ip2_vm3, "sudo route add -net 192.168.3.0/24 gw " + conf_ip2_vm3, "sudo route add -net 192.168.4.0/24 gw " + conf_ip2_vm3, "sudo route add -net 192.168.5.0/24 gw " + conf_ip2_vm3 ] vm6_rt = [ "sudo route add -net 192.168.1.0/24 gw " + conf_ip3_vm3, "sudo route add -net 192.168.2.0/24 gw " + conf_ip3_vm3, "sudo route add -net 192.168.4.0/24 gw " + conf_ip3_vm3, "sudo route add -net 192.168.5.0/24 gw " + conf_ip3_vm3 ] for rt in vm1_rt: route_add(c1, rt) for rt in vm2_rt: route_add(c2, rt) for rt in vm3_rt: route_add(c3, rt) for rt in vm4_rt: route_add(c4, rt) for rt in vm5_rt: route_add(c5, rt) for rt in vm6_rt: route_add(c6, rt) add_ip_fwd = [ "sudo chmod 777 /etc/sysctl.conf", "sudo sysctl -w net.ipv4.ip_forward=1", "sudo sed -i.bak s/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g /etc/sysctl.conf" ] for con1 in con_handle: for cmd in add_ip_fwd: en_ip_fwd(con1, cmd) haproxy_conf = [ "sudo chmod 777 /etc/haproxy/haproxy.cfg", "sudo chmod 777 /etc/default/haproxy", "sudo chmod 777 /etc/hosts", "sudo sed -i.bak s/ENABLED=0/ENABLED=1/g /etc/default/haproxy", "sudo sed -i.bak s/server VM1 VM1IP:PORT/server " + vm5_name + " " + conf_ip_vm5 + ":80/g /etc/haproxy/haproxy.cfg", "sudo sed -i.bak s/server VM2 VM2IP:PORT/server " + vm6_name + " " + conf_ip_vm6 + ":80/g /etc/haproxy/haproxy.cfg", "sudo sed -i.bak s/bind BINDIP:PORT/bind " + conf_ip1_vm3 + ":80/g /etc/haproxy/haproxy.cfg", "sudo echo " + conf_ip1_vm3 + " " + vm3_name + " >> /etc/hosts", "sudo echo " + conf_ip_vm5 + " " + vm5_name + " >> /etc/hosts", "sudo echo " + conf_ip_vm6 + " " + vm6_name + " >> /etc/hosts", "sudo service haproxy restart" ] s1_conf = [ "sudo chmod 777 /etc/hosts", "sudo chmod 777 /var/www/html/index.html", "sudo echo " + conf_ip1_vm3 + " " + vm3_name + " >> /etc/hosts", "sudo echo " + conf_ip_vm5 + " " + vm5_name + " >> /etc/hosts", "sudo echo " + conf_ip_vm6 + " " + vm6_name + " >> /etc/hosts", "sudo sed -i.bak s/VMNAME:VMIP/" + vm5_name + ":" + conf_ip_vm5 + "/g /var/www/html/index.html", "sudo service networking restart", "sudo service apache2 restart", "sudo ufw allow 80/tcp", "sudo ufw reload" ] s2_conf = [ "sudo chmod 777 /etc/hosts", "sudo chmod 777 /var/www/html/index.html", "sudo echo " + conf_ip1_vm3 + " " + vm3_name + " >> /etc/hosts", "sudo echo " + conf_ip_vm5 + " " + vm5_name + " >> /etc/hosts", "sudo echo " + conf_ip_vm6 + " " + vm6_name + " >> /etc/hosts", "sudo sed -i.bak s/VMNAME:VMIP/" + vm6_name + ":" + conf_ip_vm6 + "/g /var/www/html/index.html", "sudo service networking restart", "sudo service apache2 restart", "sudo ufw allow 80/tcp", "sudo ufw reload" ] for cmd in haproxy_conf: cmd_exec(c3, cmd) for cmd in s1_conf: cmd_exec(c5, cmd) for cmd in s2_conf: cmd_exec(c6, cmd) c1.disconnect() c2.disconnect() c3.disconnect() c4.disconnect() c5.disconnect() c6.disconnect()
def validate_ip_vnf_multistack(multi_stack_name): login_ip = [] time.sleep(30) ost_cmd = "openstack server list | grep %s-server1" % multi_stack_name print "Command1: %s" % ost_cmd output = exec_sys_command(ost_cmd) exact_server_name1 = output.split('|')[2].split()[0] login_ip.append( output.split('|')[4].split(',')[1].split(';')[0].split()[0]) ost_cmd = "openstack server list | grep %s-server2" % multi_stack_name print "Command2: %s" % ost_cmd output = exec_sys_command(ost_cmd) exact_server_name2 = output.split('|')[2].split()[0] login_ip.append( output.split('|')[4].split(',')[1].split(';')[0].split()[0]) # login_ip = get_multi_float_ip(multi_stack_name) ost_cmd = "openstack server list | grep %s-server3" % multi_stack_name print "Command2: %s" % ost_cmd output = exec_sys_command(ost_cmd) exact_server_name2 = output.split('|')[2].split()[0] login_ip.append( output.split('|')[4].split(',')[1].split(';')[0].split()[0]) exact_server_name = [exact_server_name1, exact_server_name2] print "Login IP: %s" % login_ip for idx, server_name in enumerate(exact_server_name): ip_float = login_ip[idx] print "IP Float: %s " % ip_float try: try: c1 = SSHConnection( IP=ip_float, username="******", ssh_key="/home/test/automation/lcm/key234demo.pem") c1.connect() except: c1 = SSHConnection( IP=ip_float, username="******", ssh_key="/home/test/automation/lcm/key234demo.pem") c1.connect() #c1 = SSHConnection(IP=ip_float, username="******", ssh_key="/home/test/automation/rmaity/test_demo/key234demo.pem") #c1 = SSHConnection(IP=ip_float, username="******", password="******") except: print "first connection failed" time.sleep(180) try: c1 = SSHConnection( IP=ip_float, username="******", ssh_key="/home/test/automation/lcm/key234demo.pem") except: c1 = SSHConnection( IP=ip_float, username="******", ssh_key="/home/test/automation/lcm/key234demo.pem") #c1 = SSHConnection(IP=ip_float, username="******", ssh_key="/home/test/automation/rmaity/test_demo/key234demo.pem") #c1 = SSHConnection(IP=ip_float, username="******", password="******") c1.connect() print "Connection Successful" c1.disconnect() return login_ip
def test_icmp_traffic(login_ip1, login_ip3): status = True c1 = SSHConnection(IP=login_ip1, username="******", ssh_key="/home/test/automation/lcm/key234demo.pem") c3 = SSHConnection(IP=login_ip3, username="******", ssh_key="/home/test/automation/lcm/key234demo.pem") #c1 = SSHConnection(IP=login_ip1, username="******", password="******") #c3 = SSHConnection(IP=login_ip3, username="******", password="******") if c1.connect() and c3.connect(): c3.execute_command("ifconfig ens3") eth1_detail = c3.conn.rc.before c3_eth1_ip = util_findhost.search_host(eth1_detail) print "c3_eth1_ip :", c3_eth1_ip cmd = "ping -c 3 " + c3_eth1_ip pat = "0% packet loss" check1 = run_check_cmd(c1, cmd, pat) print "the value of icmp check1 is:", check1 if check1: print "Verification of Ping test -- Successful" else: status = False print "Verification of Ping test -- Failed." c1.disconnect() c3.disconnect() return status
def test_http_traffic(login_ip1, login_ip3): status = True c1 = SSHConnection(IP=login_ip1, username="******", password="******") c3 = SSHConnection(IP=login_ip3, username="******", password="******") if c1.connect() and c3.connect(): c3.execute_command("ifconfig ens5") eth1_detail = c3.conn.rc.before c3_eth1_ip = util_findhost.search_host(eth1_detail) c1.execute_command("ifconfig ens5") eth1_detail = c1.conn.rc.before c1_eth1_ip = util_findhost.search_host(eth1_detail) print "c3_eth1_ip :", c3_eth1_ip cmd = "i=0; while [ $i -lt 10 ]; do wget http://" + c3_eth1_ip + ";sleep 1; $i=$i+1;done" #pat = "HTTP request sent, awaiting response... 200 OK" pat = "200 OK" cmd1 = 'sudo tcpdump -nqt -s 0 -A -i ens4 port 80 | grep "IP ' + c1_eth1_ip + '"' pat1 = c1_eth1_ip check1 = run_check_cmd(c1, cmd, pat) check2 = run_check_cmd(c3, cmd1, pat1) if check1 and check2: print "Verification of traffic test before disabling http -- Successful" else: status = False print "Verification of traffic test before disabling icmp -- Failed." c1.disconnect() c3.disconnect() return status
def test_iperf3_traffic(login_ip1, login_ip3): status = True c1 = SSHConnection(IP=login_ip1, username="******", password="******") c3 = SSHConnection(IP=login_ip3, username="******", password="******") if c1.connect() and c3.connect(): c3.execute_command("ifconfig ens5") eth1_detail = c3.conn.rc.before c3_eth1_ip = util_findhost.search_host(eth1_detail) ''' print "c3_eth1_ip :", c3_eth1_ip cmd = "ping -c 3 " + c3_eth1_ip pat = "0% packet loss" check1 = run_check_cmd(c1, cmd, pat) print "the value of icmp check1 is:", check1 if check1: print "Verification of Ping test before disabling icmp -- Successful" else: status = False print "Verification of Ping test before disabling icmp -- Failed." ''' logging.info("VM1 is client and VM3 is server") traffic_iperf3(login_ip1, c3_eth1_ip, "server") traffic_iperf3(login_ip3, c3_eth1_ip, "client") c1.disconnect() c3.disconnect() return status
def test_vm_config(login_ip1, login_ip2, login_ip3, conf_ip1_vm2, conf_ip2_vm2, vm1_name, vm2_name, vm3_name): c1 = SSHConnection(IP=login_ip1, username="******", password="******") c3 = SSHConnection(IP=login_ip3, username="******", password="******") time.sleep(30) con_handle = [c1, c3] if c1.connect() and c3.connect(): time.sleep(30) c1.execute_command("ifconfig -a | grep ^e") print "intf detail 2 ::: ", c1.conn.rc.before intf_v1 = c1.conn.rc.before intf_list_v1 = util_findhost.get_intf(intf_v1) print "intf_list_v1 ::: ", intf_list_v1 time.sleep(5) c3.execute_command("ifconfig -a | grep ^e") print "intf detail 3 ::: ", c3.conn.rc.before intf_v3 = c3.conn.rc.before intf_list_v3 = util_findhost.get_intf(intf_v3) print "intf_list_v3 ::: ", intf_list_v3 time.sleep(5) for con in con_handle: setup_vnf_vm(con) time.sleep(5) vm1_rt = ["sudo route add -net 10.12.1.0/24 gw " + conf_ip1_vm2] route_add(c1, vm1_rt) vm3_rt = ["sudo route add -net 10.11.1.0/24 gw " + conf_ip2_vm2] route_add(c3, vm3_rt) logging.info("SSH to VM2") i=1 while(i<=50): try: # VM2 = vyos_config(login_ip2) break except: i += 1 print ("ssh timeout. Try %s times untill it is connected" % (10-i)) time.sleep(10) logging.info("Configure RIPv2 in VM2") # VM2.configure(['set interfaces loopback address 1.1.1.1/32','set protocols rip network 10.11.1.0/24', # 'set protocols rip network 10.12.1.0/24', 'set protocols rip redistribute connected']) logging.info("Sleeping 30 seconds for RIP to come up") time.sleep(30) c1.disconnect() c3.disconnect()
def test_traffic_telnet_success(login_ip1, login_ip5): status = True print "Telnet traffic testing" c1 = SSHConnection(IP=login_ip1, username="******", password="******") c5 = SSHConnection(IP=login_ip5, username="******", password="******") if c1.connect() and c5.connect(): c1.execute_command("ifconfig ens4") eth1_detail = c1.conn.rc.before c1_eth1_ip = util_findhost.search_host(eth1_detail) #c1.execute_command("sudo sh -c 'echo 'telnet stream tcp nowait telnetd /usr/sbin/tcpd /usr/sbin/in.telnetd' >> /etc/inetd.conf''") c1.execute_command("sudo /etc/init.d/xinetd restart") c5.execute_command("ifconfig ens4") eth1_detail = c5.conn.rc.before c5_eth1_ip = util_findhost.search_host(eth1_detail) #c5.execute_command("sudo sh -c 'echo 'telnet stream tcp nowait telnetd /usr/sbin/tcpd /usr/sbin/in.telnetd' >> '/etc/inetd.conf''") c5.execute_command("sudo /etc/init.d/xinetd restart") cmd5 = 'sudo tcpdump -nqt -s 0 -A -i eth1 port 23 | grep "IP ' + c1_eth1_ip + '"' pat5 = "IP " + c1_eth1_ip c1.execute_command("telnet " + c5_eth1_ip) if c1.conn.rc.before.find(":") != -1: c1.execute_command("mininet") if c1.conn.rc.before.find(":") != -1: c1.execute_command("mininet") time.sleep(2) c5.execute_command(cmd5) time.sleep(5) if c5.conn.rc.before.find(pat5) != -1: print "SUCCESS" else: status = False print "FAILED" c1.disconnect() c5.disconnect() return status
def test_traffic_ftp_success(login_ip1, login_ip5): status = True print "FTP traffic testing" c1 = SSHConnection(IP=login_ip1, username="******", password="******") c5 = SSHConnection(IP=login_ip5, username="******", password="******") if c1.connect() and c5.connect(): c1.execute_command("ifconfig ens4") eth1_detail = c1.conn.rc.before c1_eth1_ip = util_findhost.search_host(eth1_detail) c5.execute_command("ifconfig ens4") eth1_detail = c5.conn.rc.before c5_eth1_ip = util_findhost.search_host(eth1_detail) print "c1_eth1_ip:", c1_eth1_ip print "c5_eth1_ip:", c5_eth1_ip cmd = "sh a.sh" # pat = "HTTP request sent, awaiting response... 200 OK" pat = "*transferred*" cmd1 = 'sudo tcpdump -nqt -s 0 -A -i eth1 port 21 | grep "IP ' + c1_eth1_ip + '"' pat1 = "IP " + c1_eth1_ip check1 = run_check_cmd(c1, cmd, pat) check2 = run_check_cmd(c5, cmd1, pat1) #check3 = run_nt_check_cmd(c6, cmd2, pat2) print "check1:", check1 print "check2:", check2 #print "check3:", check3 if check1 and check2: print "Verification of ftp traffic test completed -- Successful" else: status = False print "Verification of ftp traffic test not complete -- Failed." c1.disconnect() c5.disconnect() return status
def test_load_balance(login_ip1, login_ip3, login_ip5, login_ip6): status = True print "Load balancing on HAPROXY" c1 = SSHConnection(IP=login_ip1, username="******", password="******") c3 = SSHConnection(IP=login_ip3, username="******", password="******") c5 = SSHConnection(IP=login_ip5, username="******", password="******") c6 = SSHConnection(IP=login_ip6, username="******", password="******") if c1.connect() and c3.connect() and c5.connect() and c6.connect(): c1.execute_command("ifconfig ens4") eth1_detail = c1.conn.rc.before c1_eth1_ip = util_findhost.search_host(eth1_detail) c3.execute_command("ifconfig ens4") ens4_detail = c3.conn.rc.before c3_ens4_ip = util_findhost.search_host(ens4_detail) c3.execute_command("ifconfig ens5") ens5_detail = c3.conn.rc.before c3_ens5_ip = util_findhost.search_host(ens5_detail) c3.execute_command("ifconfig ens6") ens6_detail = c3.conn.rc.before c3_ens6_ip = util_findhost.search_host(ens6_detail) c5.execute_command("ifconfig ens4") eth1_detail = c5.conn.rc.before c5_eth1_ip = util_findhost.search_host(eth1_detail) c6.execute_command("ifconfig ens4") eth1_detail = c6.conn.rc.before c6_eth1_ip = util_findhost.search_host(eth1_detail) print "c1_eth1_ip:", c1_eth1_ip print "c3_ens4_ip:", c3_ens4_ip print "c3_ens5_ip:", c3_ens5_ip print "c3_ens6_ip:", c3_ens6_ip print "c5_eth1_ip:", c5_eth1_ip print "c6_eth1_ip:", c6_eth1_ip cmd = "i=0; while [ $i -lt 10 ]; do wget http://" + c3_ens4_ip + ";sleep 1; $i=$i+1;done" #cmd = "i=0; while [ $i -lt 10 ]; do curl http://" + c3_ens4_ip + ";sleep 1; $i=$i+1;done" pat = "HTTP request sent, awaiting response... 200 OK" #pat = "index.html*" cmd1 = 'sudo tcpdump -nqt -s 0 -A -i ens4 port 80 | grep "IP ' + c3_ens5_ip + '"' pat1 = "IP " + c3_ens5_ip + "" cmd2 = 'sudo tcpdump -nqt -s 0 -A -i ens4 port 80 | grep "IP ' + c3_ens6_ip + '"' pat2 = "IP " + c3_ens6_ip + "" check1 = run_check_cmd(c1, cmd, pat) check2 = run_check_cmd(c5, cmd1, pat1) check3 = run_check_cmd(c6, cmd2, pat2) print "pat:", pat print "pat1:", pat1 print "pat2:", pat2 print "check1:", check1 print "check2:", check2 print "check3:", check3 if check1 and check2 and check3: #if check2 and check3: print "Verification of load balancing traffic test completed -- Successful" else: status = False print "Verification of load balancing traffic test not complete -- Failed." c1.disconnect() c3.disconnect() c5.disconnect() c6.disconnect() return status
def test_icmp_traffic(login_ip1, login_ip3, usrname, key, password): print "this is usename", usrname status = True print "test_icmp_traffic key: ", key try: c1 = SSHConnection(IP=login_ip1, username=usrname, password=password) c3 = SSHConnection(IP=login_ip3, username=usrname, password=password) #c1 = SSHConnection(IP=login_ip1, username=usrname, ssh_key=key) #c3 = SSHConnection(IP=login_ip3, username=usrname, ssh_key=key) except: c1 = SSHConnection(IP=login_ip1, username=usrname, password=password) c3 = SSHConnection(IP=login_ip3, username=usrname, password=password) if c1.connect() and c3.connect(): c3.execute_command("ifconfig ens3") eth1_detail = c3.conn.rc.before c3_eth1_ip = util_findhost.search_host(eth1_detail) print "c3_eth1_ip :", c3_eth1_ip cmd = "ping -c 3 " + c3_eth1_ip pat = "0% packet loss" check1 = run_check_cmd(c1, cmd, pat) print "the value of icmp check1 is:", check1 if check1: print "Verification of Ping test -- Successful" else: status = False print "Verification of Ping test -- Failed." c1.disconnect() c3.disconnect() return status