[v2,2/2] RPC: add script to test the new RPC version interface

Submitted by Adrian Reber on April 6, 2017, 3:03 p.m.

Details

Message ID 20170406150330.3818-2-adrian@lisas.de
State Accepted
Series "Series without cover letter"
Headers show

Commit Message

Adrian Reber April 6, 2017, 3:03 p.m.
From: Adrian Reber <areber@redhat.com>

This script connects to 'criu swrk' and asks for the version. If running
from a git checkout the output would look like this:

 $ ./version.py
 Connecting to CRIU in swrk mode to check the version:
 RPC: Success
 CRIU major 2
 CRIU minor 12
 CRIU gitid v2.12-635-g6d3ae4d

If not running from git checkout it looks like this:

 $ ./version.py
 Connecting to CRIU in swrk mode to check the version:
 RPC: Success
 CRIU major 2
 CRIU minor 12

If running with a CRIU binary which does not support the VERSION
command:

 $ ./version.py
 Connecting to CRIU in swrk mode to check the version:
 Error (cr-service.c:116): RPC error: Invalid req: Success
 RPC: Unexpected msg type

Signed-off-by: Adrian Reber <areber@redhat.com>
---
 test/others/rpc/version.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100755 test/others/rpc/version.py

Patch hide | download patch | download mbox

diff --git a/test/others/rpc/version.py b/test/others/rpc/version.py
new file mode 100755
index 0000000..93975f4
--- /dev/null
+++ b/test/others/rpc/version.py
@@ -0,0 +1,48 @@ 
+#!/usr/bin/python2
+
+import socket
+import sys
+import rpc_pb2 as rpc
+import argparse
+import subprocess
+
+print('Connecting to CRIU in swrk mode to check the version:')
+
+css = socket.socketpair(socket.AF_UNIX, socket.SOCK_SEQPACKET)
+swrk = subprocess.Popen(['./criu', "swrk", "%d" % css[0].fileno()])
+css[0].close()
+
+s = css[1]
+
+# 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.VERSION
+
+# 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.VERSION:
+	print('RPC: Unexpected msg type')
+	sys.exit(-1)
+else:
+	if resp.success:
+		print('RPC: Success')
+		print('CRIU major %d' % resp.version.major)
+		print('CRIU minor %d' % resp.version.minor)
+		if resp.version.HasField('gitid'):
+			print('CRIU gitid %s' % resp.version.gitid)
+		if resp.version.HasField('sublevel'):
+			print('CRIU sublevel %s' % resp.version.sublevel)
+		if resp.version.HasField('extra'):
+			print('CRIU extra %s' % resp.version.extra)
+		if resp.version.HasField('name'):
+			print('CRIU name %s' % resp.version.name)
+	else:
+		print 'Fail'
+		sys.exit(-1)