blob: be50aa72cfec0da2419d5740ef26e0b276aa5799 [file] [log] [blame]
mbligh7f7dbd32007-08-31 14:46:26 +00001"""The standalone harness interface
2
3The default interface as required for the standalone reboot helper.
4"""
5
6__author__ = """Copyright Andy Whitcroft 2007"""
7
Eric Lid656d562011-04-20 11:48:29 -07008from autotest_lib.client.common_lib import utils, error
showardb18134f2009-03-20 20:52:18 +00009import os, harness, shutil, logging
mbligh7f7dbd32007-08-31 14:46:26 +000010
11class harness_standalone(harness.harness):
jadmanski0afbb632008-06-06 21:10:57 +000012 """The standalone server harness
mbligh7f7dbd32007-08-31 14:46:26 +000013
jadmanski0afbb632008-06-06 21:10:57 +000014 Properties:
15 job
16 The job object for this job
17 """
mbligh7f7dbd32007-08-31 14:46:26 +000018
Eric Li8a12e802011-02-17 14:24:13 -080019 def __init__(self, job, harness_args):
jadmanski0afbb632008-06-06 21:10:57 +000020 """
21 job
22 The job object for this job
23 """
24 self.autodir = os.path.abspath(os.environ['AUTODIR'])
25 self.setup(job)
mbligh7f7dbd32007-08-31 14:46:26 +000026
jadmanski0afbb632008-06-06 21:10:57 +000027 src = job.control_get()
28 dest = os.path.join(self.autodir, 'control')
29 if os.path.abspath(src) != os.path.abspath(dest):
30 shutil.copyfile(src, dest)
31 job.control_set(dest)
mbligh8d83cdc2007-12-03 18:09:18 +000032
Dale Curtis456d3c12011-07-19 11:42:51 -070033 logging.debug("Symlinking init scripts")
jadmanski0afbb632008-06-06 21:10:57 +000034 rc = os.path.join(self.autodir, 'tools/autotest')
Eric Lid656d562011-04-20 11:48:29 -070035 # see if system supports event.d versus systemd versus inittab
36 supports_eventd = os.path.exists('/etc/event.d')
37 supports_systemd = os.path.exists('/etc/systemd')
38 supports_inittab = os.path.exists('/etc/inittab')
39 if supports_eventd or supports_systemd:
jadmanski0afbb632008-06-06 21:10:57 +000040 # NB: assuming current runlevel is default
mblighc3758582008-09-02 17:09:19 +000041 initdefault = utils.system_output('/sbin/runlevel').split()[1]
Eric Lid656d562011-04-20 11:48:29 -070042 elif supports_inittab:
jadmanski0afbb632008-06-06 21:10:57 +000043 initdefault = utils.system_output('grep :initdefault: /etc/inittab')
44 initdefault = initdefault.split(':')[1]
rtc@google.com8ebda9a2009-11-13 03:50:06 +000045 else:
46 initdefault = '2'
mblighd9be00e2007-12-17 18:16:57 +000047
jadmanski0afbb632008-06-06 21:10:57 +000048 try:
Dale Curtis456d3c12011-07-19 11:42:51 -070049 service = '/etc/init.d/autotest'
50 service_link = '/etc/rc%s.d/S99autotest' % initdefault
51 if os.path.islink(service):
52 os.remove(service)
53 if os.path.islink(service_link):
54 os.remove(service_link)
55 os.symlink(rc, service)
56 os.symlink(rc, service_link)
57 except Exception, e:
58 logging.error("Symlink init scripts failed with %s", e)