blob: 2ee8694e9c7db9326ba6fc327607d1cebe0452ab [file] [log] [blame]
apw00a69a62006-10-10 08:35:33 +00001"""The ABAT harness interface
2
3The interface as required for ABAT.
4"""
5
6__author__ = """Copyright Andy Whitcroft 2006"""
7
mbligh53da18e2009-01-05 21:13:26 +00008from autotest_lib.client.bin import utils
apw7d400382007-02-28 15:23:09 +00009import os, harness, time, re
10
11def autobench_load(fn):
jadmanski0afbb632008-06-06 21:10:57 +000012 disks = re.compile(r'^\s*DATS_FREE_DISKS\s*=(.*\S)\s*$')
13 parts = re.compile(r'^\s*DATS_FREE_PARTITIONS\s*=(.*\S)\s*$')
14 modules = re.compile(r'^\s*INITRD_MODULES\s*=(.*\S)\s*$')
apw7d400382007-02-28 15:23:09 +000015
jadmanski0afbb632008-06-06 21:10:57 +000016 conf = {}
apw7d400382007-02-28 15:23:09 +000017
jadmanski0afbb632008-06-06 21:10:57 +000018 try:
19 fd = file(fn, "r")
20 except:
21 return conf
22 for ln in fd.readlines():
23 m = disks.match(ln)
24 if m:
25 val = m.groups()[0]
26 conf['disks'] = val.strip('"').split()
27 m = parts.match(ln)
28 if m:
29 val = m.groups()[0]
30 conf['partitions'] = val.strip('"').split()
31 m = modules.match(ln)
32 if m:
33 val = m.groups()[0]
34 conf['modules'] = val.strip('"').split()
35 fd.close()
apw7d400382007-02-28 15:23:09 +000036
jadmanski0afbb632008-06-06 21:10:57 +000037 return conf
apw7d400382007-02-28 15:23:09 +000038
apw00a69a62006-10-10 08:35:33 +000039
40class harness_ABAT(harness.harness):
jadmanski0afbb632008-06-06 21:10:57 +000041 """The ABAT server harness
apw00a69a62006-10-10 08:35:33 +000042
jadmanski0afbb632008-06-06 21:10:57 +000043 Properties:
44 job
45 The job object for this job
46 """
apw00a69a62006-10-10 08:35:33 +000047
Eric Li8a12e802011-02-17 14:24:13 -080048 def __init__(self, job, harness_args):
jadmanski0afbb632008-06-06 21:10:57 +000049 """
50 job
51 The job object for this job
52 """
53 self.setup(job)
apw00a69a62006-10-10 08:35:33 +000054
jadmanski0afbb632008-06-06 21:10:57 +000055 if 'ABAT_STATUS' in os.environ:
56 self.status = file(os.environ['ABAT_STATUS'], "w")
57 else:
58 self.status = None
apw00a69a62006-10-10 08:35:33 +000059
apwa6fe2012006-11-28 10:00:53 +000060
jadmanski0afbb632008-06-06 21:10:57 +000061 def __send(self, msg):
62 if self.status:
63 msg = msg.rstrip()
64 self.status.write(msg + "\n")
65 self.status.flush()
apw00a69a62006-10-10 08:35:33 +000066
67
jadmanski0afbb632008-06-06 21:10:57 +000068 def __send_status(self, code, subdir, operation, msg):
mbligh8b352852008-06-07 01:07:08 +000069 self.__send("STATUS %s %s %s %s" % (code, subdir, operation, msg))
apw4b2e4fb2007-09-25 16:52:30 +000070
71
jadmanski0afbb632008-06-06 21:10:57 +000072 def __root_device(self):
73 device = None
74 root = re.compile(r'^\S*(/dev/\S+).*\s/\s*$')
apw25cf55a2007-10-01 17:11:46 +000075
jadmanski0afbb632008-06-06 21:10:57 +000076 df = utils.system_output('df -lP')
77 for line in df.split("\n"):
78 m = root.match(line)
79 if m:
80 device = m.groups()[0]
81
82 return device
apw25cf55a2007-10-01 17:11:46 +000083
apw55dc5bd52007-03-04 16:23:06 +000084
jadmanski0afbb632008-06-06 21:10:57 +000085 def run_start(self):
86 """A run within this job is starting"""
87 self.__send_status('GOOD', '----', '----', 'run starting')
apw00a69a62006-10-10 08:35:33 +000088
jadmanski0afbb632008-06-06 21:10:57 +000089 # Load up the autobench.conf if it exists.
90 conf = autobench_load("/etc/autobench.conf")
91 if 'partitions' in conf:
mbligh4ec32c12008-10-22 21:05:04 +000092 self.job.config_set('partition.partitions',
jadmanski0afbb632008-06-06 21:10:57 +000093 conf['partitions'])
apw7d400382007-02-28 15:23:09 +000094
jadmanski0afbb632008-06-06 21:10:57 +000095 # Search the boot loader configuration for the autobench entry,
96 # and extract its args.
jadmanski0afbb632008-06-06 21:10:57 +000097 args = None
mblighc2ebea02009-10-02 00:02:33 +000098 for entry in self.job.bootloader.get_entries().itervalues():
99 if entry['title'].startswith('autobench'):
100 args = entry.get('args')
apw935903e2006-12-01 11:35:10 +0000101
jadmanski0afbb632008-06-06 21:10:57 +0000102 if args:
103 args = re.sub(r'autobench_args:.*', '', args)
104 args = re.sub(r'root=\S*', '', args)
105 args += " root=" + self.__root_device()
apw55dc5bd52007-03-04 16:23:06 +0000106
jadmanski0afbb632008-06-06 21:10:57 +0000107 self.job.config_set('boot.default_args', args)
apw935903e2006-12-01 11:35:10 +0000108
jadmanski0afbb632008-06-06 21:10:57 +0000109 # Turn off boot_once semantics.
110 self.job.config_set('boot.set_default', True)
apwf47934f2007-10-04 15:45:10 +0000111
jadmanski0afbb632008-06-06 21:10:57 +0000112 # For RedHat installs we do not load up the module.conf
113 # as they cannot be builtin. Pass them as arguments.
mbligh53da18e2009-01-05 21:13:26 +0000114 vendor = utils.get_os_vendor()
jadmanski0afbb632008-06-06 21:10:57 +0000115 if vendor in ['Red Hat', 'Fedora Core'] and 'modules' in conf:
116 args = '--allow-missing'
117 for mod in conf['modules']:
118 args += " --with " + mod
119 self.job.config_set('kernel.mkinitrd_extra_args', args)
apwe43a30b2007-09-25 16:51:30 +0000120
apw00a69a62006-10-10 08:35:33 +0000121
jadmanski0afbb632008-06-06 21:10:57 +0000122 def run_reboot(self):
123 """A run within this job is performing a reboot
124 (expect continue following reboot)
125 """
126 self.__send("REBOOT")
apw2e33c6a2006-11-02 00:22:26 +0000127
apw2e33c6a2006-11-02 00:22:26 +0000128
jadmanski0afbb632008-06-06 21:10:57 +0000129 def run_complete(self):
130 """A run within this job is completing (all done)"""
131 self.__send("DONE")
apw00a69a62006-10-10 08:35:33 +0000132
133
Eric Lid656d562011-04-20 11:48:29 -0700134 def test_status_detail(self, code, subdir, operation, msg, tag,
135 optional_fields):
jadmanski0afbb632008-06-06 21:10:57 +0000136 """A test within this job is completing (detail)"""
apw00a69a62006-10-10 08:35:33 +0000137
jadmanski0afbb632008-06-06 21:10:57 +0000138 # Send the first line with the status code as a STATUS message.
139 lines = msg.split("\n")
140 self.__send_status(code, subdir, operation, lines[0])
apw4b2e4fb2007-09-25 16:52:30 +0000141
apwf3e78442007-12-13 06:36:14 +0000142
jadmanski0afbb632008-06-06 21:10:57 +0000143 def test_status(self, msg, tag):
144 lines = msg.split("\n")
apw00a69a62006-10-10 08:35:33 +0000145
jadmanski0afbb632008-06-06 21:10:57 +0000146 # Send each line as a SUMMARY message.
147 for line in lines:
148 self.__send("SUMMARY :" + line)