diff options
author | Radostin Stoyanov <rstoyanov1@gmail.com> | 2019-07-31 11:46:18 +0300 |
---|---|---|
committer | Andrei Vagin <avagin@gmail.com> | 2019-09-07 15:59:57 +0300 |
commit | 6b615ca15277fc14b52a09b4eb18314b7c6cbe75 (patch) | |
tree | b0e11f503eb2406d169e6decee3ccded080fb5bd /test | |
parent | 4c1ee3e227045fc1dc07b10ac7a538a68299693b (diff) |
test/others: Reuse setup_swrk()
Reduce code duplication by taking setup_swrk() function into a separate
module that can be reused in multiple places.
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
Diffstat (limited to 'test')
-rwxr-xr-x | test/others/rpc/config_file.py | 17 | ||||
-rw-r--r-- | test/others/rpc/setup_swrk.py | 16 | ||||
-rwxr-xr-x | test/others/rpc/version.py | 13 |
3 files changed, 21 insertions, 25 deletions
diff --git a/test/others/rpc/config_file.py b/test/others/rpc/config_file.py index e4b395e31..7b07bc145 100755 --- a/test/others/rpc/config_file.py +++ b/test/others/rpc/config_file.py @@ -1,31 +1,18 @@ #!/usr/bin/python import os -import socket import sys import rpc_pb2 as rpc import argparse -import subprocess from tempfile import mkstemp import time +from setup_swrk import setup_swrk + log_file = 'config_file_test.log' does_not_exist = 'does-not.exist' -def setup_swrk(): - print('Connecting to CRIU in swrk mode.') - s1, s2 = socket.socketpair(socket.AF_UNIX, socket.SOCK_SEQPACKET) - - kwargs = {} - if sys.version_info.major == 3: - kwargs["pass_fds"] = [s1.fileno()] - - swrk = subprocess.Popen(['./criu', "swrk", "%d" % s1.fileno()], **kwargs) - s1.close() - return swrk, s2 - - def setup_config_file(content): # Creating a temporary file which will be used as configuration file. fd, path = mkstemp() diff --git a/test/others/rpc/setup_swrk.py b/test/others/rpc/setup_swrk.py new file mode 100644 index 000000000..c7f84f952 --- /dev/null +++ b/test/others/rpc/setup_swrk.py @@ -0,0 +1,16 @@ +import sys +import socket +import subprocess + +def setup_swrk(): + print('Connecting to CRIU in swrk mode.') + s1, s2 = socket.socketpair(socket.AF_UNIX, socket.SOCK_SEQPACKET) + + kwargs = {} + if sys.version_info.major == 3: + kwargs["pass_fds"] = [s1.fileno()] + + swrk = subprocess.Popen(['./criu', "swrk", "%d" % s1.fileno()], **kwargs) + s1.close() + return swrk, s2 + diff --git a/test/others/rpc/version.py b/test/others/rpc/version.py index 3b8f1b961..9d7fa745b 100755 --- a/test/others/rpc/version.py +++ b/test/others/rpc/version.py @@ -1,20 +1,13 @@ #!/usr/bin/python -import socket import sys import rpc_pb2 as rpc -import subprocess -print('Connecting to CRIU in swrk mode to check the version:') - -s1, s2 = socket.socketpair(socket.AF_UNIX, socket.SOCK_SEQPACKET) +from setup_swrk import setup_swrk -kwargs = {} -if sys.version_info.major == 3: - kwargs["pass_fds"] = [s2.fileno()] +print('Connecting to CRIU in swrk mode to check the version:') -swrk = subprocess.Popen(['./criu', "swrk", "%d" % s2.fileno()], **kwargs) -s2.close() +swrk, s1 = setup_swrk() # Create criu msg, set it's type to dump request # and set dump options. Checkout more options in protobuf/rpc.proto |