Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Unified Diff: call_script.py

Issue 6187006: Added HWQual utility script - call_script.py (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git@master
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« archive_hwqual ('K') | « archive_hwqual ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: call_script.py
diff --git a/call_script.py b/call_script.py
new file mode 100644
index 0000000000000000000000000000000000000000..bd31cf286d3420738df2c2791af72788672d5c95
--- /dev/null
+++ b/call_script.py
@@ -0,0 +1,135 @@
+#!/usr/bin/python
kmixter1 2011/01/13 01:52:52 High level comment is that, as we discussed, this
+
+# 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.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""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!
+
+This script can be used to save results of each test run in timestamped
+unique results directory.
+
+"""
+
+import os
+import sys
+import glob
+import datetime
kmixter1 2011/01/13 01:52:52 abc order
ruchic 2011/01/18 23:52:31 Done.
+
+class ArgumentError(Exception):
+ def __init__(self, value):
+ self.value = value
+ def __str__(self):
+ return repr(self.value)
+
+def connectRemoteMachine(machine_ip):
+ os.system('ssh-add testing_rsa')
+ 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
+ username = open('/tmp/user_name', 'r').readline().strip()
+
+ # Removing the machine IP entry from known hosts to avoid identity clash.
+ print "Removing machine IP entry from known hosts to avoid identity clash."
+ host_list = open('/home/%s/.ssh/known_hosts' % username, 'r').readlines()
+ index = 0
+ for host in host_list:
+ if machine_ip in host:
+ del host_list[index]
+ break
+ index += 1
+
+ open('/home/%s/.ssh/known_hosts' % username, 'w').writelines(host_list)
+
+ # Starting ssh connection to remote test machine.
+ print "Starting ssh connection to remote test machine."
+ os.system('ssh root@%s true; echo $? > ssh_result_file' % machine_ip)
+ ssh_result = open('ssh_result_file', 'r').read()
+ print "Status of ssh connection to remote machine : %s" % ssh_result
+
+ if ssh_result.strip() != '0':
+ print "Ssh connection to remote test machine FAILED. Exiting the test."
+ sys.exit()
+
+def checkTestResult(result_path):
+ # Checking the results for any FAIL or ERROR messages in status log.
+ status_file = open('%s/status' % result_path, 'r').readlines()
+ for line in status_file:
+ 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.
+ # Grabbing the results directory.
+ log_name = "%s.tar.bz2" % result_path
+ os.system('tar cjf %s %s' % (log_name, result_path))
+ print "INFO : Logs for the failed test at : %s" % log_name
+ break
+
+def triggerTest(test_name, machine_ip):
+ test_path = ""
+ # Creating unique time stamped result folder name.
+ current_time = datetime.datetime.now()
+ result_name = "results." + test_name + \
+ current_time.strftime("_%d-%m-%y_%H:%M")
+
+ # Setting the test path location based on the test_name.
+ suite_path = "./autotest/client/site_tests/suite_HWQual"
+ filenames = glob.glob(os.path.join(suite_path, "control.%s" % test_name))
+ for filename in filenames:
+ if filename == "%s/control.%s" % (suite_path, test_name):
+ test_path = filename
+ break
+
+ # Looking for test_name under site_tests if not present under suite_HWQual
+ if test_path == "":
+ test_path = "./autotest/client/site_tests/%s/control" % test_name
+
+ # Making the call to HWQual test.
+ 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.
+ 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
+ (result_name, machine_ip, test_path))
+
+ # Displaying results on test completion.
+ os.system('./generate_test_report ./autotest/%s' % result_name)
+
+ # Checking test results and grabbing logs for failing tests.
+ checkTestResult("./autotest/%s" % result_name)
+ print "INFO : Results of test run at : ./autotest/%s" % result_name
+
+def main(argv):
+ arg_ip, arg_testname = "", ""
+ # Checking the arguments for help, machine ip and test name.
+ try:
+ for i in argv:
+ 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.
+ raise ArgumentError(-1)
+ elif i.startswith("test="):
+ arg_testname = i[5:]
+ if not arg_testname:
+ raise ArgumentError(1)
+ print "HWQual test to trigger : %s" % arg_testname
+ elif i.startswith("ip="):
+ arg_ip = i[3:]
+ if not arg_ip:
+ raise ArgumentError(1)
+ print "Remote test machine IP : %s" % arg_ip
+
+ # Checking for presence of both ip and test parameters.
+ if (arg_ip == "") or (arg_testname == ""):
+ raise ArgumentError(0)
+
+ # Setting up ssh connection to remote machine.
+ connectRemoteMachine(arg_ip)
+
+ # Triggerring the HWQual test and result handling.
+ triggerTest(arg_testname, arg_ip)
+
+ except ArgumentError as e:
+ if e.value == 0:
+ print "FAIL : Argument missing"
+ elif e.value == 1:
+ print "FAIL : Blank values are not accepted for arguments."
+ print "To execute this script, pass 'ip' of remote machine to run test" \
+ " on and 'test' name-"
+ print " python callscript.py ip=<IP address of machine> test=<test name>"
+ sys.exit()
+
+
+if __name__ == '__main__':
+ main(sys.argv)
+
« archive_hwqual ('K') | « archive_hwqual ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698