test/other: Resolve Py3 compatibility issues

When Python 2 is not installed we assume that /usr/bin/python refers to
version 3 of Python and the executable /usr/bin/python2 does not exist.

This commit also resolves a compatibility issue with Popen where in
Py2 file descriptors will be inherited by the child process and in
Py3 they will be closed by default.

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
This commit is contained in:
Radostin Stoyanov 2019-07-29 22:07:10 +01:00 committed by Andrei Vagin
parent 5aa72e7237
commit 4c1ee3e227
11 changed files with 31 additions and 23 deletions

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python
import sys, os
import hashlib

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python
import sys
import os

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python
import subprocess
import os, sys, time, signal, pty

View file

@ -20,7 +20,7 @@ for i in `cat /proc/self/mounts | awk '{ print $2 }'`; do
umount -l $i
done
python2 mounts.py
python mounts.py
kill $INMNTNS_PID
while :; do
sleep 10

View file

@ -1,4 +1,4 @@
#!/usr/bin/python2
#!/usr/bin/python
import os
import socket
@ -15,10 +15,15 @@ does_not_exist = 'does-not.exist'
def setup_swrk():
print('Connecting to CRIU in swrk mode.')
css = socket.socketpair(socket.AF_UNIX, socket.SOCK_SEQPACKET)
swrk = subprocess.Popen(['./criu', "swrk", "%d" % css[0].fileno()])
css[0].close()
return swrk, css[1]
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):

View file

@ -1,4 +1,4 @@
#!/usr/bin/python2
#!/usr/bin/python
# Test criu errno
import socket, os, errno

View file

@ -1,4 +1,4 @@
#!/usr/bin/python2
#!/usr/bin/python
import socket, os, sys, errno
import rpc_pb2 as rpc

View file

@ -1,4 +1,4 @@
#!/usr/bin/python2
#!/usr/bin/python
import socket, os, sys
import rpc_pb2 as rpc

View file

@ -1,4 +1,4 @@
#!/usr/bin/python2
#!/usr/bin/python
import socket, os, sys
import rpc_pb2 as rpc

View file

@ -1,4 +1,4 @@
#!/usr/bin/python2
#!/usr/bin/python
import socket
import sys
@ -7,11 +7,14 @@ import subprocess
print('Connecting to CRIU in swrk mode to check the version:')
css = socket.socketpair(socket.AF_UNIX, socket.SOCK_SEQPACKET)
swrk = subprocess.Popen(['./criu', "swrk", "%d" % css[0].fileno()])
css[0].close()
s1, s2 = socket.socketpair(socket.AF_UNIX, socket.SOCK_SEQPACKET)
s = css[1]
kwargs = {}
if sys.version_info.major == 3:
kwargs["pass_fds"] = [s2.fileno()]
swrk = subprocess.Popen(['./criu', "swrk", "%d" % s2.fileno()], **kwargs)
s2.close()
# Create criu msg, set it's type to dump request
# and set dump options. Checkout more options in protobuf/rpc.proto
@ -19,12 +22,12 @@ req = rpc.criu_req()
req.type = rpc.VERSION
# Send request
s.send(req.SerializeToString())
s1.send(req.SerializeToString())
# Recv response
resp = rpc.criu_resp()
MAX_MSG_SIZE = 1024
resp.ParseFromString(s.recv(MAX_MSG_SIZE))
resp.ParseFromString(s1.recv(MAX_MSG_SIZE))
if resp.type != rpc.VERSION:
print('RPC: Unexpected msg type')

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python
import os, pty, sys, subprocess
import termios, fcntl, time
@ -9,11 +9,11 @@ os.chdir(os.getcwd())
def create_pty():
(fd1, fd2) = pty.openpty()
return (os.fdopen(fd1, "w+"), os.fdopen(fd2, "w+"))
return (os.fdopen(fd1, "wb"), os.fdopen(fd2, "wb"))
if not os.access("work", os.X_OK):
os.mkdir("work", 0755)
os.mkdir("work", 0o755)
open("running", "w").close()
m, s = create_pty()