diff options
author | Sergey V. Lobanov <sergey@lobanov.in> | 2022-09-04 18:49:42 +0300 |
---|---|---|
committer | Sergey V. Lobanov <sergey@lobanov.in> | 2022-09-04 19:06:49 +0300 |
commit | c92ff6266b18a9655edef231391739f0479dfb3a (patch) | |
tree | 0196077cbd54c9607ba918a42cac567411197663 /tests/accel-pppd/pppoe | |
parent | 38d96b8e20608fb743d543fe3f08ad4b9d1dcd66 (diff) | |
download | accel-ppp-c92ff6266b18a9655edef231391739f0479dfb3a.tar.gz accel-ppp-c92ff6266b18a9655edef231391739f0479dfb3a.zip |
add tests and ci workflow for running tests
This commit adds tests (using python3 pytest framework):
1. Test basic accel-cmd commands (show version, show stat, etc)
2. Test ipoe shared session up (dhcpv4) without radius
3. Test pppoe discovery (without PADO delay)
4. Test pppoe discovery (without PADO delay)
5. Test pppoe session up (ipv4) without radius
6. Test vlan creation using vlan-mon (pppoe)
These tests require external utils. Please read tests/README.md how to setup
environment, how to run the tests and how to generate coverage report
Also, run-tests.yml contains step-by-step instruction how to run the tests
Signed-off-by: Sergey V. Lobanov <sergey@lobanov.in>
Diffstat (limited to 'tests/accel-pppd/pppoe')
-rw-r--r-- | tests/accel-pppd/pppoe/conftest.py | 42 | ||||
-rw-r--r-- | tests/accel-pppd/pppoe/test_pppoe_disc.py | 42 | ||||
-rw-r--r-- | tests/accel-pppd/pppoe/test_pppoe_pado_delay.py | 83 | ||||
-rw-r--r-- | tests/accel-pppd/pppoe/test_pppoe_session_wo_auth.py | 90 | ||||
-rw-r--r-- | tests/accel-pppd/pppoe/test_pppoe_vlan_mon.py | 49 |
5 files changed, 306 insertions, 0 deletions
diff --git a/tests/accel-pppd/pppoe/conftest.py b/tests/accel-pppd/pppoe/conftest.py new file mode 100644 index 00000000..8ebaaed3 --- /dev/null +++ b/tests/accel-pppd/pppoe/conftest.py @@ -0,0 +1,42 @@ +import pytest +from common import pppd_process + +# pppd executable file name +@pytest.fixture() +def pppd(pytestconfig): + return pytestconfig.getoption("pppd") + + +# pppd configuration as string (should be redefined by specific test) +# all configs should contain "nodetach" option +@pytest.fixture() +def pppd_config(): + return "" + + +# pppd configuration as command line args +@pytest.fixture() +def pppd_args(pppd_config): + return pppd_config.split() + + +# setup and teardown for tests that required running pppd (after accel-pppd) +@pytest.fixture() +def pppd_instance(accel_pppd_instance, veth_pair_netns, pppd, pppd_args): + # test setup: + print("pppd_instance: accel_pppd_instance = " + str(accel_pppd_instance)) + is_started, pppd_thread, pppd_control = pppd_process.start( + veth_pair_netns["netns"], + pppd, + pppd_args, + ) + + # test execution: + yield { + "is_started": is_started, + "pppd_thread": pppd_thread, + "pppd_control": pppd_control, + } + + # test teardown: + pppd_process.end(pppd_thread, pppd_control) diff --git a/tests/accel-pppd/pppoe/test_pppoe_disc.py b/tests/accel-pppd/pppoe/test_pppoe_disc.py new file mode 100644 index 00000000..eb069c42 --- /dev/null +++ b/tests/accel-pppd/pppoe/test_pppoe_disc.py @@ -0,0 +1,42 @@ +import pytest +from common import netns + + +@pytest.fixture() +def accel_pppd_config(veth_pair_netns): + print(veth_pair_netns) + return ( + """ + [modules] + pppoe + + [log] + log-debug=/dev/stdout + level=5 + + [cli] + tcp=127.0.0.1:2001 + + [pppoe] + ac-name=test-accel + interface=""" + + veth_pair_netns["veth_a"] + ) + + +# test pppoe discovery +def test_pppoe_discovery(accel_pppd_instance, veth_pair_netns): + + # test that accel-pppd started successfully + assert accel_pppd_instance + + (exit_sh_stat, out_sh_stat, err_sh_stat) = netns.exec( + veth_pair_netns["netns"], ["pppoe-discovery", "-I", veth_pair_netns["veth_b"]] + ) + + # test that ac-name=test-accel is in pppoe-discovery reply (PADO) + assert ( + exit_sh_stat == 0 + and err_sh_stat == "" + and "test-accel" in out_sh_stat + ) diff --git a/tests/accel-pppd/pppoe/test_pppoe_pado_delay.py b/tests/accel-pppd/pppoe/test_pppoe_pado_delay.py new file mode 100644 index 00000000..96c73bf8 --- /dev/null +++ b/tests/accel-pppd/pppoe/test_pppoe_pado_delay.py @@ -0,0 +1,83 @@ +import pytest +from common import netns, process +import time + +# This test module requires pppoe-discovery with -a and -t options +# Ubuntu 20.04 has not this option, Ubuntu 22.04 is ok + +# Check that pppoe-discover supports -a and -t (to disable some tests required these features) +def support_pppoe_discovery_a_t(): + try: + (_, out, err) = process.run(["pppoe-discovery", "-h"]) + except: # can't run pppoe-discovery + return False + + if "-t " in out + err and "-a " in out + err: # found -t and -a options + return True + else: + return False + + +# skip tests in this module if pppoe-discovery doesn't support '-a' and '-t' options +pytestmark = pytest.mark.skipif( + not support_pppoe_discovery_a_t(), reason="bad pppoe-discovery" +) + + +@pytest.fixture() +def accel_pppd_config(veth_pair_netns): + print(veth_pair_netns) + return ( + """ + [modules] + pppoe + + [log] + log-debug=/dev/stdout + level=5 + + [cli] + tcp=127.0.0.1:2001 + + [pppoe] + ac-name=test-accel + pado-delay=1500 + interface=""" + + veth_pair_netns["veth_a"] + ) + + +# test pado delay. accel-pppd is configured for 1.5s delay +# first step: test that pppoe-discovery fails if wait timeout=1<1.5 +# second step: test that pppoe-discovery gets pado if wait timeout=2>1.5 +def test_pppoe_pado_delay(accel_pppd_instance, veth_pair_netns): + + # test that accel-pppd started successfully + assert accel_pppd_instance + + # send two times with wait timeout = 1 + (exit_sh_stat, out_sh_stat, err_sh_stat) = netns.exec( + veth_pair_netns["netns"], + ["pppoe-discovery", "-a1", "-t1", "-I", veth_pair_netns["veth_b"]], + ) + time.sleep(1) # sleep for one second (because accel-pppd replies in this timeslot) + (exit_sh_stat2, out_sh_stat2, err_sh_stat2) = netns.exec( + veth_pair_netns["netns"], + ["pppoe-discovery", "-a1", "-t1", "-I", veth_pair_netns["veth_b"]], + ) + time.sleep(1) # sleep for one second (because accel-pppd replies in this timeslot) + + # print(out_sh_stat + err_sh_stat) + # print(out_sh_stat2 + err_sh_stat2) + + # test that pppoe-discovery (wait timeout 1s) fails (as expected) (two times) + assert exit_sh_stat != 0 and "test-accel" not in out_sh_stat + assert exit_sh_stat2 != 0 and "test-accel" not in out_sh_stat2 + + (exit_sh_stat3, out_sh_stat3, err_sh_stat3) = netns.exec( + veth_pair_netns["netns"], + ["pppoe-discovery", "-a1", "-t2", "-I", veth_pair_netns["veth_b"]], + ) + + # test that pppoe-discovery (wait timeout 2s) gets pado + assert exit_sh_stat3 == 0 and "test-accel" in out_sh_stat3 diff --git a/tests/accel-pppd/pppoe/test_pppoe_session_wo_auth.py b/tests/accel-pppd/pppoe/test_pppoe_session_wo_auth.py new file mode 100644 index 00000000..0c8aa2c0 --- /dev/null +++ b/tests/accel-pppd/pppoe/test_pppoe_session_wo_auth.py @@ -0,0 +1,90 @@ +import pytest +from common import process +import time + + +@pytest.fixture() +def accel_pppd_config(veth_pair_netns): + print("accel_pppd_config veth_pair_netns: " + str(veth_pair_netns)) + return ( + """ + [modules] + pppoe + auth_pap + ippool + + [log] + log-debug=/dev/stdout + level=5 + + [auth] + any-login=1 + + [ip-pool] + gw-ip-address=192.0.2.1 + 192.0.2.2-255 + + [cli] + tcp=127.0.0.1:2001 + + [pppoe] + interface=""" + + veth_pair_netns["veth_a"] + ) + + +@pytest.fixture() +def pppd_config(veth_pair_netns): + print("pppd_config veth_pair_netns: " + str(veth_pair_netns)) + return ( + """ + nodetach + noipdefault + defaultroute + connect /bin/true + noauth + persist + mtu 1492 + noaccomp + default-asyncmap + plugin rp-pppoe.so + user loginAB + password pass123 + nic-""" + + veth_pair_netns["veth_b"] + ) + + +# test pppoe session without auth check +def test_pppoe_session_wo_auth(pppd_instance, accel_cmd): + + # test that pppd (with accel-pppd) started successfully + assert pppd_instance["is_started"] + + # wait until session is started + max_wait_time = 10.0 + sleep_time = 0.0 + is_started = False # is session started + while sleep_time < max_wait_time: + (exit, out, err) = process.run( + [ + accel_cmd, + "show sessions match username loginAB username,ip,state", + ] + ) + assert exit == 0 # accel-cmd fails + # print(out) + if "loginAB" in out and "192.0.2." in out and "active" in out: + # session is found + print( + "test_pppoe_session_wo_auth: session found in (sec): " + str(sleep_time) + ) + is_started = True + break + time.sleep(0.1) + sleep_time += 0.1 + + print("test_pppoe_session_wo_auth: last accel-cmd out: " + out) + + # test that session is started + assert is_started == True diff --git a/tests/accel-pppd/pppoe/test_pppoe_vlan_mon.py b/tests/accel-pppd/pppoe/test_pppoe_vlan_mon.py new file mode 100644 index 00000000..670abc33 --- /dev/null +++ b/tests/accel-pppd/pppoe/test_pppoe_vlan_mon.py @@ -0,0 +1,49 @@ +import pytest +from common import netns + + +# create vlan 15 only in netns (invisble to accel-pppd) +@pytest.fixture() +def veth_pair_vlans_config(): + return {"vlans_a": [], "vlans_b": [15]} + + +@pytest.fixture() +def accel_pppd_config(veth_pair_netns): + print(veth_pair_netns) + return """ + [modules] + pppoe + + [log] + log-debug=/dev/stdout + level=5 + + [cli] + tcp=127.0.0.1:2001 + + [pppoe] + ac-name=test-accel + vlan-mon=%s,10-20 + interface=re:%s.\\d+ + """ % ( + veth_pair_netns["veth_a"], + veth_pair_netns["veth_a"], + ) + + +# test pppoe discovery in vlan created by vlan_mon +@pytest.mark.dependency(depends=["vlan_mon_driver_loaded"], scope="session") +@pytest.mark.vlan_mon_driver +def test_pppoe_vlan_mon(accel_pppd_instance, veth_pair_netns): + + # test that accel-pppd started successfully + assert accel_pppd_instance + + (exit_sh_stat, out_sh_stat, err_sh_stat) = netns.exec( + veth_pair_netns["netns"], + ["pppoe-discovery", "-I", veth_pair_netns["veth_b"] + ".15"], + ) + + # test that ac-name=test-accel is in pppoe-discovery reply (PADO) + assert exit_sh_stat == 0 and err_sh_stat == "" and "test-accel" in out_sh_stat |