OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python | |
kmixter1
2011/01/13 01:52:52
High level comment is that, as we discussed, this
| |
2 | |
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | |
kmixter1
2011/01/13 01:52:52
2011
ruchic
2011/01/18 23:52:31
Done.
| |
4 # Use of this source code is governed by a BSD-style license that can be | |
5 # found in the LICENSE file. | |
6 | |
7 """Script to run client or server tests on a live remote image. | |
kmixter1
2011/01/13 01:52:52
call_script.py is a little too generic. How about
ruchic
2011/01/18 23:52:31
Done. Changed the name to call_autoserv.py Thanks!
| |
8 | |
9 This script can be used to save results of each test run in timestamped | |
10 unique results directory. | |
11 | |
12 """ | |
13 | |
14 import os | |
15 import sys | |
16 import glob | |
17 import datetime | |
kmixter1
2011/01/13 01:52:52
abc order
ruchic
2011/01/18 23:52:31
Done.
| |
18 | |
19 class ArgumentError(Exception): | |
20 def __init__(self, value): | |
21 self.value = value | |
22 def __str__(self): | |
23 return repr(self.value) | |
24 | |
25 def connectRemoteMachine(machine_ip): | |
26 os.system('ssh-add testing_rsa') | |
27 os.system('echo $USER > /tmp/user_name') | |
kmixter1
2011/01/13 01:52:52
username = os.environ['USER']?
ruchic
2011/01/18 23:52:31
Done. Thanks for the tip
| |
28 username = open('/tmp/user_name', 'r').readline().strip() | |
29 | |
30 # Removing the machine IP entry from known hosts to avoid identity clash. | |
31 print "Removing machine IP entry from known hosts to avoid identity clash." | |
32 host_list = open('/home/%s/.ssh/known_hosts' % username, 'r').readlines() | |
33 index = 0 | |
34 for host in host_list: | |
35 if machine_ip in host: | |
36 del host_list[index] | |
37 break | |
38 index += 1 | |
39 | |
40 open('/home/%s/.ssh/known_hosts' % username, 'w').writelines(host_list) | |
41 | |
42 # Starting ssh connection to remote test machine. | |
43 print "Starting ssh connection to remote test machine." | |
44 os.system('ssh root@%s true; echo $? > ssh_result_file' % machine_ip) | |
45 ssh_result = open('ssh_result_file', 'r').read() | |
46 print "Status of ssh connection to remote machine : %s" % ssh_result | |
47 | |
48 if ssh_result.strip() != '0': | |
49 print "Ssh connection to remote test machine FAILED. Exiting the test." | |
50 sys.exit() | |
51 | |
52 def checkTestResult(result_path): | |
53 # Checking the results for any FAIL or ERROR messages in status log. | |
54 status_file = open('%s/status' % result_path, 'r').readlines() | |
55 for line in status_file: | |
56 if ("FAIL" in line) or ("ERROR" in line): | |
kmixter1
2011/01/13 01:52:52
Suggest running generate_test_report and using its
ruchic
2011/01/18 23:52:31
Done.
| |
57 # Grabbing the results directory. | |
58 log_name = "%s.tar.bz2" % result_path | |
59 os.system('tar cjf %s %s' % (log_name, result_path)) | |
60 print "INFO : Logs for the failed test at : %s" % log_name | |
61 break | |
62 | |
63 def triggerTest(test_name, machine_ip): | |
64 test_path = "" | |
65 # Creating unique time stamped result folder name. | |
66 current_time = datetime.datetime.now() | |
67 result_name = "results." + test_name + \ | |
68 current_time.strftime("_%d-%m-%y_%H:%M") | |
69 | |
70 # Setting the test path location based on the test_name. | |
71 suite_path = "./autotest/client/site_tests/suite_HWQual" | |
72 filenames = glob.glob(os.path.join(suite_path, "control.%s" % test_name)) | |
73 for filename in filenames: | |
74 if filename == "%s/control.%s" % (suite_path, test_name): | |
75 test_path = filename | |
76 break | |
77 | |
78 # Looking for test_name under site_tests if not present under suite_HWQual | |
79 if test_path == "": | |
80 test_path = "./autotest/client/site_tests/%s/control" % test_name | |
81 | |
82 # Making the call to HWQual test. | |
83 print "INFO : Starting the HWQual test : %s" % test_path | |
kmixter1
2011/01/13 01:52:52
May want to consider import logging for these.
ruchic
2011/01/18 23:52:31
Done.
| |
84 os.system('./autotest/server/autoserv -r ./autotest/%s -m %s -c %s' % \ | |
kmixter1
2011/01/13 01:52:52
-c assumes the test is a client test. Probably wo
ruchic
2011/01/18 23:52:31
Changed the code to support server tests also.
On
| |
85 (result_name, machine_ip, test_path)) | |
86 | |
87 # Displaying results on test completion. | |
88 os.system('./generate_test_report ./autotest/%s' % result_name) | |
89 | |
90 # Checking test results and grabbing logs for failing tests. | |
91 checkTestResult("./autotest/%s" % result_name) | |
92 print "INFO : Results of test run at : ./autotest/%s" % result_name | |
93 | |
94 def main(argv): | |
95 arg_ip, arg_testname = "", "" | |
96 # Checking the arguments for help, machine ip and test name. | |
97 try: | |
98 for i in argv: | |
99 if i in ["-h", "--help", "-?"]: | |
kmixter1
2011/01/13 01:52:52
I would suggest using import optparse for arg pars
ruchic
2011/01/18 23:52:31
Done.
| |
100 raise ArgumentError(-1) | |
101 elif i.startswith("test="): | |
102 arg_testname = i[5:] | |
103 if not arg_testname: | |
104 raise ArgumentError(1) | |
105 print "HWQual test to trigger : %s" % arg_testname | |
106 elif i.startswith("ip="): | |
107 arg_ip = i[3:] | |
108 if not arg_ip: | |
109 raise ArgumentError(1) | |
110 print "Remote test machine IP : %s" % arg_ip | |
111 | |
112 # Checking for presence of both ip and test parameters. | |
113 if (arg_ip == "") or (arg_testname == ""): | |
114 raise ArgumentError(0) | |
115 | |
116 # Setting up ssh connection to remote machine. | |
117 connectRemoteMachine(arg_ip) | |
118 | |
119 # Triggerring the HWQual test and result handling. | |
120 triggerTest(arg_testname, arg_ip) | |
121 | |
122 except ArgumentError as e: | |
123 if e.value == 0: | |
124 print "FAIL : Argument missing" | |
125 elif e.value == 1: | |
126 print "FAIL : Blank values are not accepted for arguments." | |
127 print "To execute this script, pass 'ip' of remote machine to run test" \ | |
128 " on and 'test' name-" | |
129 print " python callscript.py ip=<IP address of machine> test=<test name>" | |
130 sys.exit() | |
131 | |
132 | |
133 if __name__ == '__main__': | |
134 main(sys.argv) | |
135 | |
OLD | NEW |