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 | |
| 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')
| -rw-r--r-- | tests/accel-pppd/ipoe/conftest.py | 46 | ||||
| -rw-r--r-- | tests/accel-pppd/ipoe/dhcpv4/test_ipoe_shared_session_wo_auth.py | 70 | ||||
| -rw-r--r-- | tests/accel-pppd/ipoe/test_ipoe_driver.py | 8 | ||||
| -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 | ||||
| -rw-r--r-- | tests/accel-pppd/test_basic.py | 83 | ||||
| -rw-r--r-- | tests/accel-pppd/test_vlan_mon_driver.py | 7 |
10 files changed, 520 insertions, 0 deletions
diff --git a/tests/accel-pppd/ipoe/conftest.py b/tests/accel-pppd/ipoe/conftest.py new file mode 100644 index 00000000..3db8dd60 --- /dev/null +++ b/tests/accel-pppd/ipoe/conftest.py @@ -0,0 +1,46 @@ +import pytest +from common import dhclient_process +import tempfile, os + +# dhclient executable file name +@pytest.fixture() +def dhclient(pytestconfig): + return pytestconfig.getoption("dhclient") + + +# pppd configuration as command line args (might be redefined by specific test) +# "-d" (do not daemonize) must be a part of the args +@pytest.fixture() +def dhclient_args(): + # test setup: + #lease_file = tempfile.NamedTemporaryFile(delete=True) + #lease_file_name = lease_file.name + #lease_file.close() # just create, close and delete + + # test execution: + yield ["-d", "-4", "--no-pid", "-lf", "/dev/null"] + + # test teardown: + #os.unlink(lease_file_name) + + +# setup and teardown for tests that required running dhclient (after accel-pppd) +@pytest.fixture() +def dhclient_instance(accel_pppd_instance, veth_pair_netns, dhclient, dhclient_args): + # test setup: + print("dhclient_instance: accel_pppd_instance = " + str(accel_pppd_instance)) + is_started, dhclient_thread, dhclient_control = dhclient_process.start( + veth_pair_netns["netns"], + dhclient, + dhclient_args, + ) + + # test execution: + yield { + "is_started": is_started, + "dhclient_thread": dhclient_thread, + "dhclient_control": dhclient_control, + } + + # test teardown: + dhclient_process.end(dhclient_thread, dhclient_control) diff --git a/tests/accel-pppd/ipoe/dhcpv4/test_ipoe_shared_session_wo_auth.py b/tests/accel-pppd/ipoe/dhcpv4/test_ipoe_shared_session_wo_auth.py new file mode 100644 index 00000000..104e4e9b --- /dev/null +++ b/tests/accel-pppd/ipoe/dhcpv4/test_ipoe_shared_session_wo_auth.py @@ -0,0 +1,70 @@ +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 + ipoe + ippool + + [ip-pool] + gw-ip-address=192.0.2.1 + 192.0.2.2-255 + + [cli] + tcp=127.0.0.1:2001 + + [log] + log-debug=/dev/stdout + level=5 + + [ipoe] + noauth=1 + shared=1 + gw-ip-address=192.0.2.1/24 + interface=""" + + veth_pair_netns["veth_a"] + ) + + +# test dhcpv4 shared session without auth check +@pytest.mark.dependency(depends=["ipoe_driver_loaded"], scope = 'session') +@pytest.mark.ipoe_driver +def test_ipoe_shared_session_wo_auth(dhclient_instance, accel_cmd, veth_pair_netns): + + # test that dhclient (with accel-pppd) started successfully + assert dhclient_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 called-sid,ip,state", + ] + ) + assert exit == 0 # accel-cmd fails + # print(out) + if veth_pair_netns["veth_a"] 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_ipoe_shared_session_wo_auth: last accel-cmd out: " + out) + + # test that session is started + assert is_started == True diff --git a/tests/accel-pppd/ipoe/test_ipoe_driver.py b/tests/accel-pppd/ipoe/test_ipoe_driver.py new file mode 100644 index 00000000..d21e9ba7 --- /dev/null +++ b/tests/accel-pppd/ipoe/test_ipoe_driver.py @@ -0,0 +1,8 @@ +import pytest +import os + +# test that ipoe kernel module is loaded +@pytest.mark.dependency(name = 'ipoe_driver_loaded', scope = 'session') +@pytest.mark.ipoe_driver +def test_ipoe_kernel_module_loaded(): + assert os.path.isdir("/sys/module/ipoe")
\ No newline at end of file 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 diff --git a/tests/accel-pppd/test_basic.py b/tests/accel-pppd/test_basic.py new file mode 100644 index 00000000..2b2c6f71 --- /dev/null +++ b/tests/accel-pppd/test_basic.py @@ -0,0 +1,83 @@ +import pytest +from common import process + + +def test_accel_pppd_version(accel_pppd): + (exit, out, err) = process.run([accel_pppd, "--version"]) + + # test that accel-pppd --version exits with code 0, prints + # nothing to stdout and prints to stdout + assert exit == 0 and err == "" and "accel-ppp " in out and len(out.split(" ")) == 2 + + +@pytest.fixture() +def accel_pppd_config(): + return """ + [modules] + log_file + log_syslog + log_tcp + #log_pgsql + + pptp + l2tp + sstp + pppoe + ipoe + + auth_mschap_v2 + auth_mschap_v1 + auth_chap_md5 + auth_pap + + radius + chap-secrets + + ippool + + pppd_compat + shaper + #net-snmp + logwtmp + connlimit + + ipv6_nd + ipv6_dhcp + ipv6pool + + [core] + log-error=/dev/stderr + + [log] + log-debug=/dev/stdout + log-file=/dev/stdout + log-emerg=/dev/stderr + level=5 + + [cli] + tcp=127.0.0.1:2001 + + [pppoe] + + [client-ip-range] + 10.0.0.0/8 + + [radius] + """ + + +# load all modules and check that accel-pppd replies to 'show stat' command +def test_load_all_modules(accel_pppd_instance, accel_cmd): + + # test that accel-pppd started successfully + assert accel_pppd_instance + + (exit_sh_stat, out_sh_stat, err_sh_stat) = process.run([accel_cmd, "show stat"]) + + # test that 'show stat' has no errors and contains 'uptime' + assert ( + exit_sh_stat == 0 + and len(out_sh_stat) > 1 + and err_sh_stat == "" + and "uptime" in out_sh_stat + ) diff --git a/tests/accel-pppd/test_vlan_mon_driver.py b/tests/accel-pppd/test_vlan_mon_driver.py new file mode 100644 index 00000000..3e937f83 --- /dev/null +++ b/tests/accel-pppd/test_vlan_mon_driver.py @@ -0,0 +1,7 @@ +import pytest +import os + +# test that vlan_mon kernel module is loaded +@pytest.mark.dependency(name = 'vlan_mon_driver_loaded', scope = 'session') +def test_vlan_mon_kernel_module_loaded(): + assert os.path.isdir("/sys/module/vlan_mon")
\ No newline at end of file |
