mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # Copyright 2007 Google Inc. Released under the GPL v2 |
| 4 | |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 5 | """ |
| 6 | This module defines the Autotest class |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 7 | |
| 8 | Autotest: software to run tests automatically |
| 9 | """ |
| 10 | |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 11 | __author__ = """ |
| 12 | mbligh@google.com (Martin J. Bligh), |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 13 | poirier@google.com (Benjamin Poirier), |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 14 | stutsman@google.com (Ryan Stutsman) |
| 15 | """ |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 16 | |
| 17 | import re |
| 18 | import os |
| 19 | import sys |
| 20 | import subprocess |
| 21 | import urllib |
| 22 | import tempfile |
| 23 | import shutil |
mbligh | 0e4613b | 2007-10-29 16:55:07 +0000 | [diff] [blame] | 24 | import time |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 25 | |
| 26 | import installable_object |
| 27 | import errors |
| 28 | import utils |
| 29 | |
| 30 | |
| 31 | AUTOTEST_SVN = 'svn://test.kernel.org/autotest/trunk/client' |
| 32 | AUTOTEST_HTTP = 'http://test.kernel.org/svn/autotest/trunk/client' |
| 33 | |
| 34 | # Timeouts for powering down and up respectively |
| 35 | HALT_TIME = 300 |
mbligh | 07c1eac | 2007-11-05 18:39:29 +0000 | [diff] [blame] | 36 | BOOT_TIME = 1800 |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 37 | |
| 38 | |
| 39 | class AutotestRunError(errors.AutoservRunError): |
| 40 | pass |
| 41 | |
mbligh | 0e4613b | 2007-10-29 16:55:07 +0000 | [diff] [blame] | 42 | class AutotestTimeoutError(errors.AutoservRunError): |
| 43 | """This exception is raised when an autotest test exceeds the timeout |
| 44 | parameter passed to run_timed_test and is killed. |
| 45 | """ |
| 46 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 47 | |
| 48 | class Autotest(installable_object.InstallableObject): |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 49 | """ |
| 50 | This class represents the Autotest program. |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 51 | |
| 52 | Autotest is used to run tests automatically and collect the results. |
| 53 | It also supports profilers. |
| 54 | |
| 55 | Implementation details: |
| 56 | This is a leaf class in an abstract class hierarchy, it must |
| 57 | implement the unimplemented methods in parent classes. |
| 58 | """ |
mbligh | dd81ef0 | 2007-08-10 01:18:40 +0000 | [diff] [blame] | 59 | def __init__(self, host = None): |
| 60 | self.host = host |
mbligh | 9133490 | 2007-09-28 01:47:59 +0000 | [diff] [blame] | 61 | self.got = False |
| 62 | self.installed = False |
mbligh | 9708f73 | 2007-10-18 03:18:54 +0000 | [diff] [blame] | 63 | self.serverdir = utils.get_server_dir() |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 64 | super(Autotest, self).__init__() |
mbligh | c8949b8 | 2007-07-23 16:33:58 +0000 | [diff] [blame] | 65 | |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 66 | |
mbligh | dd81ef0 | 2007-08-10 01:18:40 +0000 | [diff] [blame] | 67 | def install(self, host = None): |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 68 | """ |
| 69 | Install autotest. If get() was not called previously, an |
mbligh | c8949b8 | 2007-07-23 16:33:58 +0000 | [diff] [blame] | 70 | attempt will be made to install from the autotest svn |
| 71 | repository. |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 72 | |
| 73 | Args: |
| 74 | host: a Host instance on which autotest will be |
| 75 | installed |
| 76 | |
| 77 | Raises: |
| 78 | AutoservError: if a tarball was not specified and |
| 79 | the target host does not have svn installed in its path |
mbligh | c8949b8 | 2007-07-23 16:33:58 +0000 | [diff] [blame] | 80 | |
| 81 | TODO(poirier): check dependencies |
| 82 | autotest needs: |
| 83 | bzcat |
| 84 | liboptdev (oprofile) |
| 85 | binutils-dev (oprofile) |
| 86 | make |
mbligh | 629e39e | 2007-08-10 19:32:00 +0000 | [diff] [blame] | 87 | psutils (netperf) |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 88 | """ |
mbligh | dd81ef0 | 2007-08-10 01:18:40 +0000 | [diff] [blame] | 89 | if not host: |
| 90 | host = self.host |
mbligh | 9133490 | 2007-09-28 01:47:59 +0000 | [diff] [blame] | 91 | if not self.got: |
| 92 | self.get() |
mbligh | 7386abc | 2007-08-31 08:57:56 +0000 | [diff] [blame] | 93 | host.ensure_up() |
mbligh | 9133490 | 2007-09-28 01:47:59 +0000 | [diff] [blame] | 94 | host.setup() |
mbligh | b84a1cf | 2007-08-09 23:08:13 +0000 | [diff] [blame] | 95 | print "Installing autotest on %s" % host.hostname |
mbligh | 40f122a | 2007-11-03 23:08:46 +0000 | [diff] [blame] | 96 | |
| 97 | autodir = _get_autodir(host) |
| 98 | host.run('mkdir -p "%s"' % utils.sh_escape(autodir)) |
| 99 | |
| 100 | if getattr(host, 'site_install_autotest', None): |
| 101 | if host.site_install_autotest(): |
| 102 | self.installed = True |
| 103 | return |
| 104 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 105 | # try to install from file or directory |
mbligh | c8949b8 | 2007-07-23 16:33:58 +0000 | [diff] [blame] | 106 | if self.source_material: |
| 107 | if os.path.isdir(self.source_material): |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 108 | # Copy autotest recursively |
mbligh | 40f122a | 2007-11-03 23:08:46 +0000 | [diff] [blame] | 109 | host.send_file(self.source_material, autodir) |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 110 | else: |
| 111 | # Copy autotest via tarball |
| 112 | raise "Not yet implemented!" |
mbligh | 9133490 | 2007-09-28 01:47:59 +0000 | [diff] [blame] | 113 | print "Installation of autotest completed" |
| 114 | self.installed = True |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 115 | return |
mbligh | 9133490 | 2007-09-28 01:47:59 +0000 | [diff] [blame] | 116 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 117 | # if that fails try to install using svn |
| 118 | if utils.run('which svn').exit_status: |
| 119 | raise AutoservError('svn not found in path on \ |
| 120 | target machine: %s' % host.name) |
| 121 | try: |
| 122 | host.run('svn checkout %s %s' % |
mbligh | 3850f89 | 2007-11-05 22:49:24 +0000 | [diff] [blame] | 123 | (AUTOTEST_SVN, autodir)) |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 124 | except errors.AutoservRunError, e: |
| 125 | host.run('svn checkout %s %s' % |
mbligh | 3850f89 | 2007-11-05 22:49:24 +0000 | [diff] [blame] | 126 | (AUTOTEST_HTTP, autodir)) |
mbligh | 9133490 | 2007-09-28 01:47:59 +0000 | [diff] [blame] | 127 | print "Installation of autotest completed" |
| 128 | self.installed = True |
| 129 | |
| 130 | |
| 131 | def get(self, location = None): |
| 132 | if not location: |
| 133 | location = os.path.join(self.serverdir, '../client') |
| 134 | location = os.path.abspath(location) |
mbligh | 8fc0e5a | 2007-10-11 18:39:03 +0000 | [diff] [blame] | 135 | # If there's stuff run on our client directory already, it |
| 136 | # can cause problems. Try giving it a quick clean first. |
| 137 | cwd = os.getcwd() |
| 138 | os.chdir(location) |
| 139 | os.system('tools/make_clean') |
| 140 | os.chdir(cwd) |
mbligh | 9133490 | 2007-09-28 01:47:59 +0000 | [diff] [blame] | 141 | super(Autotest, self).get(location) |
| 142 | self.got = True |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 143 | |
| 144 | |
mbligh | 0e4613b | 2007-10-29 16:55:07 +0000 | [diff] [blame] | 145 | def run(self, control_file, results_dir = '.', host = None, |
| 146 | timeout=None): |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 147 | """ |
| 148 | Run an autotest job on the remote machine. |
mbligh | c8949b8 | 2007-07-23 16:33:58 +0000 | [diff] [blame] | 149 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 150 | Args: |
| 151 | control_file: an open file-like-obj of the control file |
| 152 | results_dir: a str path where the results should be stored |
| 153 | on the local filesystem |
| 154 | host: a Host instance on which the control file should |
| 155 | be run |
| 156 | |
| 157 | Raises: |
| 158 | AutotestRunError: if there is a problem executing |
| 159 | the control file |
| 160 | """ |
mbligh | 55a2a3b | 2007-09-30 01:27:55 +0000 | [diff] [blame] | 161 | results_dir = os.path.abspath(results_dir) |
mbligh | dd81ef0 | 2007-08-10 01:18:40 +0000 | [diff] [blame] | 162 | if not host: |
| 163 | host = self.host |
mbligh | 9133490 | 2007-09-28 01:47:59 +0000 | [diff] [blame] | 164 | if not self.installed: |
mbligh | 7fdd169 | 2007-10-02 19:16:53 +0000 | [diff] [blame] | 165 | self.install(host) |
mbligh | 9133490 | 2007-09-28 01:47:59 +0000 | [diff] [blame] | 166 | |
mbligh | dbe4a38 | 2007-07-26 19:41:28 +0000 | [diff] [blame] | 167 | host.ensure_up() |
| 168 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 169 | atrun = _Run(host, results_dir) |
mbligh | e4f0151 | 2007-08-10 01:42:50 +0000 | [diff] [blame] | 170 | try: |
| 171 | atrun.verify_machine() |
| 172 | except: |
| 173 | print "Verify machine failed on %s. Reinstalling" % \ |
| 174 | host.hostname |
| 175 | self.install(host) |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 176 | atrun.verify_machine() |
| 177 | debug = os.path.join(results_dir, 'debug') |
mbligh | 55a2a3b | 2007-09-30 01:27:55 +0000 | [diff] [blame] | 178 | try: |
| 179 | os.makedirs(debug) |
| 180 | except: |
| 181 | pass |
mbligh | c8949b8 | 2007-07-23 16:33:58 +0000 | [diff] [blame] | 182 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 183 | # Ready .... Aim .... |
| 184 | host.run('rm -f ' + atrun.remote_control_file) |
| 185 | host.run('rm -f ' + atrun.remote_control_file + '.state') |
mbligh | c8949b8 | 2007-07-23 16:33:58 +0000 | [diff] [blame] | 186 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 187 | # Copy control_file to remote_control_file on the host |
| 188 | tmppath = utils.get(control_file) |
| 189 | host.send_file(tmppath, atrun.remote_control_file) |
| 190 | os.remove(tmppath) |
mbligh | 0e4613b | 2007-10-29 16:55:07 +0000 | [diff] [blame] | 191 | |
| 192 | timeout_exc = None |
| 193 | try: |
| 194 | atrun.execute_control(timeout=timeout) |
| 195 | except AutotestTimeoutError, exc: |
| 196 | # on timeout, fall though and try to grab results, |
| 197 | # and then reraise |
| 198 | timeout_exc = exc |
| 199 | |
| 200 | # try to retrive results, even if a timeout occured |
| 201 | results = os.path.join(atrun.autodir, 'results', |
| 202 | 'default') |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 203 | # Copy all dirs in default to results_dir |
| 204 | host.get_file(results + '/', results_dir) |
| 205 | |
mbligh | 0e4613b | 2007-10-29 16:55:07 +0000 | [diff] [blame] | 206 | if timeout_exc: |
| 207 | raise timeout_exc |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 208 | |
mbligh | 0e4613b | 2007-10-29 16:55:07 +0000 | [diff] [blame] | 209 | |
| 210 | def run_timed_test(self, test_name, results_dir = '.', host = None, |
| 211 | timeout=None, *args, **dargs): |
mbligh | d54832b | 2007-07-25 16:46:56 +0000 | [diff] [blame] | 212 | """ |
| 213 | Assemble a tiny little control file to just run one test, |
| 214 | and run it as an autotest client-side test |
| 215 | """ |
mbligh | dd81ef0 | 2007-08-10 01:18:40 +0000 | [diff] [blame] | 216 | if not host: |
| 217 | host = self.host |
mbligh | 9133490 | 2007-09-28 01:47:59 +0000 | [diff] [blame] | 218 | if not self.installed: |
mbligh | 7fdd169 | 2007-10-02 19:16:53 +0000 | [diff] [blame] | 219 | self.install(host) |
mbligh | 271d5af | 2007-08-10 19:54:01 +0000 | [diff] [blame] | 220 | opts = ["%s=%s" % (o[0], repr(o[1])) for o in dargs.items()] |
| 221 | cmd = ", ".join([repr(test_name)] + map(repr, args) + opts) |
mbligh | f1c5284 | 2007-10-16 15:21:38 +0000 | [diff] [blame] | 222 | control = "job.run_test(%s)\n" % cmd |
mbligh | 0e4613b | 2007-10-29 16:55:07 +0000 | [diff] [blame] | 223 | self.run(control, results_dir, host, timeout=timeout) |
| 224 | |
| 225 | |
| 226 | def run_test(self, test_name, results_dir = '.', host = None, |
| 227 | *args, **dargs): |
| 228 | self.run_timed_test(test_name, results_dir, host, None, |
| 229 | *args, **dargs) |
mbligh | d54832b | 2007-07-25 16:46:56 +0000 | [diff] [blame] | 230 | |
| 231 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 232 | class _Run(object): |
| 233 | """ |
| 234 | Represents a run of autotest control file. This class maintains |
| 235 | all the state necessary as an autotest control file is executed. |
| 236 | |
| 237 | It is not intended to be used directly, rather control files |
| 238 | should be run using the run method in Autotest. |
| 239 | """ |
| 240 | def __init__(self, host, results_dir): |
| 241 | self.host = host |
| 242 | self.results_dir = results_dir |
mbligh | cc53b35 | 2007-10-24 21:15:30 +0000 | [diff] [blame] | 243 | self.env = host.env |
mbligh | c8949b8 | 2007-07-23 16:33:58 +0000 | [diff] [blame] | 244 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 245 | self.autodir = _get_autodir(self.host) |
| 246 | self.remote_control_file = os.path.join(self.autodir, 'control') |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 247 | |
| 248 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 249 | def verify_machine(self): |
| 250 | binary = os.path.join(self.autodir, 'bin/autotest') |
mbligh | dd81ef0 | 2007-08-10 01:18:40 +0000 | [diff] [blame] | 251 | try: |
| 252 | self.host.run('ls ' + binary) |
| 253 | except: |
mbligh | 8d7e347 | 2007-08-10 01:35:18 +0000 | [diff] [blame] | 254 | raise "Autotest does not appear to be installed" |
| 255 | tmpdir = os.path.join(self.autodir, 'tmp') |
| 256 | self.host.run('umount %s' % tmpdir, ignore_status=True) |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 257 | |
| 258 | |
mbligh | 0e4613b | 2007-10-29 16:55:07 +0000 | [diff] [blame] | 259 | def __execute_section(self, section, timeout): |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 260 | print "Executing %s/bin/autotest %s/control phase %d" % \ |
| 261 | (self.autodir, self.autodir, |
| 262 | section) |
| 263 | logfile = "%s/debug/client.log.%d" % (self.results_dir, |
| 264 | section) |
mbligh | d2fc50f | 2007-10-23 22:38:00 +0000 | [diff] [blame] | 265 | client_log = open(logfile, 'w', 0) |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 266 | if section > 0: |
| 267 | cont = '-c' |
| 268 | else: |
| 269 | cont = '' |
| 270 | client = os.path.join(self.autodir, 'bin/autotest_client') |
| 271 | ssh = "ssh -q %s@%s" % (self.host.user, self.host.hostname) |
mbligh | cc53b35 | 2007-10-24 21:15:30 +0000 | [diff] [blame] | 272 | env = ' '.join(['='.join(i) for i in self.env.iteritems()]) |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 273 | cmd = "%s %s %s" % (client, cont, self.remote_control_file) |
mbligh | 0e4613b | 2007-10-29 16:55:07 +0000 | [diff] [blame] | 274 | full_cmd = "%s '%s %s'" % (ssh, env, cmd) |
| 275 | print full_cmd |
| 276 | |
mbligh | d2fc50f | 2007-10-23 22:38:00 +0000 | [diff] [blame] | 277 | status_log_file = os.path.join(self.results_dir, 'status.log') |
| 278 | status_log = open(status_log_file, 'a', 0) |
mbligh | 0e4613b | 2007-10-29 16:55:07 +0000 | [diff] [blame] | 279 | |
| 280 | class StdErrRedirector(object): |
| 281 | """Partial file object to write to both stdout and |
| 282 | the status log file. We only implement those methods |
| 283 | utils.run() actually calls. |
| 284 | """ |
| 285 | def write(self, str): |
| 286 | sys.stdout.write(str) |
| 287 | status_log.write(str) |
| 288 | |
| 289 | def flush(self): |
| 290 | sys.stdout.flush() |
| 291 | status_log.flush() |
| 292 | |
| 293 | result = utils.run(full_cmd, ignore_status=True, |
| 294 | timeout=timeout, |
| 295 | stdout_tee=client_log, |
| 296 | stderr_tee=StdErrRedirector()) |
| 297 | if not result.stderr: |
| 298 | raise AutotestRunError( |
| 299 | "execute_section: %s failed to return anything\n" |
| 300 | "stdout:%s\n" % (full_cmd, result.stdout)) |
| 301 | |
| 302 | last_line = result.stderr.strip().rsplit('\n', 1).pop() |
| 303 | return last_line |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 304 | |
| 305 | |
mbligh | 0e4613b | 2007-10-29 16:55:07 +0000 | [diff] [blame] | 306 | def execute_control(self, timeout=None): |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 307 | section = 0 |
mbligh | 0e4613b | 2007-10-29 16:55:07 +0000 | [diff] [blame] | 308 | time_left = None |
| 309 | if timeout: |
| 310 | end_time = time.time() + timeout |
| 311 | time_left = end_time - time.time() |
| 312 | while not timeout or time_left > 0: |
| 313 | last = self.__execute_section(section, time_left) |
| 314 | if timeout: |
| 315 | time_left = end_time - time.time() |
| 316 | if time_left <= 0: |
| 317 | break |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 318 | section += 1 |
| 319 | if re.match('DONE', last): |
| 320 | print "Client complete" |
| 321 | return |
| 322 | elif re.match('REBOOT', last): |
| 323 | print "Client is rebooting" |
| 324 | print "Waiting for client to halt" |
| 325 | if not self.host.wait_down(HALT_TIME): |
| 326 | raise AutotestRunError("%s \ |
| 327 | failed to shutdown after %ds" % |
mbligh | c8949b8 | 2007-07-23 16:33:58 +0000 | [diff] [blame] | 328 | (self.host.hostname, |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 329 | HALT_TIME)) |
| 330 | print "Client down, waiting for restart" |
| 331 | if not self.host.wait_up(BOOT_TIME): |
| 332 | # since reboot failed |
| 333 | # hardreset the machine once if possible |
| 334 | # before failing this control file |
mbligh | ba81c68 | 2007-10-25 15:35:59 +0000 | [diff] [blame] | 335 | print "Hardresetting %s" % ( |
| 336 | self.host.hostname,) |
| 337 | try: |
| 338 | self.host.hardreset(wait=False) |
| 339 | except errors.AutoservUnsupportedError: |
| 340 | print "Hardreset unsupported on %s" % ( |
| 341 | self.host.hostname,) |
mbligh | c8949b8 | 2007-07-23 16:33:58 +0000 | [diff] [blame] | 342 | raise AutotestRunError("%s failed to " |
| 343 | "boot after %ds" % ( |
| 344 | self.host.hostname, |
| 345 | BOOT_TIME,)) |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 346 | continue |
mbligh | c8949b8 | 2007-07-23 16:33:58 +0000 | [diff] [blame] | 347 | raise AutotestRunError("Aborting - unknown " |
| 348 | "return code: %s\n" % last) |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 349 | |
mbligh | 0e4613b | 2007-10-29 16:55:07 +0000 | [diff] [blame] | 350 | # should only get here if we timed out |
| 351 | assert timeout |
| 352 | raise AutotestTimeoutError() |
| 353 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 354 | |
| 355 | def _get_autodir(host): |
| 356 | try: |
| 357 | atdir = host.run( |
mbligh | c8949b8 | 2007-07-23 16:33:58 +0000 | [diff] [blame] | 358 | 'grep "autodir *=" /etc/autotest.conf').stdout.strip() |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 359 | if atdir: |
| 360 | m = re.search(r'autodir *= *[\'"]?([^\'"]*)[\'"]?', |
| 361 | atdir) |
| 362 | return m.group(1) |
| 363 | except errors.AutoservRunError: |
| 364 | pass |
| 365 | for path in ['/usr/local/autotest', '/home/autotest']: |
| 366 | try: |
| 367 | host.run('ls ' + path) |
| 368 | return path |
| 369 | except errors.AutoservRunError: |
| 370 | pass |
| 371 | raise AutotestRunError("Cannot figure out autotest directory") |