def run(self, commands, parser=None, iterations=1, fixupdict=None, timeout=-1): target = self.client.target_device log_dir = tempfile.mkdtemp(dir=target.scratch_dir) self._logfile = os.path.join(log_dir, 'stdout.log') if parser is not None: self._parser = parser if fixupdict is not None: self._fixupdict = fixupdict logging.info("lava_command logfile: %s" % self._logfile) with self.client.tester_session() as session: for count in range(iterations): logging.info("Executing lava_command_run iteration: %s" % count) for command in commands: logging.info("Executing lava_command_run: %s" % command) try: res = {} res['test_case_id'] = command session.run(command, timeout=timeout, log_in_host=self._logfile) res['result'] = 'pass' self._results_from_log_file.append(res) except (OperationFailed, RuntimeError, pexpect.TIMEOUT) as e: res['result'] = 'fail' self._results_from_log_file.append(res) logging.error(e) bundle = self._get_bundle() self._write_results_bundle(bundle) printer = PrettyPrinter(self.context) printer.print_results(bundle)
def _bundle_results(self, target, signal_director, testdef_objs): """ Pulls the results from the target device and builds a bundle """ results_part = target.deployment_data['lava_test_results_part_attr'] results_part = getattr(target.config, results_part) rdir = self.context.host_result_dir parse_err_msg = None filesystem_access_failure = True try: with target.file_system(results_part, target.lava_test_results_dir) as d: filesystem_access_failure = False err_log = os.path.join(d, 'parse_err.log') results_dir = os.path.join(d, 'results') bundle = lava_test_shell.get_bundle(results_dir, testdef_objs, err_log) parse_err_msg = read_content(err_log, ignore_missing=True) if os.path.isfile(err_log): os.unlink(err_log) # lava/results must be empty, but we keep a copy named # lava/results-XXXXXXXXXX for post-mortem analysis timestamp = datetime.now().strftime("%s") os.rename(results_dir, results_dir + '-' + timestamp) utils.ensure_directory(results_dir) except Exception as e: if filesystem_access_failure: # a failure when accessing the filesystem means the device # probably crashed. We use the backup bundle then. bundle = self._backup_bundle logging.warning( """Error extracting test results from device: %s""" % e) logging.warning( """This may mean that the device under test crashed. """ """We will use test results parsed from the serial """ """output as a backup, but note that some test """ """artifacts (such as attachments and """ """hardware/software contexts) will not be available""") else: raise e signal_director.postprocess_bundle(bundle) (fd, name) = tempfile.mkstemp( prefix='lava-test-shell', suffix='.bundle', dir=rdir) with os.fdopen(fd, 'w') as f: DocumentIO.dump(f, bundle) printer = PrettyPrinter(self.context) printer.print_results(bundle) if parse_err_msg: raise GeneralError(parse_err_msg)