mbligh | 7f7dbd3 | 2007-08-31 14:46:26 +0000 | [diff] [blame] | 1 | """The standalone harness interface |
| 2 | |
| 3 | The default interface as required for the standalone reboot helper. |
| 4 | """ |
| 5 | |
| 6 | __author__ = """Copyright Andy Whitcroft 2007""" |
| 7 | |
Eric Li | d656d56 | 2011-04-20 11:48:29 -0700 | [diff] [blame] | 8 | from autotest_lib.client.common_lib import utils, error |
showard | b18134f | 2009-03-20 20:52:18 +0000 | [diff] [blame] | 9 | import os, harness, shutil, logging |
mbligh | 7f7dbd3 | 2007-08-31 14:46:26 +0000 | [diff] [blame] | 10 | |
| 11 | class harness_standalone(harness.harness): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 12 | """The standalone server harness |
mbligh | 7f7dbd3 | 2007-08-31 14:46:26 +0000 | [diff] [blame] | 13 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 14 | Properties: |
| 15 | job |
| 16 | The job object for this job |
| 17 | """ |
mbligh | 7f7dbd3 | 2007-08-31 14:46:26 +0000 | [diff] [blame] | 18 | |
Eric Li | 8a12e80 | 2011-02-17 14:24:13 -0800 | [diff] [blame] | 19 | def __init__(self, job, harness_args): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 20 | """ |
| 21 | job |
| 22 | The job object for this job |
| 23 | """ |
| 24 | self.autodir = os.path.abspath(os.environ['AUTODIR']) |
| 25 | self.setup(job) |
mbligh | 7f7dbd3 | 2007-08-31 14:46:26 +0000 | [diff] [blame] | 26 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 27 | 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) |
mbligh | 8d83cdc | 2007-12-03 18:09:18 +0000 | [diff] [blame] | 32 | |
Dale Curtis | 456d3c1 | 2011-07-19 11:42:51 -0700 | [diff] [blame] | 33 | logging.debug("Symlinking init scripts") |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 34 | rc = os.path.join(self.autodir, 'tools/autotest') |
Eric Li | d656d56 | 2011-04-20 11:48:29 -0700 | [diff] [blame] | 35 | # 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: |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 40 | # NB: assuming current runlevel is default |
mbligh | c375858 | 2008-09-02 17:09:19 +0000 | [diff] [blame] | 41 | initdefault = utils.system_output('/sbin/runlevel').split()[1] |
Eric Li | d656d56 | 2011-04-20 11:48:29 -0700 | [diff] [blame] | 42 | elif supports_inittab: |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 43 | initdefault = utils.system_output('grep :initdefault: /etc/inittab') |
| 44 | initdefault = initdefault.split(':')[1] |
rtc@google.com | 8ebda9a | 2009-11-13 03:50:06 +0000 | [diff] [blame] | 45 | else: |
| 46 | initdefault = '2' |
mbligh | d9be00e | 2007-12-17 18:16:57 +0000 | [diff] [blame] | 47 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 48 | try: |
Dale Curtis | 456d3c1 | 2011-07-19 11:42:51 -0700 | [diff] [blame] | 49 | 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) |