Commit 147660f0 authored by Radostin Stoyanov's avatar Radostin Stoyanov Committed by Andrei Vagin

Convert to python3 style print() syntax

Use __future__ imports to keep this working for python2
Signed-off-by: 's avatarRadostin Stoyanov <rstoyanov1@gmail.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@gmail.com>
parent 7ce23b2a
...@@ -12,7 +12,7 @@ dst = os.getenv("TCP_DST", "127.0.0.1") ...@@ -12,7 +12,7 @@ dst = os.getenv("TCP_DST", "127.0.0.1")
sport = os.getenv("TCP_SPORT", "12345") sport = os.getenv("TCP_SPORT", "12345")
dport = os.getenv("TCP_DPORT", "54321") dport = os.getenv("TCP_DPORT", "54321")
print sys.argv[1] print(sys.argv[1])
args = [sys.argv[1], args = [sys.argv[1],
"--addr", src, "--port", sport, "--seq", "555", "--addr", src, "--port", sport, "--seq", "555",
"--next", "--next",
...@@ -41,7 +41,7 @@ m.update(str2) ...@@ -41,7 +41,7 @@ m.update(str2)
str2 = m.hexdigest() str2 = m.hexdigest()
if str2 != eval(s): if str2 != eval(s):
print "FAIL", repr(str2), repr(s) print("FAIL", repr(str2), repr(s))
sys.exit(5); sys.exit(5);
s = p1.stdout.read() s = p1.stdout.read()
...@@ -51,7 +51,7 @@ str1 = m.hexdigest() ...@@ -51,7 +51,7 @@ str1 = m.hexdigest()
s = p2.stdout.read() s = p2.stdout.read()
if str1 != eval(s): if str1 != eval(s):
print "FAIL", repr(str1), s print("FAIL", repr(str1), s)
sys.exit(5); sys.exit(5);
if p1.wait(): if p1.wait():
...@@ -59,4 +59,4 @@ if p1.wait(): ...@@ -59,4 +59,4 @@ if p1.wait():
if p2.wait(): if p2.wait():
sys.exit(1) sys.exit(1)
print "PASS" print("PASS")
#!/usr/bin/env python2 #!/usr/bin/env python2
from __future__ import print_function
import sys, socket import sys, socket
import hashlib import hashlib
...@@ -7,13 +8,13 @@ sk = socket.fromfd(3, socket.AF_INET, socket.SOCK_STREAM) ...@@ -7,13 +8,13 @@ sk = socket.fromfd(3, socket.AF_INET, socket.SOCK_STREAM)
s = sys.stdin.read() s = sys.stdin.read()
ret = sk.send(s) ret = sk.send(s)
print >> sys.stderr, "%s: send() -> %d" % (sys.argv[1], ret) print("%s: send() -> %d" % (sys.argv[1], ret), file=sys.stderr)
sk.shutdown(socket.SHUT_WR) sk.shutdown(socket.SHUT_WR)
m = hashlib.md5() m = hashlib.md5()
while True: while True:
s = sk.recv((1 << 20) * 10) s = sk.recv((1 << 20) * 10)
if not s: if not s:
break break
print >> sys.stderr, "%s: recv() -> %d" % (sys.argv[1], len(s)) print("%s: recv() -> %d" % (sys.argv[1], len(s)), file=sys.stderr)
m.update(s) m.update(s)
print repr(m.hexdigest()) print(repr(m.hexdigest()))
...@@ -34,7 +34,7 @@ if actions: ...@@ -34,7 +34,7 @@ if actions:
if errors: if errors:
for x in errors: for x in errors:
print x print(x)
sys.exit(1) sys.exit(1)
print 'PASS' print('PASS')
...@@ -34,7 +34,7 @@ def mix(nr_tasks, nr_pipes): ...@@ -34,7 +34,7 @@ def mix(nr_tasks, nr_pipes):
# Called by a test sub-process. It just closes the not needed ends # Called by a test sub-process. It just closes the not needed ends
# of pipes and sleeps waiting for death. # of pipes and sleeps waiting for death.
def make_pipes(task_nr, nr_pipes, pipes, comb, status_pipe): def make_pipes(task_nr, nr_pipes, pipes, comb, status_pipe):
print '\t\tMake pipes for %d' % task_nr print('\t\tMake pipes for %d' % task_nr)
# We need to make sure that pipes have their # We need to make sure that pipes have their
# ends according to comb for task_nr # ends according to comb for task_nr
...@@ -134,7 +134,7 @@ def check_pipes(kids, pipes, comb): ...@@ -134,7 +134,7 @@ def check_pipes(kids, pipes, comb):
# and waits for a signal (unix socket message) to start checking # and waits for a signal (unix socket message) to start checking
# the kids' FD tables. # the kids' FD tables.
def make_comb(comb, opts, status_pipe): def make_comb(comb, opts, status_pipe):
print '\tMake pipes' print('\tMake pipes')
# 1st -- make needed pipes # 1st -- make needed pipes
pipes = [] pipes = []
for p in xrange(0, opts.pipes): for p in xrange(0, opts.pipes):
...@@ -168,7 +168,7 @@ def make_comb(comb, opts, status_pipe): ...@@ -168,7 +168,7 @@ def make_comb(comb, opts, status_pipe):
ex_code = 1 ex_code = 1
if k_res == '0' * opts.tasks: if k_res == '0' * opts.tasks:
print '\tWait for C/R' print('\tWait for C/R')
cmd_sk = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM, 0) cmd_sk = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM, 0)
cmd_sk.bind('\0CRIUPCSK') cmd_sk.bind('\0CRIUPCSK')
...@@ -178,12 +178,12 @@ def make_comb(comb, opts, status_pipe): ...@@ -178,12 +178,12 @@ def make_comb(comb, opts, status_pipe):
os.close(status_pipe) os.close(status_pipe)
v = cmd_sk.recv(16) v = cmd_sk.recv(16)
if v == '0': if v == '0':
print '\tCheck pipes' print('\tCheck pipes')
res = check_pipes(kids, pipes, comb) res = check_pipes(kids, pipes, comb)
if res == None: if res == None:
ex_code = 0 ex_code = 0
else: else:
print '\tFAIL %s' % res print('\tFAIL %s' % res)
# Just kill kids, all checks are done by us, we don't need'em any more # Just kill kids, all checks are done by us, we don't need'em any more
for t in kids: for t in kids:
...@@ -194,27 +194,27 @@ def make_comb(comb, opts, status_pipe): ...@@ -194,27 +194,27 @@ def make_comb(comb, opts, status_pipe):
def cr_test(pid): def cr_test(pid):
print 'C/R test' print('C/R test')
img_dir = 'pimg_%d' % pid img_dir = 'pimg_%d' % pid
try: try:
os.mkdir(img_dir) os.mkdir(img_dir)
subprocess.check_call([criu_bin, 'dump', '-t', '%d' % pid, '-D', img_dir, '-o', 'dump.log', '-v4', '-j']) subprocess.check_call([criu_bin, 'dump', '-t', '%d' % pid, '-D', img_dir, '-o', 'dump.log', '-v4', '-j'])
except: except:
print '`- dump fail' print('`- dump fail')
return False return False
try: try:
os.waitpid(pid, 0) os.waitpid(pid, 0)
subprocess.check_call([criu_bin, 'restore', '-D', img_dir, '-o', 'rst.log', '-v4', '-j', '-d', '-S']) subprocess.check_call([criu_bin, 'restore', '-D', img_dir, '-o', 'rst.log', '-v4', '-j', '-d', '-S'])
except: except:
print '`- restore fail' print('`- restore fail')
return False return False
return True return True
def run(comb, opts): def run(comb, opts):
print 'Checking %r' % comb print('Checking %r' % comb)
cpipe = os.pipe() cpipe = os.pipe()
pid = os.fork() pid = os.fork()
if pid == 0: if pid == 0:
...@@ -230,7 +230,7 @@ def run(comb, opts): ...@@ -230,7 +230,7 @@ def run(comb, opts):
if res == '0': if res == '0':
res = cr_test(pid) res = cr_test(pid)
print 'Wake up test' print('Wake up test')
s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM, 0) s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM, 0)
if res: if res:
res = '0' res = '0'
...@@ -249,7 +249,7 @@ def run(comb, opts): ...@@ -249,7 +249,7 @@ def run(comb, opts):
if os.WIFEXITED(st): if os.WIFEXITED(st):
st = os.WEXITSTATUS(st) st = os.WEXITSTATUS(st)
print 'Done (%d, pid == %d)' % (st, pid) print('Done (%d, pid == %d)' % (st, pid))
return st == 0 return st == 0
...@@ -264,7 +264,7 @@ pipe_combs = mix(opts.tasks, opts.pipes) ...@@ -264,7 +264,7 @@ pipe_combs = mix(opts.tasks, opts.pipes)
for comb in pipe_combs: for comb in pipe_combs:
if not run(comb, opts): if not run(comb, opts):
print 'FAIL' print('FAIL')
break break
else: else:
print 'PASS' print('PASS')
...@@ -471,10 +471,10 @@ def chk_real_state(st): ...@@ -471,10 +471,10 @@ def chk_real_state(st):
try: try:
s_st = os.fstat(rsk.fileno()) s_st = os.fstat(rsk.fileno())
except: except:
print 'FAIL: Socket %d lost' % sk.sk_id print('FAIL: Socket %d lost' % sk.sk_id)
return CHK_FAIL_SOCKET return CHK_FAIL_SOCKET
if not stat.S_ISSOCK(s_st.st_mode): if not stat.S_ISSOCK(s_st.st_mode):
print 'FAIL: Not a socket %d at %d' % (sk.sk_id, rsk.fileno()) print('FAIL: Not a socket %d at %d' % (sk.sk_id, rsk.fileno()))
return CHK_FAIL_STAT return CHK_FAIL_STAT
# First -- check the listen states and names # First -- check the listen states and names
...@@ -485,16 +485,16 @@ def chk_real_state(st): ...@@ -485,16 +485,16 @@ def chk_real_state(st):
rsk = st.real_sockets[sk.sk_id] rsk = st.real_sockets[sk.sk_id]
r_listen = rsk.getsockopt(socket.SOL_SOCKET, socket.SO_ACCEPTCONN) r_listen = rsk.getsockopt(socket.SOL_SOCKET, socket.SO_ACCEPTCONN)
if (sk.listen and r_listen == 0) or (not sk.listen and r_listen == 1): if (sk.listen and r_listen == 0) or (not sk.listen and r_listen == 1):
print "FAIL: Socket %d listen %d, expected %d" % \ print("FAIL: Socket %d listen %d, expected %d"
(sk.sk_id, r_listen, sk.listen and 1 or 0) % (sk.sk_id, r_listen, sk.listen and 1 or 0))
return CHK_FAIL_LISTEN return CHK_FAIL_LISTEN
if sk.name: if sk.name:
r_name = rsk.getsockname() r_name = rsk.getsockname()
w_name = sock.real_name_for(sk.name) w_name = sock.real_name_for(sk.name)
if r_name != w_name: if r_name != w_name:
print 'FAIL: Socket %d name mismatch [%s], want [%s]' % \ print('FAIL: Socket %d name mismatch [%s], want [%s]'
(sk.sk_id, r_name, w_name) % (sk.sk_id, r_name, w_name))
return CHK_FAIL_NAME return CHK_FAIL_NAME
# Second -- check (accept) pending connections # Second -- check (accept) pending connections
...@@ -513,10 +513,10 @@ def chk_real_state(st): ...@@ -513,10 +513,10 @@ def chk_real_state(st):
try: try:
acc.do(st) acc.do(st)
except: except:
print 'FAIL: Cannot accept pending connection for %d' % sk.sk_id print('FAIL: Cannot accept pending connection for %d' % sk.sk_id)
return CHK_FAIL_ACCEPT return CHK_FAIL_ACCEPT
print ' `- did %s' % acc.show() print(' `- did %s' % acc.show())
# Third -- check inqueues # Third -- check inqueues
for sk in st.sockets: for sk in st.sockets:
...@@ -531,18 +531,18 @@ def chk_real_state(st): ...@@ -531,18 +531,18 @@ def chk_real_state(st):
try: try:
r_msg, m_from = rsk.recvfrom(128) r_msg, m_from = rsk.recvfrom(128)
except: except:
print 'FAIL: No message in queue for %d' % sk.sk_id print('FAIL: No message in queue for %d' % sk.sk_id)
return CHK_FAIL_RECV_0 return CHK_FAIL_RECV_0
w_msg = act_sendmsg.msgval(msg[1]) w_msg = act_sendmsg.msgval(msg[1])
if r_msg != w_msg: if r_msg != w_msg:
print 'FAIL: Message misorder: %s want %s (from %d)' % \ print('FAIL: Message misorder: %s want %s (from %d)'
(r_msg, w_msg, msg[0]) %(r_msg, w_msg, msg[0]))
return CHK_FAIL_RECV_MIX return CHK_FAIL_RECV_MIX
# TODO -- check sender # TODO -- check sender
print ' `- recvd %d.%d msg %s -> %d' % \ print(' `- recvd %d.%d msg %s -> %d'
(msg[0], msg[1], m_from, sk.sk_id) % (msg[0], msg[1], m_from, sk.sk_id))
# Finally, after all sockets are visible and all inqueues are # Finally, after all sockets are visible and all inqueues are
# drained -- check the sockets connectivity # drained -- check the sockets connectivity
...@@ -563,8 +563,7 @@ def chk_real_state(st): ...@@ -563,8 +563,7 @@ def chk_real_state(st):
rsk.send(msgv) rsk.send(msgv)
rmsg = psk.recv(128) rmsg = psk.recv(128)
except: except:
print 'FAIL: Connectivity %d -> %d lost' % \ print('FAIL: Connectivity %d -> %d lost' % (sk.sk_id, sk.peer))
(sk.sk_id, sk.peer)
return CHK_FAIL_CONNECT return CHK_FAIL_CONNECT
# If sockets are not connected the recv above # If sockets are not connected the recv above
...@@ -573,17 +572,17 @@ def chk_real_state(st): ...@@ -573,17 +572,17 @@ def chk_real_state(st):
# the hard way -- also check for the message being # the hard way -- also check for the message being
# delivered for real # delivered for real
if rmsg != msgv: if rmsg != msgv:
print 'FAIL: Connectivity %d -> %d not verified' % \ print('FAIL: Connectivity %d -> %d not verified'
(sk.sk_id, sk.peer) % (sk.sk_id, sk.peer))
return CHK_FAIL_CONNECT2 return CHK_FAIL_CONNECT2
print ' `- checked %d -> %d with %s' % (sk.sk_id, sk.peer, msgv) print(' `- checked %d -> %d with %s' % (sk.sk_id, sk.peer, msgv))
return CHK_PASS return CHK_PASS
def chk_state(st, opts): def chk_state(st, opts):
print "Will check state" print("Will check state")
sigsk_name = "\0" + "CRSIGSKC" sigsk_name = "\0" + "CRSIGSKC"
signal_sk = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM, 0) signal_sk = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM, 0)
...@@ -606,25 +605,25 @@ def chk_state(st, opts): ...@@ -606,25 +605,25 @@ def chk_state(st, opts):
for rsk in st.real_sockets.values(): for rsk in st.real_sockets.values():
rsk.close() rsk.close()
print "`- dump" print("`- dump")
img_path = "sti_" + st.describe() img_path = "sti_" + st.describe()
try: try:
os.mkdir(img_path) os.mkdir(img_path)
subprocess.check_call([criu_bin, "dump", "-t", "%d" % pid, "-D", img_path, "-v4", "-o", "dump.log", "-j"]) subprocess.check_call([criu_bin, "dump", "-t", "%d" % pid, "-D", img_path, "-v4", "-o", "dump.log", "-j"])
except: except:
print "Dump failed" print("Dump failed")
os.kill(pid, signal.SIGKILL) os.kill(pid, signal.SIGKILL)
return CHK_FAIL_DUMP return CHK_FAIL_DUMP
print "`- restore" print("`- restore")
try: try:
os.waitpid(pid, 0) os.waitpid(pid, 0)
subprocess.check_call([criu_bin, "restore", "-D", img_path, "-v4", "-o", "rst.log", "-j", "-d", "-S"]) subprocess.check_call([criu_bin, "restore", "-D", img_path, "-v4", "-o", "rst.log", "-j", "-d", "-S"])
except: except:
print "Restore failed" print("Restore failed")
return CHK_FAIL_RESTORE return CHK_FAIL_RESTORE
print "`- check" print("`- check")
signal_sk = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM, 0) signal_sk = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM, 0)
try: try:
signal_sk.sendto('check', sigsk_name) signal_sk.sendto('check', sigsk_name)
...@@ -636,11 +635,11 @@ def chk_state(st, opts): ...@@ -636,11 +635,11 @@ def chk_state(st, opts):
if os.WIFEXITED(status): if os.WIFEXITED(status):
status = os.WEXITSTATUS(status) status = os.WEXITSTATUS(status)
if status != CHK_PASS: if status != CHK_PASS:
print "`- exited with %d" % status print("`- exited with %d" % status)
return status return status
elif os.WIFSIGNALED(status): elif os.WIFSIGNALED(status):
status = os.WTERMSIG(status) status = os.WTERMSIG(status)
print "`- killed with %d" % status print("`- killed with %d" % status)
return CHK_FAIL_KILLED return CHK_FAIL_KILLED
else: else:
return CHK_FAIL_UNKNOWN return CHK_FAIL_UNKNOWN
...@@ -649,7 +648,7 @@ def chk_state(st, opts): ...@@ -649,7 +648,7 @@ def chk_state(st, opts):
def run_state(st, opts): def run_state(st, opts):
print "Will run state" print("Will run state")
pid = os.fork() pid = os.fork()
if pid != 0: if pid != 0:
wpid, status = os.wait() wpid, status = os.wait()
...@@ -685,9 +684,9 @@ def proceed(st, seen, failed, opts, depth = 0): ...@@ -685,9 +684,9 @@ def proceed(st, seen, failed, opts, depth = 0):
# using less steps and it's better to proceed as we have # using less steps and it's better to proceed as we have
# depth to move forward and generate more states. # depth to move forward and generate more states.
seen[desc] = len(st.steps) seen[desc] = len(st.steps)
print '%s' % desc print('%s' % desc)
for s in st.steps: for s in st.steps:
print '\t%s' % s.show() print('\t%s' % s.show())
if not opts.gen: if not opts.gen:
ret = run_state(st, opts) ret = run_state(st, opts)
...@@ -731,7 +730,7 @@ opts.depth = int(opts.depth) ...@@ -731,7 +730,7 @@ opts.depth = int(opts.depth)
# XXX: does it make any sense to mix two types in one go? # XXX: does it make any sense to mix two types in one go?
if opts.stream and opts.dgram: if opts.stream and opts.dgram:
print 'Choose only one type' print('Choose only one type')
sys.exit(1) sys.exit(1)
if opts.stream: if opts.stream:
...@@ -739,7 +738,7 @@ if opts.stream: ...@@ -739,7 +738,7 @@ if opts.stream:
elif opts.dgram: elif opts.dgram:
sk_type = socket.SOCK_DGRAM sk_type = socket.SOCK_DGRAM
else: else:
print 'Choose some type' print('Choose some type')
sys.exit(1) sys.exit(1)
st = state(int(opts.sockets), sk_type) st = state(int(opts.sockets), sk_type)
...@@ -748,8 +747,8 @@ failed = set() ...@@ -748,8 +747,8 @@ failed = set()
proceed(st, seen, failed, opts) proceed(st, seen, failed, opts)
if len(failed) == 0: if len(failed) == 0:
print 'PASS (%d states)' % len(seen) print('PASS (%d states)' % len(seen))
else: else:
print 'FAIL %d/%d' % (len(failed), len(seen)) print('FAIL %d/%d' % (len(failed), len(seen)))
for f in failed: for f in failed:
print "\t%-50s: %s" % (f[0], fail_desc.get(f[1], 'unknown reason %d' % f[1])) print("\t%-50s: %s" % (f[0], fail_desc.get(f[1], 'unknown reason %d' % f[1])))
...@@ -13,7 +13,7 @@ def create_fds(): ...@@ -13,7 +13,7 @@ def create_fds():
os.system("umount -l %s" % tdir) os.system("umount -l %s" % tdir)
os.rmdir(tdir) os.rmdir(tdir)
mnt_id = -1; mnt_id = -1
with open("/proc/self/fdinfo/%d" % fd1.fileno()) as f: with open("/proc/self/fdinfo/%d" % fd1.fileno()) as f:
for l in f: for l in f:
l = l.split() l = l.split()
......
...@@ -30,7 +30,7 @@ os.waitpid(-1, os.WNOHANG) # is the process alive ...@@ -30,7 +30,7 @@ os.waitpid(-1, os.WNOHANG) # is the process alive
os.close(new_master) os.close(new_master)
_, status = os.wait() _, status = os.wait()
if not os.WIFSIGNALED(status) or os.WTERMSIG(status) != signal.SIGHUP: if not os.WIFSIGNALED(status) or os.WTERMSIG(status) != signal.SIGHUP:
print status print(status)
sys.exit(1) sys.exit(1)
print "PASS" print("PASS")
...@@ -14,10 +14,10 @@ def mount(src, dst, shared, private, slave): ...@@ -14,10 +14,10 @@ def mount(src, dst, shared, private, slave):
else: else:
cmd += " -t tmpfs none '%s'" % (dst) cmd += " -t tmpfs none '%s'" % (dst)
print cmd print(cmd)
ret = os.system(cmd) ret = os.system(cmd)
if ret: if ret:
print "failed" print("failed")
root = tempfile.mkdtemp(prefix = "root.mount", dir = "/tmp") root = tempfile.mkdtemp(prefix = "root.mount", dir = "/tmp")
mount(None, root, 1, 0, 0) mount(None, root, 1, 0, 0)
......
...@@ -48,7 +48,7 @@ class test: ...@@ -48,7 +48,7 @@ class test:
raise Exception('Unexpected cr_errno ' + str(resp.cr_errno)) raise Exception('Unexpected cr_errno ' + str(resp.cr_errno))
def no_process(self): def no_process(self):
print 'Try to dump unexisting process' print('Try to dump unexisting process')
# Get pid of non-existing process. # Get pid of non-existing process.
# Suppose max_pid is not taken by any process. # Suppose max_pid is not taken by any process.
with open("/proc/sys/kernel/pid_max", "r") as f: with open("/proc/sys/kernel/pid_max", "r") as f:
...@@ -70,10 +70,10 @@ class test: ...@@ -70,10 +70,10 @@ class test:
self.check_resp(resp, rpc.DUMP, errno.ESRCH) self.check_resp(resp, rpc.DUMP, errno.ESRCH)
print 'Success' print('Success')
def process_exists(self): def process_exists(self):
print 'Try to restore process which pid is already taken by other process' print('Try to restore process which pid is already taken by other process')
# Perform self-dump # Perform self-dump
req = self.get_base_req() req = self.get_base_req()
...@@ -95,10 +95,10 @@ class test: ...@@ -95,10 +95,10 @@ class test:
self.check_resp(resp, rpc.RESTORE, errno.EEXIST) self.check_resp(resp, rpc.RESTORE, errno.EEXIST)
print 'Success' print('Success')
def bad_options(self): def bad_options(self):
print 'Try to send criu invalid opts' print('Try to send criu invalid opts')
# Subdirs are not allowed in log_file # Subdirs are not allowed in log_file
req = self.get_base_req() req = self.get_base_req()
...@@ -110,10 +110,10 @@ class test: ...@@ -110,10 +110,10 @@ class test:
self.check_resp(resp, rpc.DUMP, errno.EBADRQC) self.check_resp(resp, rpc.DUMP, errno.EBADRQC)
print 'Success' print('Success')
def bad_request(self): def bad_request(self):
print 'Try to send criu invalid request type' print('Try to send criu invalid request type')
req = self.get_base_req() req = self.get_base_req()
req.type = rpc.NOTIFY req.type = rpc.NOTIFY
...@@ -123,7 +123,7 @@ class test: ...@@ -123,7 +123,7 @@ class test:
self.check_resp(resp, rpc.EMPTY, None) self.check_resp(resp, rpc.EMPTY, None)
print 'Success' print('Success')
def run(self): def run(self):
self.no_process() self.no_process()
......
...@@ -15,7 +15,7 @@ s = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET) ...@@ -15,7 +15,7 @@ s = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
s.connect(args['socket']) s.connect(args['socket'])
# Start page-server # Start page-server
print 'Starting page-server' print('Starting page-server')
req = rpc.criu_req() req = rpc.criu_req()
req.type = rpc.PAGE_SERVER req.type = rpc.PAGE_SERVER
req.opts.log_file = 'page-server.log' req.opts.log_file = 'page-server.log'
...@@ -29,7 +29,7 @@ MAX_MSG_SIZE = 1024 ...@@ -29,7 +29,7 @@ MAX_MSG_SIZE = 1024
resp.ParseFromString(s.recv(MAX_MSG_SIZE)) resp.ParseFromString(s.recv(MAX_MSG_SIZE))
if resp.type != rpc.PAGE_SERVER: if resp.type != rpc.PAGE_SERVER:
print 'Unexpected msg type' print('Unexpected msg type')
sys.exit(1) sys.exit(1)
else: else:
if resp.success: if resp.success:
...@@ -38,18 +38,18 @@ else: ...@@ -38,18 +38,18 @@ else:
os.kill(resp.ps.pid, 0) os.kill(resp.ps.pid, 0)
except OSError as err: except OSError as err:
if err.errno == errno.ESRCH: if err.errno == errno.ESRCH:
print 'No process with page-server pid %d' %(resp.ps.pid) print('No process with page-server pid %d' %(resp.ps.pid))
else: else:
print 'Can\'t check that process %d exists' %(resp.ps.pid) print('Can\'t check that process %d exists' %(resp.ps.pid))
sys.exit(1) sys.exit(1)
print 'Success, page-server pid %d started on port %u' %(resp.ps.pid, resp.ps.port) print('Success, page-server pid %d started on port %u' %(resp.ps.pid, resp.ps.port))
else: else:
print 'Failed to start page-server' print('Failed to start page-server')
sys.exit(1) sys.exit(1)
# Perform self-dump # Perform self-dump
print 'Dumping myself using page-server' print('Dumping myself using page-server')
req.type = rpc.DUMP req.type = rpc.DUMP
req.opts.ps.port = resp.ps.port req.opts.ps.port = resp.ps.port
req.opts.ps.address = "127.0.0.1" req.opts.ps.address = "127.0.0.1"
...@@ -64,11 +64,11 @@ s.send(req.SerializeToString()) ...@@ -64,11 +64,11 @@ s.send(req.SerializeToString())
resp.ParseFromString(s.recv(MAX_MSG_SIZE)) resp.ParseFromString(s.recv(MAX_MSG_SIZE))
if resp.type != rpc.DUMP: if resp.type != rpc.DUMP:
print 'Unexpected msg type' print('Unexpected msg type')
sys.exit(1) sys.exit(1)
else: else:
if resp.success: if resp.success:
print 'Success' print('Success')
else: else:
print 'Fail' print('Fail')
sys.exit(1) sys.exit(1)
...@@ -34,12 +34,12 @@ MAX_MSG_SIZE = 1024 ...@@ -34,12 +34,12 @@ MAX_MSG_SIZE = 1024
resp.ParseFromString(s.recv(MAX_MSG_SIZE)) resp.ParseFromString(s.recv(MAX_MSG_SIZE))
if resp.type != rpc.RESTORE: if resp.type != rpc.RESTORE:
print 'Unexpected msg type' print('Unexpected msg type')
sys.exit(-1) sys.exit(-1)
else: else:
if resp.success: if resp.success:
print 'Restore success' print('Restore success')
else: else:
print 'Restore fail' print('Restore fail')
sys.exit(-1) sys.exit(-1)
print "PID of the restored program is %d\n" %(resp.restore.pid) print("PID of the restored program is %d\n" %(resp.restore.pid))
...@@ -31,17 +31,17 @@ MAX_MSG_SIZE = 1024 ...@@ -31,17 +31,17 @@ MAX_MSG_SIZE = 1024
resp.ParseFromString(s.recv(MAX_MSG_SIZE)) resp.ParseFromString(s.recv(MAX_MSG_SIZE))
if resp.type != rpc.DUMP: if resp.type != rpc.DUMP:
print 'Unexpected msg type' print('Unexpected msg type')
sys.exit(-1) sys.exit(-1)
else: else:
if resp.success: if resp.success:
print 'Success' print('Success')
else: else:
print 'Fail' print('Fail')
sys.exit(-1) sys.exit(-1)
if resp.dump.restored: if resp.dump.restored:
print 'Restored' print('Restored')
# Connect to service socket # Connect to service socket
s = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET) s = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
...@@ -77,5 +77,5 @@ else: ...@@ -77,5 +77,5 @@ else:
if resp.version.HasField('name'): if resp.version.HasField('name'):
print('CRIU name %s' % resp.version.name) print('CRIU name %s' % resp.version.name)
else: else:
print 'Fail' print('Fail')
sys.exit(-1) sys.exit(-1)
...@@ -43,5 +43,5 @@ else: ...@@ -43,5 +43,5 @@ else:
if resp.version.HasField('name'): if resp.version.HasField('name'):
print('CRIU name %s' % resp.version.name) print('CRIU name %s' % resp.version.name)
else: else:
print 'Fail' print('Fail')
sys.exit(-1) sys.exit(-1)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment