define PLC_MAIL_FROM_ADDRESS
[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 from qa.TestScripts import TestScript, TestScripts
6 from qa.logger import Logfile
7
8 class node_run_tests(Test):
9     """
10     Attempt to download and execute the specified test scripts onto a node 
11     and execute them run them. If no test files are specified, 
12     then all are used. 
13     """
14
15     def __init__(self, config = None, logfile = None):
16         if not config: config = Config()
17         if not logfile: logfile = Logfile(config.logfile.dir + 'testscript.log')
18         Test.__init__(self, config, logfile)
19
20     def call(self, hostname, plcname, test):
21
22         node = self.config.get_node(hostname)
23         plc = self.config.get_plc(plcname)
24         node_tests = ['node_cpu_sched.py', 'pf2test.pl'] 
25         node_tests_path = self.config.node_tests_path
26         node_test_files = self.config.node_tests_path
27         tests_dir = node['tests_dir']
28
29         # Verify test files
30         if test:
31             invalid_tests = set([test]).difference(node_tests)
32             if invalid_tests:
33                 raise Exception, "Invalid test(s) %s. File(s) not found in %s" % \
34                                 (" ".join(list(invalid_tests)), node_tests_path)
35                 
36         results = {}
37         if self.config.verbose:
38             utils.header("Running %(test)s test on %(hostname)s" % locals(), logfile = self.logfile)
39         script = self.config.get_node_test(test)
40             
41         exe_pre, exe_script, exe_post = None, script['name'], None
42         if script['pre']: exe_pre = script['exe_pre']
43         if script['args']: exe_script = "%s %s" % (script['name'], script['args'])
44         if script['post']: exe_post = script['exe_post']
45
46         for command in [exe_pre, exe_script, exe_post]:
47             if command:
48                 command = "cd %(tests_dir)s/node/  && ./%(command)s" % locals()
49                 print >> node.logfile,  command
50                 print >> self.logfile, command
51   
52                 # Execute script on node
53                 (stdout, stderr) = node.popen(command, False)
54                 print >> node.logfile, "".join(stdout)   
55                 print >> self.logfile, "".join(stdout) 
56                 if self.config.verbose:
57                     utils.header(stdout, logfile = self.config.logfile)
58                 results[test] = (stdout, stderr)
59         
60         return 1 
61
62 if  __name__ == '__main__':
63     args = tuple(sys.argv[1:])
64     plc_remote_call()(*args)