used to run node test scripts on the specified node
authorTony Mack <tmack@cs.princeton.edu>
Thu, 31 Jan 2008 20:14:13 +0000 (20:14 +0000)
committerTony Mack <tmack@cs.princeton.edu>
Thu, 31 Jan 2008 20:14:13 +0000 (20:14 +0000)
qaapi/qa/tests/node_run_tests.py [new file with mode: 0755]

diff --git a/qaapi/qa/tests/node_run_tests.py b/qaapi/qa/tests/node_run_tests.py
new file mode 100755 (executable)
index 0000000..375c470
--- /dev/null
@@ -0,0 +1,53 @@
+#!/usr/bin/python
+import os, sys
+from Test import Test
+from qa import utils
+
+class node_run_tests(Test):
+    """
+    Attempt to copy the specified node test files onto a node using 
+    the plc root key and execute them. If no test files are specified, 
+    then all are used. 
+    """
+
+    def call(self, hostname, tests = None, root_key_path = "/etc/planetlab/root_ssh_key.rsa"):
+       
+       # Verify root key exists
+       if not os.path.isfile(root_key_path):
+           raise Exception, "no such private key file %(root_key_path)s" % locals()
+       
+       node_tests_path = self.config.node_tests_path
+       node_test_files = self.config.node_tests_path
+       # Verify test files
+       if tests:
+           invalid_tests = set(tests).difference(node_test_files)
+           if invalid_tests:
+               raise Exception, "Invalid test(s) %s. File(s) not found in %s" % \
+                               (" ".join(list(invalid_tests)), node_tests_path)
+       else:
+           tests = test_files
+
+       # Add full path to test files      
+       test_files_abs = [node_tests_path + os.sep + file for file in tests]
+       
+       # Copy files onto node
+       copy_command = "scp -i %s %s root@%s:/tmp/ " % (root_key_path, " ".join(test_files_abs), hostname)
+       if self.config.verbose:
+           utils.header(copy_command)
+       (status, output) = utils.commands(copy_command)
+
+       # execute each file individually
+       results = {}
+       exe_command = "ssh -i %(root_key_path)s root@%(hostname)s /tmp/%(file)s" 
+       for file in test_files:
+           command = exe_command % locals()
+           if self.config.verbose:
+               utils.header(command)
+           (status, output) = utils.commands(command, False)
+           results[file] = (status, output)
+       
+       return 1 
+
+if  __name__ == '__main__':
+    args = tuple(sys.argv[1:])
+    plc_remote_call()(*args)