示例#1
0
def main():
    try:
        description = ("Execute automated workloads on a remote device and process "
                       "the resulting output.\n\nUse \"wa <subcommand> -h\" to see "
                       "help for individual subcommands.")
        parser = argparse.ArgumentParser(description=format_body(description, 80),
                                         prog='wa',
                                         formatter_class=argparse.RawDescriptionHelpFormatter,
                                         )
        init_argument_parser(parser)
        load_commands(parser.add_subparsers(dest='command'))  # each command will add its own subparser
        args = parser.parse_args()
        settings.verbosity = args.verbose
        settings.debug = args.debug
        if args.config:
            if not os.path.exists(args.config):
                raise ConfigError("Config file {} not found".format(args.config))
            settings.update(args.config)
        init_logging(settings.verbosity)

        signal.signal(signal.SIGTERM, convert_TERM_into_INT_handler)
        command = settings.commands[args.command]
        sys.exit(command.execute(args))

    except KeyboardInterrupt:
        logging.info('Got CTRL-C. Aborting.')
        sys.exit(3)
    except WAError as e:
        logging.critical(e)
        sys.exit(1)
    except subprocess.CalledProcessError as e:
        tb = get_traceback()
        logging.critical(tb)
        command = e.cmd
        if e.args:
            command = '{} {}'.format(command, ' '.join(e.args))
        message = 'Command \'{}\' returned non-zero exit status {}\nOUTPUT:\n{}\n'
        logging.critical(message.format(command, e.returncode, e.output))
        sys.exit(2)
    except SyntaxError as e:
        tb = get_traceback()
        logging.critical(tb)
        message = 'Syntax Error in {}, line {}, offset {}:'
        logging.critical(message.format(e.filename, e.lineno, e.offset))
        logging.critical('\t{}'.format(e.msg))
        sys.exit(2)
    except Exception as e:  # pylint: disable=broad-except
        tb = get_traceback()
        logging.critical(tb)
        logging.critical('{}({})'.format(e.__class__.__name__, e))
        sys.exit(2)
 def __init__(self, thread, exc_info):
     self.thread = thread
     self.exc_info = exc_info
     orig = self.exc_info[1]
     orig_name = type(orig).__name__
     message = 'Exception of type {} occured on thread {}:\n'.format(orig_name, thread)
     message += '{}\n{}: {}'.format(get_traceback(self.exc_info), orig_name, orig)
     super(WorkerThreadError, self).__init__(message)
示例#3
0
 def __init__(self, thread, exc_info):
     self.thread = thread
     self.exc_info = exc_info
     orig = self.exc_info[1]
     orig_name = type(orig).__name__
     message = 'Exception of type {} occured on thread {}:\n'.format(
         orig_name, thread)
     message += '{}\n{}: {}'.format(get_traceback(self.exc_info), orig_name,
                                    orig)
     super(WorkerThreadError, self).__init__(message)
 def __str__(self):
     if self.exc_info:
         orig = self.exc_info[1]
         orig_name = type(orig).__name__
         if isinstance(orig, WAError):
             reason = 'because of:\n{}: {}'.format(orig_name, orig)
         else:
             reason = 'because of:\n{}\n{}: {}'.format(get_traceback(self.exc_info), orig_name, orig)
         return '\n'.join([self.message, reason])
     else:
         return self.message
示例#5
0
 def __str__(self):
     if self.exc_info:
         orig = self.exc_info[1]
         orig_name = type(orig).__name__
         if isinstance(orig, WAError):
             reason = 'because of:\n{}: {}'.format(orig_name, orig)
         else:
             reason = 'because of:\n{}\n{}: {}'.format(
                 get_traceback(self.exc_info), orig_name, orig)
         return '\n'.join([self.message, reason])
     else:
         return self.message
 def __call__(self, context):
     if self.instrument.is_enabled:
         try:
             self.callback(context)
         except (KeyboardInterrupt, DeviceNotRespondingError, TimeoutError):  # pylint: disable=W0703
             raise
         except Exception as e:  # pylint: disable=W0703
             logger.error('Error in insturment {}'.format(self.instrument.name))
             global failures_detected  # pylint: disable=W0603
             failures_detected = True
             if isinstance(e, WAError):
                 logger.error(e)
             else:
                 tb = get_traceback()
                 logger.error(tb)
                 logger.error('{}({})'.format(e.__class__.__name__, e))
             if not context.current_iteration:
                 # Error occureed outside of an iteration (most likely
                 # during intial setup or teardown). Since this would affect
                 # the rest of the run, mark the instument as broken so that
                 # it doesn't get re-enabled for subsequent iterations.
                 self.instrument.is_broken = True
             disable(self.instrument)
 def __call__(self, context):
     if self.instrument.is_enabled:
         try:
             self.callback(context)
         except (KeyboardInterrupt, DeviceNotRespondingError, TimeoutError):  # pylint: disable=W0703
             raise
         except Exception as e:  # pylint: disable=W0703
             logger.error('Error in insturment {}'.format(
                 self.instrument.name))
             global failures_detected  # pylint: disable=W0603
             failures_detected = True
             if isinstance(e, WAError):
                 logger.error(e)
             else:
                 tb = get_traceback()
                 logger.error(tb)
                 logger.error('{}({})'.format(e.__class__.__name__, e))
             if not context.current_iteration:
                 # Error occureed outside of an iteration (most likely
                 # during intial setup or teardown). Since this would affect
                 # the rest of the run, mark the instument as broken so that
                 # it doesn't get re-enabled for subsequent iterations.
                 self.instrument.is_broken = True
             disable(self.instrument)
示例#8
0
                # screenshot failed is not surprising...
                pass
            if action:
                action = action[0].lower() + action[1:]
            self.logger.error('Error while {}:\n\t{}'.format(action, we))
        except Exception, e:  # pylint: disable=W0703
            error_text = '{}("{}")'.format(e.__class__.__name__, e)
            if self.current_job:
                self.current_job.result.status = on_error_status
                self.current_job.result.add_event(error_text)
            self.logger.error('Error while {}'.format(action))
            self.logger.error(error_text)
            if isinstance(e, subprocess.CalledProcessError):
                self.logger.error('Got:')
                self.logger.error(e.output)
            tb = get_traceback()
            self.logger.error(tb)

    @contextmanager
    def _signal_wrap(self, signal_name):
        """Wraps the suite in before/after signals, ensuring
        that after signal is always sent."""
        before_signal = getattr(signal, 'BEFORE_' + signal_name)
        success_signal = getattr(signal, 'SUCCESSFUL_' + signal_name)
        after_signal = getattr(signal, 'AFTER_' + signal_name)
        try:
            self._send(before_signal)
            yield
            self._send(success_signal)
        finally:
            self._send(after_signal)
示例#9
0
                # screenshot failed is not surprising...
                pass
            if action:
                action = action[0].lower() + action[1:]
            self.logger.error('Error while {}:\n\t{}'.format(action, we))
        except Exception, e:  # pylint: disable=W0703
            error_text = '{}("{}")'.format(e.__class__.__name__, e)
            if self.current_job:
                self.current_job.result.status = on_error_status
                self.current_job.result.add_event(error_text)
            self.logger.error('Error while {}'.format(action))
            self.logger.error(error_text)
            if isinstance(e, subprocess.CalledProcessError):
                self.logger.error('Got:')
                self.logger.error(e.output)
            tb = get_traceback()
            self.logger.error(tb)

    @contextmanager
    def _signal_wrap(self, signal_name):
        """Wraps the suite in before/after signals, ensuring
        that after signal is always sent."""
        before_signal = getattr(signal, 'BEFORE_' + signal_name)
        success_signal = getattr(signal, 'SUCCESSFUL_' + signal_name)
        after_signal = getattr(signal, 'AFTER_' + signal_name)
        try:
            self._send(before_signal)
            yield
            self._send(success_signal)
        finally:
            self._send(after_signal)