diff --git a/runtest/emv_network_pretest.py b/runtest/emv_network_pretest.py index c379dbcd86215a33f90e34c00b4c89bd9d980906..e14233419c32032ac81a14964a8b17bc1ff5f082 100755 --- a/runtest/emv_network_pretest.py +++ b/runtest/emv_network_pretest.py @@ -7,6 +7,7 @@ import subprocess import time import curses +import os # Window dimensions x_max = 70 @@ -59,8 +60,8 @@ def msg_write(action,keys,stdscr): stdscr.addstr(action, curses.color_pair(1)) stdscr.move(19,2) stdscr.addstr(keys, curses.color_pair(1)) - stdscr.refresh() stdscr.move(y_max+2,0) + stdscr.refresh() def msg_clear(stdscr): for x in range(1,70): stdscr.move(18,x) @@ -68,8 +69,8 @@ def msg_clear(stdscr): for x in range(1,70): stdscr.move(19,x) stdscr.addstr(" ") - stdscr.refresh() stdscr.move(y_max+2,0) + stdscr.refresh() #---------------------------------------------------------------------------# # Evaluate test output @@ -109,6 +110,14 @@ def bash_cmd(inputStr): value = subprocess.call(callStr, shell=True) return value +#---------------------------------------------------------------------------# +# Check and delete default ip route +#---------------------------------------------------------------------------# +def del_default_route(): + route_str = subprocess.check_output('route') + if route_str.find('default') != -1: + bash_cmd("route del default") + #---------------------------------------------------------------------------# # Network Ethernet 0 #---------------------------------------------------------------------------# @@ -120,7 +129,8 @@ def eth0(stdscr): msg_write("Remove the cable from ethernet port 0","Press 'c' to continue, 'q' to quit",stdscr) user_input(stdscr) msg_clear(stdscr) - + + bash_cmd("echo 'Ethernet 0 unplugged (Test should fail):'") out = subprocess.call("/opt/ltp/testcases/bin/iptest -q -g 192.168.1.100 -n 1 -w 50 &>>/opt/ltp/results/network_test.log", shell=True) ev_output(out,0,current_line,stdscr) @@ -132,6 +142,7 @@ def eth0(stdscr): time.sleep(8) msg_clear(stdscr) + bash_cmd("echo 'Ethernet 0 plugged (Test should pass):'") out = subprocess.call("/opt/ltp/testcases/bin/iptest -q -g 192.168.1.100 -n 1 -w 50 &>>/opt/ltp/results/network_test.log", shell=True) ev_output(out,1,current_line,stdscr) @@ -147,6 +158,8 @@ def eth1(stdscr): user_input(stdscr) msg_clear(stdscr) + del_default_route() + bash_cmd("echo 'Ethernet 1 unplugged (Test should fail):'") out = subprocess.call("/opt/ltp/testcases/bin/iptest -q -g 192.168.2.100 -n 1 -w 50 &>>/opt/ltp/results/network_test.log", shell=True) ev_output(out,0,current_line,stdscr) @@ -158,6 +171,8 @@ def eth1(stdscr): time.sleep(8) msg_clear(stdscr) + del_default_route() + bash_cmd("echo 'Ethernet 1 plugged (Test should pass):'") out = subprocess.call("/opt/ltp/testcases/bin/iptest -q -g 192.168.2.100 -n 1 -w 50 &>>/opt/ltp/results/network_test.log", shell=True) ev_output(out,1,current_line,stdscr) @@ -169,21 +184,25 @@ def wlan(stdscr): stdscr.addstr(current_line,2,"WLAN:") # Unplugged test - msg_write("Remove ethernet cable from the router","Press 'c' to continue, 'q' to quit",stdscr) + msg_write("Remove the WLAN stick","Press 'c' to continue, 'q' to quit",stdscr) user_input(stdscr) msg_clear(stdscr) - + + del_default_route() + bash_cmd("echo 'WLAN unplugged (Test should fail):'") out = subprocess.call("/opt/ltp/testcases/bin/iptest -q -g 192.168.3.100 -n 1 -w 1000 &>>/opt/ltp/results/network_test.log", shell=True) ev_output(out,0,current_line,stdscr) # Plugged test - msg_write ("Reconnect the cable","Press 'c' to continue, 'q' to quit",stdscr) + msg_write ("Reconnect the WLAN stick","Press 'c' to continue, 'q' to quit",stdscr) user_input(stdscr) msg_clear(stdscr) msg_write("Wait for the network to come up","",stdscr) time.sleep(10) msg_clear(stdscr) - + + del_default_route() + bash_cmd("echo 'WLAN plugged (Test should pass):'") out = subprocess.call("/opt/ltp/testcases/bin/iptest -q -g 192.168.3.100 -n 1 -w 1000 &>>/opt/ltp/results/network_test.log", shell=True) ev_output(out,1,current_line,stdscr) @@ -196,7 +215,9 @@ def main(stdscr): msg_write("Ensure the network interfaces are configured correctly. For this","you can use the emv_network_config.sh file. Press 'c' to continue",stdscr) user_input(stdscr) msg_clear(stdscr) - # Resest log + # Create and reset log + if not os.path.exists("/opt/ltp/results"): + os.makedirs("/opt/ltp/results") subprocess.call("date &>/opt/ltp/results/network_test.log", shell=True) # Ethernet 0 test eth0(stdscr)