simplify
[tests.git] / qaapi / qa / tests / node_run_tests.py
1 #!/usr/bin/python
2 import os, sys
3 from Test import Test
4 from qa import utils
5
6 class node_run_tests(Test):
7     """
8     Attempt to copy the specified node test files onto a node using 
9     the plc root key and execute them. If no test files are specified, 
10     then all are used. 
11     """
12
13     def call(self, hostname, tests = None, root_key_path = "/etc/planetlab/root_ssh_key.rsa"):
14         
15         # Verify root key exists
16         if not os.path.isfile(root_key_path):
17             raise Exception, "no such private key file %(root_key_path)s" % locals()
18         
19         node_tests_path = self.config.node_tests_path
20         node_test_files = self.config.node_tests_path
21         # Verify test files
22         if tests:
23             invalid_tests = set(tests).difference(node_test_files)
24             if invalid_tests:
25                 raise Exception, "Invalid test(s) %s. File(s) not found in %s" % \
26                                 (" ".join(list(invalid_tests)), node_tests_path)
27         else:
28             tests = test_files
29
30         # Add full path to test files      
31         test_files_abs = [node_tests_path + os.sep + file for file in tests]
32         
33         # Copy files onto node
34         copy_command = "scp -i %s %s root@%s:/tmp/ " % (root_key_path, " ".join(test_files_abs), hostname)
35         if self.config.verbose:
36             utils.header(copy_command)
37         (status, output) = utils.commands(copy_command)
38
39         # execute each file individually
40         results = {}
41         exe_command = "ssh -i %(root_key_path)s root@%(hostname)s /tmp/%(file)s" 
42         for file in test_files:
43             command = exe_command % locals()
44             if self.config.verbose:
45                 utils.header(command)
46             (status, output) = utils.commands(command, False)
47             results[file] = (status, output)
48         
49         return 1 
50
51 if  __name__ == '__main__':
52     args = tuple(sys.argv[1:])
53     plc_remote_call()(*args)