[CRIU] [PATCH 4/4] test: rpc: test.py

Ruslan Kuprieiev kupruser at gmail.com
Fri Sep 20 18:20:31 EDT 2013


Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
-------------- next part --------------
diff --git a/test/rpc/test.py b/test/rpc/test.py
new file mode 100755
index 0000000..46c6834
--- /dev/null
+++ b/test/rpc/test.py
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+
+import socket, os, imp, sys
+
+p = os.getcwd()
+sys.path.append(p)
+import rpc_pb2 as rpc
+
+# Connect to service socket
+s = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
+s.connect('criu_service.socket')
+
+# 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.DUMP
+req.dump.leave_running	= True
+req.dump.shell_job	= True
+
+if not os.path.exists('imgs_py'):
+	os.makedirs('imgs_py')
+
+req.dump.images_dir_fd	= os.open('imgs_py', os.O_DIRECTORY)
+
+# 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.DUMP:
+	print 'Unexpected msg type'
+	sys.exit(-1)
+else:
+	if resp.success:
+		print 'Success'
+	else:
+		print 'Fail'
+		sys.exit(-1)
+
+	if resp.dump.restored:
+		print 'Restored'



More information about the CRIU mailing list