def flow_01(): with fwtests.TestFwagent() as agent: (ok, _) = agent.cli('-f %s' % cli_add_config_file) assert ok (ok, _) = agent.cli('-f %s' % cli_start_router_file) assert ok f = open(ospfd_conf_filename, 'r') ospfd_content_old = f.read() f.close() (ok, _) = agent.cli('-f %s' % cli_stop_router_file) assert ok (ok, _) = agent.cli('-f %s' % cli_start_router_file) assert ok (ok, _) = agent.cli('-f %s' % cli_stop_router_file) assert ok f = open(ospfd_conf_filename, 'r') ospfd_content_new = f.read() f.close() assert ospfd_content_old == ospfd_content_new, \ "%s BEFORE test:%s\n\n%s AFTER test:%s\n" % \ (ospfd_conf_filename, ospfd_content_old, ospfd_conf_filename, ospfd_content_new)
def test(): tests_path = __file__.replace('.py', '') test_cases = sorted(glob.glob('%s/*.cli' % tests_path)) for t in test_cases: with fwtests.TestFwagent() as agent: print(" " + os.path.basename(t)) # Load router configuration with spoiled lists agent.cli('--ignore_errors -f %s' % t) # Ensure that spoiled lists were reverted completely configured = fwtests.wait_vpp_to_be_configured([('interfaces', 0), ('tunnels', 0)], timeout=30) assert configured # For route test only: ensure that route table has no routes # that *_list_routes.cli tried to add from list, but failed # and reverted them. if re.search('list_routes', os.path.basename(t)): routes = subprocess.check_output("ip route", shell=True) assert routes.find( '6.6.6.') == -1, "route for 6.6.6.X was not reverted" assert routes.find( '9.9.9.') == -1, "route for 9.9.9.X was not reverted" agent.cli('-f %s' % cli_stop_router_file)
def test(): with fwtests.TestFwagent() as agent: (ok, _) = agent.cli('-f %s' % cli_fail_router_file) assert not ok # Ensure that the failure state was recorded into file state_file = "/etc/flexiwan/agent/.router.state" try: state_file_size_str = subprocess.check_output( "sudo stat -c %%s %s" % state_file, shell=True) except subprocess.CalledProcessError: assert False, "%s file not found - failure was not recorded" % state_file state_file_size = int(state_file_size_str.rstrip()) assert state_file_size > 0, "%s file is empty - failure description was not recorded" % state_file # Ensure that vpp was stopped as a result of failure vpp_pid = fwtests.vpp_pid() assert vpp_pid is None, "vpp runs (pid=%s)! It should be stopped on failure" % vpp_pid # Ensure that configuration requests are not rejected when router is in failed state. # Note configuration requests are not blocked to enable management # to fix configuration issue that caused failure (ok, _) = agent.cli('-f %s' % cli_add_interface_file) assert ok, "'add-interface' request was rejected, when router is in failure state" # Reset the failure state (ok, _) = agent.cli('-f %s' % cli_reset_router_file) assert ok, "'reset-router' request failed" # Ensure that 'reset-router' deleted failure state record file and emptied request database file try: state_file_size_str = subprocess.check_output( "sudo stat -c %%s %s" % state_file, shell=True) assert False, "failure state record file %s was not deleted by 'reset-router' request" % state_file except subprocess.CalledProcessError: pass config = agent.show("--router configuration") assert config == '', "request database was not emptired by 'reset-router' request:\n%s" % config # As request database was emptied, add interface again to check normal activity (ok, _) = agent.cli('-f %s' % cli_add_interface_file) assert ok # Start router and ensure that configuration was applied successfully (ok, _) = agent.cli('-f %s' % cli_start_router_file) assert ok, "'start-router' request failed" configured = fwtests.wait_vpp_to_be_configured([('interfaces', 1), ('tunnels', 0)], timeout=30) assert configured # Stop router (ok, _) = agent.cli('-f %s' % cli_stop_router_file) assert ok
def test(): with fwtests.TestFwagent() as agent: (ok, _) = agent.cli('-f %s' % cli_fail_router_file) assert not ok # Ensure that the failure state was recorded into file state_file = "/etc/flexiwan/agent/.router.state" try: state_file_size_str = subprocess.check_output( "sudo stat -c %%s %s" % state_file, shell=True) except subprocess.CalledProcessError: assert False, "%s file not found - failure was not recorded" % state_file state_file_size = int(state_file_size_str.rstrip()) assert state_file_size > 0, "%s file is empty - failure description was not recorded" % state_file # Ensure that vpp was stopped as a result of failure vpp_pid = fwtests.vpp_pid() assert vpp_pid is None, "vpp runs (pid=%s)! It should be stopped on failure" % vpp_pid # Ensure that configuration requests are not rejected when router is in failed state. # Note configuration requests are not blocked to enable management # to fix configuration issue that caused failure (ok, _) = agent.cli('-f %s' % cli_add_interface_file) assert ok, "'add-interface' request was rejected, when router is in failure state" # Fix configuration by removal bad interface (ok, _) = agent.cli('-f %s' % cli_remove_interface_file) assert ok, "'remove-interface' request was rejected, when router is in failure state" # Start router and ensure that configuration was applied successfully (ok, _) = agent.cli('-f %s' % cli_start_router_file) assert ok, "'start-router' request failed" # The applyied configuration should include two interfaces: # - 0000:00:09.0 loaded from fail_router.cli # - 0000:00:08.0 loaded from add-interface.cli configured = fwtests.wait_vpp_to_be_configured([('interfaces', 2), ('tunnels', 0)], timeout=30) assert configured, "failed to configure interfaces in vpp" # Ensure that failure state was removed due to successfull start try: state_file = "/etc/flexiwan/agent/.router.state" state_file_size_str = subprocess.check_output( "sudo stat -c %%s %s" % state_file, shell=True) assert False, "failure state record file %s was not deleted by successful 'start-router' request" % state_file except subprocess.CalledProcessError: pass # Stop router (ok, _) = agent.cli('-f %s' % cli_stop_router_file) assert ok
def flow_02(): with fwtests.TestFwagent() as agent: (ok, _) = agent.cli('-f %s' % cli_add_config_file) assert ok (ok, _) = agent.cli('-f %s' % cli_start_router_file) assert ok (ok, _) = agent.cli('-f %s' % cli_remove_config_file) assert ok (ok, _) = agent.cli('-f %s' % cli_stop_router_file) assert ok (ok, _) = agent.cli('-f %s' % cli_start_router_file) assert ok assert fwtests.vpp_is_configured([('interfaces', 0), ('tunnels', 0)])
def flow_01(): with fwtests.TestFwagent() as agent: (ok, _) = agent.cli('-f %s' % cli_add_config_file) assert ok (ok, _) = agent.cli('-f %s' % cli_start_router_file) assert ok assert fwtests.vpp_is_configured([('interfaces', 4), ('tunnels', 1)]) (ok, _) = agent.cli('-f %s' % cli_stop_router_file) assert ok assert not fwtests.vpp_does_run() # Ensure vpp doesn't run (ok, _) = agent.cli('-f %s' % cli_start_router_file) assert ok assert fwtests.vpp_is_configured([('interfaces', 4), ('tunnels', 1)]) agent.cli('-f %s' % cli_stop_router_file)
def test(): with fwtests.TestFwagent() as agent: fwagent_run_time = 60 (ok, _) = agent.cli('-f %s' % cli_start_router_add_tunnel_file, bg_time=fwagent_run_time) assert ok started = fwtests.wait_vpp_to_start(timeout=30) assert started configured = fwtests.wait_vpp_to_be_configured([('interfaces', 6),('tunnels', 2)], timeout=30) assert configured # Kill vpp and give a watchdog chance to restart it vpp_pid_before = fwtests.vpp_pid() assert vpp_pid_before os.system("sudo kill -9 %s" % vpp_pid_before) time.sleep(1) # Ensure that watchdog detected vpp crash and restarted it started = fwtests.wait_vpp_to_start(timeout=20) assert started vpp_pid_after = fwtests.vpp_pid() assert vpp_pid_after != vpp_pid_before, "pid before kill %s, pid after kill %s" % (vpp_pid_before, vpp_pid_after) # Ensure that configuration was restored configured = fwtests.wait_vpp_to_be_configured([('interfaces', 6),('tunnels', 2)], timeout=30) assert configured # Clean up - wait until background fwagent exits exited = fwtests.wait_fwagent_exit(timeout=fwagent_run_time) assert exited # Stop router (ok, _) = agent.cli('-f %s' % cli_stop_router_file) assert ok