diff options
| author | xebd <xeb@mail.ru> | 2022-09-12 10:56:47 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-12 10:56:47 +0300 |
| commit | 28fe4de9441aa9d0c42c010e8eef5b1a19122c9d (patch) | |
| tree | ecefcafbeb9c9610ed3cf8c30a238b9168bba3bb /tests/accel-pppd | |
| parent | 25c72614bf8106b0e4f71e2bce70514b03858463 (diff) | |
| parent | 127b1de95923fccdfdc892c20f931d364e099f4b (diff) | |
| download | accel-ppp-28fe4de9441aa9d0c42c010e8eef5b1a19122c9d.tar.gz accel-ppp-28fe4de9441aa9d0c42c010e8eef5b1a19122c9d.zip | |
Merge pull request #61 from svlobanov/tests2
add tests and ci workflow for running tests
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 | 8 |
10 files changed, 521 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..a230c7c8 --- /dev/null +++ b/tests/accel-pppd/test_vlan_mon_driver.py @@ -0,0 +1,8 @@ +import pytest +import os + +# test that vlan_mon kernel module is loaded +@pytest.mark.dependency(name = 'vlan_mon_driver_loaded', scope = 'session') +@pytest.mark.vlan_mon_driver +def test_vlan_mon_kernel_module_loaded(): + assert os.path.isdir("/sys/module/vlan_mon")
\ No newline at end of file |
