def suspend(): self.record("GOOD", None, "suspend.start for %d seconds" % (timeout)) try: self.run_background(suspend_cmd) except error.AutoservRunError: self.record("ABORT", None, "suspend.start", "suspend command failed") raise error.AutoservSuspendError("suspend command failed") # Wait for some time, to ensure the machine is going to sleep. # Not too long to check if the machine really suspended. time_slice = min(timeout / 2, 300) time.sleep(time_slice) time_counter = time_slice while time_counter < timeout + 60: # Check if the machine is back. We check regularely to # ensure the machine was suspended long enough. if utils.ping(self.hostname, tries=1, deadline=1) == 0: return else: if time_counter > timeout - 10: time_slice = 5 time.sleep(time_slice) time_counter += time_slice if utils.ping(self.hostname, tries=1, deadline=1) != 0: raise error.AutoservSuspendError( "DUT is not responding after %d seconds" % (time_counter))
def verify(self, host): if host.is_up(): return msg = 'No answer to ssh from %s' try: socket.gethostbyname(host.hostname) except Exception as e: logging.exception('DNS lookup failure') msg = 'Unable to look up %%s in DNS: %s' % e else: if utils.ping(host.hostname, tries=1, deadline=1) != 0: msg = 'No answer to ping from %s' raise hosts.AutoservVerifyError(msg % host.hostname)
def _diagnose_dut(self, old_boot_id=None): """ Run diagnostic checks on a DUT. 1. ping: A dead host will not respond to pings. 2. ssh (happens with 3.): DUT hangs usually fail in authentication but respond to pings. 3. Check if a reboot occured: A healthy but unexpected reboot leaves the host running with a new boot id. This method will always raise an exception from the AutotestFailure family and should only get called when the reason for a test failing is ambiguous. @raises AutotestDeviceNotPingable: If the DUT doesn't respond to ping. @raises AutotestDeviceNotSSHable: If we cannot SSH into the DUT. @raises AutotestDeviceRebooted: If the boot id changed. @raises AutotestAbort: If none of the above exceptions were raised. Since we have no recourse we must abort at this stage. """ msg = 'Autotest client terminated unexpectedly: ' if utils.ping(self.host.hostname, tries=1, deadline=1) != 0: msg += 'DUT is no longer pingable, it may have rebooted or hung.\n' raise AutotestDeviceNotPingable(msg) if old_boot_id: try: new_boot_id = self.host.get_boot_id(timeout=60) except Exception as e: msg += ('DUT is pingable but not SSHable, it most likely' ' sporadically rebooted during testing. %s\n' % str(e)) raise AutotestDeviceNotSSHable(msg) else: if new_boot_id != old_boot_id: msg += 'DUT rebooted during the test run.\n' raise AutotestDeviceRebooted(msg) msg += ('DUT is pingable, SSHable and did NOT restart ' 'un-expectedly. We probably lost connectivity during the ' 'test.') else: msg += ('DUT is pingable, could not determine if an un-expected ' 'reboot occured during the test.') raise AutotestAbort(msg)