5 from qa.TestScripts import TestScript, TestScripts
6 from qa.logger import Logfile
8 class node_run_tests(Test):
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,
15 def call(self, hostname, plcname, tests = None):
17 node = self.config.get_node(hostname)
18 plc = self.config.get_plc(plcname)
19 plc_ip = plc.update_ip()
20 node_tests = ['node_cpu_sched.py', 'pf2test.pl']
21 node_tests_path = self.config.node_tests_path
22 node_test_files = self.config.node_tests_path
23 tests_dir = node['tests_dir']
25 print >> node.logfile, "Running Node Tests"
27 # Create tests archive
28 (archive_filename, archive_filepath) = self.config.archive_node_tests()
29 archive_dir = archive_filename.split('.tar')[0]
31 # Copy tests archive to plc's webroot
32 plc.scp_to_webroot("%(archive_filepath)s" % locals())
34 # Download url onto node
35 url = "http://%(plc_ip)s/%(archive_filename)s" % locals()
36 node.wget(url, tests_dir)
38 # Extract tests archive
39 tarx_cmd = "cd %(tests_dir)s && tar -xzm -f %(archive_filename)s" % locals()
40 print >> node.logfile, tarx_cmd
43 # Make tests executable
44 # XX Should find a better way to do this
45 chmod_cmd = "cd %s/%s && chmod 755 %s " % (tests_dir, archive_dir, " ".join(node_tests) )
46 print >> node.logfile, chmod_cmd
51 invalid_tests = set(tests).difference(node_tests)
53 raise Exception, "Invalid test(s) %s. File(s) not found in %s" % \
54 (" ".join(list(invalid_tests)), node_tests_path)
58 #tests = self.config.get_node_tests(tests)
59 # Add full path to test files
60 #test_files_abs = [node_tests_path + os.sep + file for file in tests]
64 if self.config.verbose:
65 utils.header("Running %(test)s test on %(hostname)s" % locals(), logfile = self.config.logfile)
66 script = self.config.get_node_test(test)
68 exe_pre, exe_script, exe_post = None, script['name'], None
69 if script['pre']: exe_pre = script['exe_pre']
70 if script['args']: exe_script = "%s %s" % (script['name'], script['args'])
71 if script['post']: exe_post = script['exe_post']
73 # Create a separate logfile for this script
74 logfile = Logfile(self.config.logfile.dir + script['name'] + ".log")
75 for command in [exe_pre, exe_script, exe_post]:
77 command = "cd %(tests_dir)s/%(archive_dir)s && ./%(command)s" % locals()
78 print >> node.logfile, command
79 print >> logfile, command
81 # Execute script on node
82 (stdout, stderr) = node.popen(command, False)
83 print >> node.logfile, "".join(stdout)
84 print >> logfile, "".join(stdout)
85 if self.config.verbose:
86 utils.header(stdout, logfile = self.config.logfile)
87 results[test] = (stdout, stderr)
91 if __name__ == '__main__':
92 args = tuple(sys.argv[1:])
93 plc_remote_call()(*args)