How to use is_client_job_finished method in autotest

Best Python code snippet using autotest_python Github


Full Screen

...457 finally:458 aux_file.close()459 return path460 @staticmethod461 def is_client_job_finished(last_line):462 return bool(re.match(r'^END .*\t----\t----\t.*$', last_line))463 @staticmethod464 def is_client_job_rebooting(last_line):465 return bool(re.match(r'^\t*GOOD\t----\treboot\.start.*$', last_line))466 def log_unexpected_abort(self, stderr_redirector):467 stderr_redirector.flush_all_buffers()468 msg = "Autotest client terminated unexpectedly"469"END ABORT", None, None, msg)470 def _execute_in_background(self, section, timeout):471 full_cmd = self.get_background_cmd(section)472 devnull = open(os.devnull, "w")473 self.copy_client_config_file(self.get_client_log())474 try:476 result =, ignore_status=True,477 timeout=timeout,478 stdout_tee=devnull,479 stderr_tee=devnull)480 finally:481 return result483 @staticmethod484 def _strip_stderr_prologue(stderr):485 """Strips the 'standard' prologue that get pre-pended to every486 remote command and returns the text that was actually written to487 stderr by the remote command."""488 stderr_lines = stderr.split("\n")[1:]489 if not stderr_lines:490 return ""491 elif stderr_lines[0].startswith("NOTE: autotestd_monitor"):492 del stderr_lines[0]493 return "\n".join(stderr_lines)494 def _execute_daemon(self, section, timeout, stderr_redirector,495 client_disconnect_timeout):496 monitor_dir = daemon_cmd = self.get_daemon_cmd(section, monitor_dir)498 # grab the location for the server-side client log file499 client_log_prefix = self.get_client_log()500 client_log_path = os.path.join(self.results_dir, 'debug',501 client_log_prefix + '.log')502 client_log = open(client_log_path, 'w', 0)503 self.copy_client_config_file(client_log_prefix)504 stdout_read = stderr_read = 0505 try:507, ignore_status=True, timeout=timeout)508 disconnect_warnings = []509 while True:510 monitor_cmd = self.get_monitor_cmd(monitor_dir, stdout_read,511 stderr_read)512 try:513 result =, ignore_status=True,514 timeout=timeout,515 stdout_tee=client_log,516 stderr_tee=stderr_redirector)517 except error.AutoservRunError, e:518 result = e.result_obj519 result.exit_status = None520 disconnect_warnings.append(e.description)521 stderr_redirector.log_warning(522 "Autotest client was disconnected: %s" % e.description,523 "NETWORK")524 except error.AutoservSSHTimeout:525 result = utils.CmdResult(monitor_cmd, "", "", None, 0)526 stderr_redirector.log_warning(527 "Attempt to connect to Autotest client timed out",528 "NETWORK")529 stdout_read += len(result.stdout)530 stderr_read += len(self._strip_stderr_prologue(result.stderr))531 if result.exit_status is not None:532 return result533 elif not raise error.AutoservSSHTimeout(535 "client was disconnected, reconnect timed out")536 finally:537 client_log.close()538 def execute_section(self, section, timeout, stderr_redirector,540 client_disconnect_timeout):541"Executing %s/bin/autotest %s/control phase %d",542 self.autodir, self.autodir, section)543 if self.background:544 result = self._execute_in_background(section, timeout)545 else:546 result = self._execute_daemon(section, timeout, stderr_redirector,547 client_disconnect_timeout)548 last_line = stderr_redirector.last_line549 # check if we failed hard enough to warrant an exception550 if result.exit_status == 1:551 err = error.AutotestRunError("client job was aborted")552 elif not self.background and not result.stderr:553 err = error.AutotestRunError(554 "execute_section %s failed to return anything\n"555 "stdout:%s\n" % (section, result.stdout))556 else:557 err = None558 # log something if the client failed AND never finished logging559 if err and not self.is_client_job_finished(last_line):560 self.log_unexpected_abort(stderr_redirector)561 if err:562 raise err563 else:564 return stderr_redirector.last_line565 def _wait_for_reboot(self, old_boot_id):566"Client is rebooting")567"Waiting for client to halt")568 if not, old_boot_id=old_boot_id):569 err = "%s failed to shutdown after %d"570 err %= (, HALT_TIME)571 raise error.AutotestRunError(err)572"Client down, waiting for restart")573 if not # since reboot failed575 # hardreset the machine once if possible576 # before failing this control file577 warning = "%s did not come back up, hard resetting"578 warning %= logging.warning(warning)580 try:581 except (AttributeError, error.AutoservUnsupportedError):583 warning = "Hard reset unsupported on %s"584 warning %= logging.warning(warning)586 raise error.AutotestRunError("%s failed to boot after %ds" %587 (, BOOT_TIME))588 def execute_control(self, timeout=None, client_disconnect_timeout=None):590 if not self.background:591 collector = log_collector(, self.tag, self.results_dir)592 hostname = remote_results = collector.client_results_dir594 local_results = collector.server_results_dir595, remote_results,596 local_results)597 job_record_context = section = 0599 start_time = time.time()600 logger = client_logger(, self.tag, self.results_dir)601 try:602 while not timeout or time.time() < start_time + timeout:603 if timeout:604 section_timeout = start_time + timeout - time.time()605 else:606 section_timeout = None607 boot_id = last = self.execute_section(section, section_timeout,609 logger, client_disconnect_timeout)610 if self.background:611 return612 section += 1613 if self.is_client_job_finished(last):614"Client complete")615 return616 elif self.is_client_job_rebooting(last):617 try:618 self._wait_for_reboot(boot_id)619 except error.AutotestRunError, e:620"ABORT", None, "reboot", str(e))621"END ABORT", None, None, str(e))622 raise623 continue624 # if we reach here, something unexpected happened625 self.log_unexpected_abort(logger)626 # give the client machine a chance to recover from a crash627

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?