6 class node_run_tests(Test):
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,
13 def call(self, hostname, plcname, tests = None):
15 node_tests = ['node_cpu_sched.py', 'pf2test.pl']
16 node_tests_path = self.config.node_tests_path
17 node_test_files = self.config.node_tests_path
18 archive_name = 'tests.tar.gz'
19 archive_path = '/tmp/'
20 tests_path = '/usr/share/'
23 node = self.config.get_node(hostname)
24 plc = self.config.get_plc(plcname)
25 plc_ip = plc.update_ip()
27 print >> node.logfile, "Running Node Tests"
29 # Create tests archive
30 if self.config.verbose:
31 utils.header("Updating tests archive at %(archive_path)s" % locals())
32 utils.commands("mkdir -p %(archive_path)s/%(tests_dir)s" % locals())
33 utils.commands("cp -Rf %(node_tests_path)s/* %(archive_path)s/%(tests_dir)s" % locals())
34 tar_cmd = "cd %(archive_path)s && tar -czf /%(archive_path)s/%(archive_name)s %(tests_dir)s" % locals()
35 print >> node.logfile, tar_cmd
36 (status, output) = utils.commands(tar_cmd)
38 # Copy tests archive to plc's webroot
39 if self.config.verbose:
40 utils.header("Copying tests archive onto %(plcname)s webroot" % locals())
41 plc.scp_to("%(archive_path)s/%(archive_name)s" % locals(), "/var/www/html/")
43 if self.config.verbose:
44 utils.header("Downloading tests archive onto %(hostname)s" % locals())
45 cleanup_cmd = "rm -f %(tests_path)s/%(archive_name)s" % locals()
46 print >> node.logfile, cleanup_cmd
47 node.commands(cleanup_cmd, False)
48 wget_cmd = "wget -nH -P %(tests_path)s http://%(plc_ip)s/%(archive_name)s" % locals()
49 print >> node.logfile, wget_cmd
51 node.commands(wget_cmd)
53 # Extract tests archive
54 tarx_cmd = "cd %(tests_path)s && tar -xzm -f %(archive_name)s" % locals()
55 print >> node.logfile, tarx_cmd
58 # Make tests executable
59 # XX Should find a better way to do this
60 chmod_cmd = "cd %s/tests && chmod 755 %s " % (tests_path, " ".join(node_tests) )
61 print >> node.logfile, chmod_cmd
66 invalid_tests = set(tests).difference(node_tests)
68 raise Exception, "Invalid test(s) %s. File(s) not found in %s" % \
69 (" ".join(list(invalid_tests)), node_tests_path)
73 # Add full path to test files
74 test_files_abs = [node_tests_path + os.sep + file for file in tests]
78 if self.config.verbose:
79 utils.header("Running %(test)s test on %(hostname)s" % locals())
80 command = "cd %(tests_path)s/tests && ./%(test)s" % locals()
81 print >> node.logfile, command
82 (stdout, stderr) = node.popen(command, False)
83 print >> node.logfile, "".join(stdout)
85 if self.config.verbose:
87 utils.header("%(test)s Susccessful " % locals())
89 utils.header("%(test)s Failed " % locals())
91 results[test] = (stdout, stderr)
95 if __name__ == '__main__':
96 args = tuple(sys.argv[1:])
97 plc_remote_call()(*args)