updated/fixed. -log output to node's logfile
[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, plcname, tests = None):
14         
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/'
21         tests_dir = 'tests/'
22
23         node = self.config.get_node(hostname)
24         plc = self.config.get_plc(plcname)
25         plc_ip = plc.update_ip()
26
27         print >> node.logfile, "Running Node Tests"
28         
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)
37
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/")
42
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
50         # Download tests onto      
51         node.commands(wget_cmd)
52         
53         # Extract tests archive
54         tarx_cmd = "cd %(tests_path)s && tar -xzm -f %(archive_name)s" % locals()
55         print >> node.logfile, tarx_cmd
56         node.popen(tarx_cmd)
57         
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
62         node.popen(chmod_cmd) 
63  
64         # Verify test files
65         if tests:
66             invalid_tests = set(tests).difference(node_tests)
67             if invalid_tests:
68                 raise Exception, "Invalid test(s) %s. File(s) not found in %s" % \
69                                 (" ".join(list(invalid_tests)), node_tests_path)
70         else:
71             tests = node_tests
72
73         # Add full path to test files      
74         test_files_abs = [node_tests_path + os.sep + file for file in tests]
75         
76         results = {}
77         for test 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)       
84             
85             if self.config.verbose:
86                 if status == 0:
87                     utils.header("%(test)s Susccessful " % locals())
88                 else:
89                     utils.header("%(test)s Failed " % locals())
90                 utils.header(output)
91             results[test] = (stdout, stderr)
92         
93         return 1 
94
95 if  __name__ == '__main__':
96     args = tuple(sys.argv[1:])
97     plc_remote_call()(*args)