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

Submitted by Andrei Vagin on April 24, 2017, 11:16 p.m.

Details

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

Commit Message

Andrei Vagin April 24, 2017, 11:16 p.m.
From: Andrei Vagin <avagin@virtuozzo.com>

v2: typo fix

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
---
 scripts/travis/travis-tests |  1 +
 test/zdtm.py                | 41 +++++++++++++++++++++++++++++++++++------
 2 files changed, 36 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

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..e202b8b 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,17 @@  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
 
 			raise test_fail_exc('RPC for %s required' % arg)
 
@@ -740,17 +759,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 +779,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 +795,10 @@  class criu_rpc:
 		imgd = ctx.get('imgd')
 		if imgd:
 			os.close(imgd)
+
+		if nowait and ret == 0:
+			return p
+
 		return ret
 
 
@@ -1036,11 +1065,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