summaryrefslogtreecommitdiff
path: root/tests/common/netns.py
diff options
context:
space:
mode:
authorSergey V. Lobanov <sergey@lobanov.in>2022-09-04 18:49:42 +0300
committerSergey V. Lobanov <sergey@lobanov.in>2022-09-04 19:06:49 +0300
commitc92ff6266b18a9655edef231391739f0479dfb3a (patch)
tree0196077cbd54c9607ba918a42cac567411197663 /tests/common/netns.py
parent38d96b8e20608fb743d543fe3f08ad4b9d1dcd66 (diff)
downloadaccel-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/common/netns.py')
-rw-r--r--tests/common/netns.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/common/netns.py b/tests/common/netns.py
new file mode 100644
index 00000000..9b0d729b
--- /dev/null
+++ b/tests/common/netns.py
@@ -0,0 +1,29 @@
+from common import process
+
+# creates netns and returns netns name. if ok return 0
+def create(netns_name):
+ netns, out, err = process.run(["ip", "netns", "add", netns_name])
+ print("netns.create: exit=%d out=%s err=%s" % (netns, out, err))
+
+ return netns
+
+
+# deletes netns. if ok return 0
+def delete(netns_name):
+ netns, out, err = process.run(["ip", "netns", "delete", netns_name])
+ print("netns.delete: exit=%d out=%s err=%s" % (netns, out, err))
+
+ return netns
+
+
+# execute command in netns using process.run
+# if netns_name is None, then execute in global rt
+def exec(netns_name, command):
+ if netns_name is None:
+ exit, out, err = process.run(command)
+ else:
+ exit, out, err = process.run(["ip", "netns", "exec", netns_name] + command)
+
+ print("netns.exec: netns=%s command=%s :: exit=%d out=%s err=%s" % (netns_name, str(command), exit, out, err))
+
+ return (exit, out, err)