diff options
| author | Denys Fedoryshchenko <denys.f@collabora.com> | 2026-08-08 18:22:47 +0300 |
|---|---|---|
| committer | Denys Fedoryshchenko <denys.f@collabora.com> | 2026-08-08 18:29:35 +0300 |
| commit | d22f698e88a05332cee4b8dac2e7085c8b83b0ed (patch) | |
| tree | 1eb98126b9c8f0b435ff97f6a4649cbf8533a478 /tests/common/ipoe_iface.py | |
| parent | 4969b65c3f55c739a0c9178086f42ba3de906119 (diff) | |
| download | accel-ppp-d22f698e88a05332cee4b8dac2e7085c8b83b0ed.tar.gz accel-ppp-d22f698e88a05332cee4b8dac2e7085c8b83b0ed.zip | |
tests: cover the removal of stale ipoe session interfaces
Three tests around the interfaces the ipoe module creates per session:
- kill accel-pppd with SIGKILL while a dhcp session is up, start it
again and check that the interfaces left behind by the killed
instance are gone,
- remove a session interface with 'ip link del',
- check that 'ip link add ... type ipoe' is refused, since a device
made through rtnetlink would have none of the private state that
IPOE_CMD_CREATE sets up.
They carry the ipoe_driver marker and sit next to the existing ipoe
tests, so the workflows run them in the steps that follow the insmod of
the module. No workflow change is needed.
The [modules] section has to list connlimit and radius before ipoe:
libipoe.so refers to symbols of both, and with a strict dynamic linker
loading it on its own fails with a relocation error instead of a missing
feature. The tests assert that accel-pppd came up, so that this kind of
misconfiguration is not reported as an unrelated cli connection failure.
Restarting accel-pppd needs no explicit synchronisation:
triton_load_modules() runs every DEFINE_INIT() before triton_run()
starts the threads that serve the cli, so by the time accel-cmd 'show
version' is answered the flush registered at DEFINE_INIT(19) has already
run.
Interfaces are compared by ifindex and not by name, because dhclient may
get a new session in the meantime and the fresh interface would reuse
the ipoe0 name. The check that nothing removes the interfaces while no
accel-pppd is running is only printed, not asserted, so that the module
is free to start doing it on its own later on.
Diffstat (limited to 'tests/common/ipoe_iface.py')
| -rw-r--r-- | tests/common/ipoe_iface.py | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/common/ipoe_iface.py b/tests/common/ipoe_iface.py new file mode 100644 index 00000000..62b26355 --- /dev/null +++ b/tests/common/ipoe_iface.py @@ -0,0 +1,84 @@ +from common import process +import os +import signal +import time + + +# (ifindex, name) of every ipoe session interface currently in the kernel. +# Matched by name rather than by 'ip link show type ipoe' so that the helper +# keeps working with a module that does not register rtnl_link_ops. +def list_ipoe(): + (exit_code, out, err) = process.run(["ip", "-o", "link", "show"]) + assert exit_code == 0, "ip link show failed: " + err + + ifaces = [] + for line in out.splitlines(): + fields = line.split(":") + if len(fields) < 2: + continue + try: + ifindex = int(fields[0].strip()) + except ValueError: + continue + name = fields[1].strip().split("@")[0] + if name.startswith("ipoe"): + ifaces.append((ifindex, name)) + + return ifaces + + +# pids of the running accel-pppd processes +def accel_pppd_pids(): + pids = [] + for entry in os.listdir("/proc"): + if not entry.isdigit(): + continue + try: + with open("/proc/" + entry + "/comm") as comm: + if comm.read().strip() == "accel-pppd": + pids.append(int(entry)) + except OSError: # process is gone, or not ours to look at + pass + + return pids + + +# SIGKILL every accel-pppd and wait until they are really gone. +# Returns the number of processes that were killed. +def kill_accel_pppd(max_wait_time=10.0): + pids = accel_pppd_pids() + for pid in pids: + print("kill_accel_pppd: SIGKILL to pid " + str(pid)) + try: + os.kill(pid, signal.SIGKILL) + except OSError: + pass + + sleep_time = 0.0 + while sleep_time < max_wait_time: + if not accel_pppd_pids(): + print("kill_accel_pppd: gone in (sec): " + str(sleep_time)) + break + time.sleep(0.1) + sleep_time += 0.1 + + return len(pids) + + +# wait until accel-pppd reports an active ipoe session on the given interface +def wait_for_session(accel_cmd, called_sid, max_wait_time=10.0): + sleep_time = 0.0 + out = "" + while sleep_time < max_wait_time: + (exit_code, out, err) = process.run( + [accel_cmd, "show sessions called-sid,ip,state"] + ) + assert exit_code == 0, "accel-cmd failed: " + err + if called_sid in out and "192.0.2." in out and "active" in out: + print("wait_for_session: session found in (sec): " + str(sleep_time)) + return True + time.sleep(0.1) + sleep_time += 0.1 + + print("wait_for_session: last accel-cmd out: " + out) + return False |
