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/common/dhclient_process.py | |
| 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/common/dhclient_process.py')
| -rw-r--r-- | tests/common/dhclient_process.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/common/dhclient_process.py b/tests/common/dhclient_process.py new file mode 100644 index 00000000..aaea4860 --- /dev/null +++ b/tests/common/dhclient_process.py @@ -0,0 +1,45 @@ +from subprocess import Popen, PIPE +from threading import Thread + + +def dhclient_thread_func(dhclient_control): + process = dhclient_control["process"] + print("dhclient_thread_func: before communicate") + (out, err) = process.communicate() + print( + "dhclient_thread_func: after communicate out=" + str(out) + " err=" + str(err) + ) + process.wait() + print("dhclient_thread_func: after wait") + + +def start(netns, dhclient, args): + print("dhclient_start: begin") + print("dhclient_start: args=" + str(args)) + dhclient_process = Popen( + ["ip", "netns", "exec", netns] + [dhclient] + args, stdout=PIPE, stderr=PIPE + ) + print("dhclient_start: dhclient_process=" + str(dhclient_process)) + dhclient_control = {"process": dhclient_process} + dhclient_thread = Thread( + target=dhclient_thread_func, + args=[dhclient_control], + ) + dhclient_thread.start() + + is_started = True if dhclient_process.poll() is None else False + + return (is_started, dhclient_thread, dhclient_control) + + +def end(dhclient_thread, dhclient_control): + print("dhclient_end: begin") + if dhclient_control["process"].poll() is not None: # already terminated + print("dhclient_end: already terminated. nothing to do") + dhclient_thread.join() + return + + print("dhclient_end: kill process: " + str(dhclient_control["process"])) + dhclient_control["process"].kill() # kill -9 + dhclient_thread.join() # wait until thread is finished + print("dhclient_end: end") |
