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_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") # ip_eth0 = None 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] 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/rmaity/test_demo/key234demo.pem") # c1 = SSHConnection(IP=ip_float, username="******", password="******") try: c1.connect() except: print "first connection failed" time.sleep(180) 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() c1.execute_command("sudo ifconfig eth0") 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_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_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_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
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_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_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