[3/3,v3] zdtm: run page-server via rpc

Submitted by Andrei Vagin on April 25, 2017, 1:02 a.m.

Details

Message ID 20170425010235.20160-1-avagin@openvz.org
State New
Series "service: allow to run page-server as a child process"
Headers show

Commit Message

Andrei Vagin April 25, 2017, 1:02 a.m.
From: Andrei Vagin <avagin@virtuozzo.com>

v2: typo fix
v3: run criu pre-dump via rpc

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
---
 lib/py/criu.py              | 15 +++++++++++++++
 scripts/travis/travis-tests |  1 +
 test/zdtm.py                | 47 +++++++++++++++++++++++++++++++++++++++------
 3 files changed, 57 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/lib/py/criu.py b/lib/py/criu.py
index f10dbc0..cafaea8 100644
--- a/lib/py/criu.py
+++ b/lib/py/criu.py
@@ -277,6 +277,21 @@  class criu:
 
 		return resp.dump
 
+	def pre_dump(self):
+		"""
+		Checkpoint a process/tree identified by opts.pid.
+		"""
+		req 		= rpc.criu_req()
+		req.type	= rpc.PRE_DUMP
+		req.opts.MergeFrom(self.opts)
+
+		resp = self._send_req_and_recv_resp(req)
+
+		if not resp.success:
+			raise CRIUExceptionExternal(req.type, resp.type, resp.cr_errno)
+
+		return resp.dump
+
 	def restore(self):
 		"""
 		Restore a process/tree.
diff --git a/scripts/travis/travis-tests b/scripts/travis/travis-tests
index 93306ce..2ac7f58 100755
--- a/scripts/travis/travis-tests
+++ b/scripts/travis/travis-tests
@@ -87,6 +87,7 @@  ip net add test
 
 # RPC testing
 ./test/zdtm.py run -t zdtm/static/env00 --rpc		# Basic
+./test/zdtm.py run -t zdtm/static/env00 --rpc --pre 2 --page-server
 ./test/zdtm.py run -t zdtm/static/ptrace_sig -f h --rpc # Error handling (crfail test)
 
 pip install flake8
diff --git a/test/zdtm.py b/test/zdtm.py
index d35731b..772feff 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -695,6 +695,14 @@  class criu_cli:
 		return cr.wait()
 
 
+class criu_rpc_process:
+	def wait(self):
+		return self.criu.wait_pid(self.pid)
+
+        def terminate(self):
+            os.kill(self.pid, signal.SIGTERM)
+
+
 class criu_rpc:
 	@staticmethod
 	def __set_opts(criu, args, ctx):
@@ -729,6 +737,23 @@  class criu_rpc:
 			if arg == '--external':
 				criu.opts.external.append(args.pop(0))
 				continue
+			if arg == '--status-fd':
+				criu.opts.status_fd = int(args.pop(0))
+				continue
+			if arg == '--port':
+				criu.opts.ps.port = int(args.pop(0))
+				continue
+			if arg == '--address':
+				criu.opts.ps.address = args.pop(0)
+				continue
+			if arg == '--page-server':
+				continue
+			if arg == '--prev-images-dir':
+                                criu.opts.parent_img = args.pop(0)
+				continue
+			if arg == '--track-mem':
+                                criu.opts.track_mem = True
+				continue
 
 			raise test_fail_exc('RPC for %s required' % arg)
 
@@ -740,17 +765,18 @@  class criu_rpc:
 			raise test_fail_exc('RPC and SAT not supported')
 		if preexec:
 			raise test_fail_exc('RPC and PREEXEC not supported')
-		if nowait:
-			raise test_fail_exc("RPC and status-fd not supported")
 
 		ctx = {}  # Object used to keep info untill action is done
 		criu = crpc.criu()
 		criu.use_binary(criu_bin)
 		criu_rpc.__set_opts(criu, args, ctx)
+		p = None
 
 		try:
 			if action == 'dump':
 				criu.dump()
+                        elif action == 'pre-dump':
+                                criu.pre_dump()
 			elif action == 'restore':
 				if 'rd' not in ctx:
 					raise test_fail_exc('RPC Non-detached restore is impossible')
@@ -759,10 +785,15 @@  class criu_rpc:
 				pidf = ctx.get('pidf')
 				if pidf:
 					open(pidf, 'w').write('%d\n' % res.pid)
+			elif action == "page-server":
+				res = criu.page_server_chld()
+				p = criu_rpc_process()
+				p.pid = res.pid
+				p.criu = criu
 			else:
 				raise test_fail_exc('RPC for %s required' % action)
-		except crpc.CRIUExceptionExternal:
-			print "Fail"
+		except crpc.CRIUExceptionExternal, e:
+			print "Fail", e
 			ret = -1
 		else:
 			ret = 0
@@ -770,6 +801,10 @@  class criu_rpc:
 		imgd = ctx.get('imgd')
 		if imgd:
 			os.close(imgd)
+
+		if nowait and ret == 0:
+			return p
+
 		return ret
 
 
@@ -1036,11 +1071,11 @@  class criu:
 	def kill(self):
 		if self.__lazy_pages_p:
 			self.__lazy_pages_p.terminate()
-			print "criu lazy-pages exited with %s" & self.wait()
+			print "criu lazy-pages exited with %s" % self.__lazy_pages_p.wait()
 			self.__lazy_pages_p = None
 		if self.__page_server_p:
 			self.__page_server_p.terminate()
-			print "criu page-server exited with %s" & self.wait()
+			print "criu page-server exited with %s" % self.__page_server_p.wait()
 			self.__page_server_p = None