virt.virt_test_utils: run_autotest - 'tar' needs relative paths to strip the leading '/'
[autotest-zwu.git] / client / bin / autotestd
blob3d4552af558e7627888e2f2908ddc6b531912398
1 #!/usr/bin/python
3 import common
4 import sys, os, subprocess, fcntl
7 bindir = os.path.dirname(__file__)
8 autotest = os.path.join(bindir, 'autotest')
10 logdir = sys.argv[1]
13 # We want to simulate the behaviour of autotest_client, where fd3 would be
14 # routed to stderr and fd1 & fd2 to stdout
16 # HACK: grab fd3 for now
17 os.dup2(2, 3)
19 # open up log files to use for std*
20 stdout = open(os.path.join(logdir, 'stdout'), 'a', 0)
21 stderr = open(os.path.join(logdir, 'stderr'), 'a', 0)
23 # set up the file descriptors now, simulating the old behaviour
24 os.dup2(stdout.fileno(), 1)
25 os.dup2(stdout.fileno(), 2)
26 os.dup2(stderr.fileno(), 3)
28 # we don't need the file objects any more
29 stdout.close()
30 stderr.close()
33 args = [autotest] + sys.argv[2:]
34 if '-H' not in args:
35 args[1:1] = ['-H', 'autoserv']
36 cmd = ' '.join(args)
38 # open up a log file for saving off the exit code
39 exit_file = open(os.path.join(logdir, 'exit_code'), 'w', 0)
40 fcntl.flock(exit_file, fcntl.LOCK_EX)
42 # touch a 'started' file to indicate we've been initialized
43 open(os.path.join(logdir, 'started'), 'w').close()
45 # run the actual autotest client and write the exit code into the log file
46 exit_code = subprocess.call(cmd, shell=True)
47 exit_file.write('%+04d' % exit_code)
48 exit_file.flush()
49 fcntl.flock(exit_file, fcntl.LOCK_UN)
50 exit_file.close()