| OLD | NEW |
| 1 import os, sys, subprocess, logging | 1 import os, sys, subprocess, logging |
| 2 | 2 |
| 3 from autotest_lib.client.common_lib import utils, error | 3 from autotest_lib.client.common_lib import utils, error |
| 4 from autotest_lib.server import utils as server_utils | 4 from autotest_lib.server import utils as server_utils |
| 5 from autotest_lib.server.hosts import remote | 5 from autotest_lib.server.hosts import remote |
| 6 | 6 |
| 7 | 7 |
| 8 SiteHost = utils.import_site_class( | 8 SiteHost = utils.import_site_class( |
| 9 __file__, "autotest_lib.server.hosts.site_host", "SiteHost", | 9 __file__, "autotest_lib.server.hosts.site_host", "SiteHost", |
| 10 remote.RemoteHost) | 10 remote.RemoteHost) |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 if not self.conmux_attach or not os.path.exists(self.conmux_attach): | 107 if not self.conmux_attach or not os.path.exists(self.conmux_attach): |
| 108 return False | 108 return False |
| 109 cmd = '%s %s echo %s 2> /dev/null' % (self.conmux_attach, | 109 cmd = '%s %s echo %s 2> /dev/null' % (self.conmux_attach, |
| 110 self.get_conmux_hostname(), | 110 self.get_conmux_hostname(), |
| 111 cmd) | 111 cmd) |
| 112 result = utils.system(cmd, ignore_status=True) | 112 result = utils.system(cmd, ignore_status=True) |
| 113 return result == 0 | 113 return result == 0 |
| 114 | 114 |
| 115 | 115 |
| 116 def hardreset(self, timeout=DEFAULT_REBOOT_TIMEOUT, wait=True, | 116 def hardreset(self, timeout=DEFAULT_REBOOT_TIMEOUT, wait=True, |
| 117 conmux_command='hardreset', num_attempts=1, | 117 conmux_command='hardreset', num_attempts=1, halt=False, |
| 118 **wait_for_restart_kwargs): | 118 **wait_for_restart_kwargs): |
| 119 """ | 119 """ |
| 120 Reach out and slap the box in the power switch. | 120 Reach out and slap the box in the power switch. |
| 121 @params conmux_command: The command to run via the conmux interface | 121 @params conmux_command: The command to run via the conmux interface |
| 122 @params timeout: timelimit in seconds before the machine is | 122 @params timeout: timelimit in seconds before the machine is |
| 123 considered unreachable | 123 considered unreachable |
| 124 @params wait: Whether or not to wait for the machine to reboot | 124 @params wait: Whether or not to wait for the machine to reboot |
| 125 @params num_attempts: Number of times to attempt hard reset erroring | 125 @params num_attempts: Number of times to attempt hard reset erroring |
| 126 on the last attempt. | 126 on the last attempt. |
| 127 @params halt: Halts the machine before hardresetting. |
| 127 @params **wait_for_restart_kwargs: keyword arguments passed to | 128 @params **wait_for_restart_kwargs: keyword arguments passed to |
| 128 wait_for_restart() | 129 wait_for_restart() |
| 129 """ | 130 """ |
| 130 conmux_command = "'~$%s'" % conmux_command | 131 conmux_command = "'~$%s'" % conmux_command |
| 131 | 132 |
| 132 # if the machine is up, grab the old boot id, otherwise use a dummy | 133 # if the machine is up, grab the old boot id, otherwise use a dummy |
| 133 # string and NOT None to ensure that wait_down always returns True, | 134 # string and NOT None to ensure that wait_down always returns True, |
| 134 # even if the machine comes back up before it's called | 135 # even if the machine comes back up before it's called |
| 135 try: | 136 try: |
| 136 old_boot_id = self.get_boot_id() | 137 old_boot_id = self.get_boot_id() |
| 137 except error.AutoservSSHTimeout: | 138 except error.AutoservSSHTimeout: |
| 138 old_boot_id = 'unknown boot_id prior to SerialHost.hardreset' | 139 old_boot_id = 'unknown boot_id prior to SerialHost.hardreset' |
| 139 | 140 |
| 140 def reboot(): | 141 def reboot(): |
| 142 if halt: |
| 143 self.halt() |
| 141 if not self.run_conmux(conmux_command): | 144 if not self.run_conmux(conmux_command): |
| 142 self.record("ABORT", None, "reboot.start", | 145 self.record("ABORT", None, "reboot.start", |
| 143 "hard reset unavailable") | 146 "hard reset unavailable") |
| 144 raise error.AutoservUnsupportedError( | 147 raise error.AutoservUnsupportedError( |
| 145 'Hard reset unavailable') | 148 'Hard reset unavailable') |
| 146 self.record("GOOD", None, "reboot.start", "hard reset") | 149 self.record("GOOD", None, "reboot.start", "hard reset") |
| 147 if wait: | 150 if wait: |
| 148 warning_msg = ('Serial console failed to respond to hard reset ' | 151 warning_msg = ('Serial console failed to respond to hard reset ' |
| 149 'attempt (%s/%s)') | 152 'attempt (%s/%s)') |
| 150 for attempt in xrange(num_attempts-1): | 153 for attempt in xrange(num_attempts-1): |
| (...skipping 20 matching lines...) Expand all Loading... |
| 171 if self.job: | 174 if self.job: |
| 172 self.job.disable_warnings("POWER_FAILURE") | 175 self.job.disable_warnings("POWER_FAILURE") |
| 173 try: | 176 try: |
| 174 if wait: | 177 if wait: |
| 175 self.log_reboot(reboot) | 178 self.log_reboot(reboot) |
| 176 else: | 179 else: |
| 177 reboot() | 180 reboot() |
| 178 finally: | 181 finally: |
| 179 if self.job: | 182 if self.job: |
| 180 self.job.enable_warnings("POWER_FAILURE") | 183 self.job.enable_warnings("POWER_FAILURE") |
| OLD | NEW |