Index: testing/legion/client_rpc_methods.py |
diff --git a/testing/legion/client_rpc_methods.py b/testing/legion/client_rpc_methods.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5ff41266b455f2e95f6fa8a674857e007f73535d |
--- /dev/null |
+++ b/testing/legion/client_rpc_methods.py |
@@ -0,0 +1,52 @@ |
+# Copyright 2015 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+"""Defines the client RPC methods.""" |
+ |
+import logging |
+import subprocess |
+import threading |
+import StringIO |
+ |
+ |
+class RPCMethods(object): |
+ """Class exposing RPC methods.""" |
+ |
+ def __init__(self, server): |
+ self.server = server |
+ |
+ def Echo(self, message): |
+ """Simple RPC method to print and return a message.""" |
+ logging.info('Echoing %s', message) |
+ return 'echo ' + message |
+ |
+ def Subprocess(self, cmd): |
+ """Run the commands in a subprocess. |
+ |
+ Returns: |
+ (returncode, stdout, stderr). |
+ """ |
+ stdout = StringIO.StringIO() |
+ stderr = StringIO.StringIO() |
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, |
+ stderr=subprocess.PIPE) |
+ |
+ while p.poll() is None: |
+ _stdout, _stderr = p.communicate() |
+ stdout.write(_stdout) |
+ stderr.write(_stderr) |
+ |
+ stdout.seek(0) |
+ stderr.seek(0) |
+ return (p.returncode, stdout.read(), stderr.read()) |
+ |
+ def Quit(self): |
+ """Call server.shutdown in another thread. |
+ |
+ This is needed because server.shutdown waits for the server to actually |
+ quit. However the server cannot shutdown until it completes handling this |
+ call. Calling this in the same thread results in a deadlock. |
+ """ |
+ t = threading.Thread(target=self.server.shutdown) |
+ t.start() |