2016-02-19 18:05:50 +03:00
|
|
|
#!/usr/bin/python2
|
2013-10-02 23:45:35 +04:00
|
|
|
|
|
|
|
import socket, os, imp, sys
|
|
|
|
import rpc_pb2 as rpc
|
2015-01-22 18:59:00 +03:00
|
|
|
import argparse
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description="Test ability to restore a process from images using CRIU RPC")
|
|
|
|
parser.add_argument('socket', type = str, help = "CRIU service socket")
|
|
|
|
parser.add_argument('dir', type = str, help = "Directory where CRIU images could be found")
|
|
|
|
|
|
|
|
args = vars(parser.parse_args())
|
2013-10-02 23:45:35 +04:00
|
|
|
|
|
|
|
# Connect to service socket
|
|
|
|
s = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
|
2015-01-22 18:59:00 +03:00
|
|
|
s.connect(args['socket'])
|
2013-10-02 23:45:35 +04:00
|
|
|
|
|
|
|
# Create criu msg, set it's type to dump request
|
|
|
|
# and set dump options. Checkout more options in protobuf/rpc.proto
|
|
|
|
req = rpc.criu_req()
|
|
|
|
req.type = rpc.RESTORE
|
2015-01-22 18:59:00 +03:00
|
|
|
req.opts.images_dir_fd = os.open(args['dir'], os.O_DIRECTORY)
|
2018-06-28 12:43:28 +00:00
|
|
|
# As the dumped process is running with setsid this should not
|
|
|
|
# be necessary. There seems to be a problem for this testcase
|
|
|
|
# in combination with alpine's setsid.
|
|
|
|
# The dump is now done with -j and the restore also.
|
|
|
|
req.opts.shell_job = True
|
2013-10-02 23:45:35 +04:00
|
|
|
|
|
|
|
# Send request
|
|
|
|
s.send(req.SerializeToString())
|
|
|
|
|
|
|
|
# Recv response
|
|
|
|
resp = rpc.criu_resp()
|
|
|
|
MAX_MSG_SIZE = 1024
|
|
|
|
resp.ParseFromString(s.recv(MAX_MSG_SIZE))
|
|
|
|
|
|
|
|
if resp.type != rpc.RESTORE:
|
|
|
|
print 'Unexpected msg type'
|
|
|
|
sys.exit(-1)
|
|
|
|
else:
|
|
|
|
if resp.success:
|
|
|
|
print 'Restore success'
|
|
|
|
else:
|
|
|
|
print 'Restore fail'
|
|
|
|
sys.exit(-1)
|
|
|
|
print "PID of the restored program is %d\n" %(resp.restore.pid)
|