Example #1
0
 def runTest(self):
     status = "PASS"
     fail_reason = ""
     try:
         messages.start_logging(self._config, self.queue)
         self.setUp()
         if isinstance(self.__status, Exception):
             # pylint doesn't know much about flow-control
             raise self.__status  # pylint: disable-msg=E0702
     except exceptions.TestBaseException as detail:
         status = detail.status
         fail_reason = (astring.to_text(detail))
         if status == "ERROR" or status not in teststatus.STATUSES:
             status = "ERROR"
             self.queue.put(
                 messages.StderrMessage.get(traceback.format_exc()))
         else:
             self.queue.put(messages.LogMessage.get(traceback.format_exc()))
     except Exception as detail:
         status = "ERROR"
         try:
             fail_reason = (astring.to_text(detail))
         except TypeError:
             fail_reason = ("Unable to get exception, check the traceback "
                            "in `debug.log` for details.")
         self.queue.put(messages.StderrMessage.get(traceback.format_exc()))
     finally:
         if 'avocado_test_' in self.logdir:
             self._save_log_dir()
         self.queue.put(messages.FinishedMessage.get(status, fail_reason))
Example #2
0
    def _run_avocado(runnable, queue):
        try:
            # This assumes that a proper resolution (see resolver module)
            # was performed, and that a URI contains:
            # 1) path to python module
            # 2) class
            # 3) method
            #
            # To be defined: if the resolution uri should be composed like
            # this, or broken down and stored into other data fields
            module_path, klass_method = runnable.uri.split(':', 1)

            klass, method = klass_method.split('.', 1)

            params = AvocadoInstrumentedTestRunner._create_params(runnable)
            result_dir = (runnable.output_dir
                          or tempfile.mkdtemp(prefix=".avocado-task"))
            test_factory = [
                klass, {
                    'name': TestID(1, runnable.uri),
                    'methodName': method,
                    'config': runnable.config,
                    'modulePath': module_path,
                    'params': params,
                    'tags': runnable.tags,
                    'run.results_dir': result_dir,
                }
            ]

            messages.start_logging(runnable.config, queue)

            if 'COVERAGE_RUN' in os.environ:
                from coverage import Coverage
                coverage = Coverage()
                coverage.start()

            instance = loader.load_test(test_factory)
            early_state = instance.get_state()
            early_state['type'] = "early_state"
            queue.put(early_state)
            instance.run_avocado()

            if 'COVERAGE_RUN' in os.environ:
                coverage.stop()
                coverage.save()

            state = instance.get_state()
            fail_reason = state.get('fail_reason')
            queue.put(messages.WhiteboardMessage.get(state['whiteboard']))
            queue.put(
                messages.FinishedMessage.get(state['status'].lower(),
                                             fail_reason=fail_reason))
        except Exception as e:
            queue.put(messages.StderrMessage.get(traceback.format_exc()))
            queue.put(messages.FinishedMessage.get('error',
                                                   fail_reason=str(e)))
Example #3
0
 def run_test(self):
     status = "ERROR"
     try:
         messages.start_logging(self.config, self.queue)
         self._run_test()
         status = "PASS"
     except exceptions.TestBaseException:
         exc_info = sys.exc_info()
         status = exc_info[0].status
         if status == "ERROR" or status not in teststatus.STATUSES:
             status = "ERROR"
             self.queue.put(messages.StderrMessage.get(traceback.format_exc()))
     except Exception:
         status = "ERROR"
         self.queue.put(messages.StderrMessage.get(traceback.format_exc()))
     finally:
         self.queue.put(messages.FinishedMessage.get(status))
Example #4
0
    def run_test(self):
        params = self.params
        try:
            messages.start_logging(self.config, self.queue)

            # Report virt test version
            self.log.info(version.get_pretty_version_info())
            self._log_parameters()

            # Warn of this special condition in related location in output & logs
            if os.getuid() == 0 and params.get('nettype', 'user') == 'user':
                self.log.warning("")
                self.log.warning("Testing with nettype='user' while running "
                                 "as root may produce unexpected results!!!")
                self.log.warning("")

            subtest_dirs = self._get_subtest_dirs()

            # Get the test routine corresponding to the specified
            # test type
            self.log.debug(
                "Searching for test modules that match 'type = %s' "
                "and 'provider = %s' on this cartesian dict",
                params.get("type"), params.get("provider", None))

            t_types = params.get("type").split()
            utils.insert_dirs_to_path(subtest_dirs)
            test_modules = utils.find_test_modules(t_types, subtest_dirs)

            # Open the environment file
            env_filename = os.path.join(data_dir.get_tmp_dir(),
                                        params.get("env", "env"))
            env = utils_env.Env(env_filename, self.env_version)

            test_passed = False
            t_type = None

            try:
                try:
                    # Pre-process
                    try:
                        params = env_process.preprocess(self, params, env)
                    finally:
                        self._safe_env_save(env)

                    # Run the test function
                    for t_type in t_types:
                        test_module = test_modules[t_type]
                        run_func = utils_misc.get_test_entrypoint_func(
                            t_type, test_module)
                        try:
                            run_func(self, params, env)
                            self.verify_background_errors()
                        finally:
                            self._safe_env_save(env)
                    test_passed = True
                    error_message = funcatexit.run_exitfuncs(env, t_type)
                    if error_message:
                        raise exceptions.TestWarn(
                            "funcatexit failed with: %s" % error_message)

                except:  # nopep8 Old-style exceptions are not inherited from Exception()
                    stacktrace.log_exc_info(sys.exc_info(), 'avocado.test')
                    if t_type is not None:
                        error_message = funcatexit.run_exitfuncs(env, t_type)
                        if error_message:
                            self.log.error(error_message)
                    try:
                        env_process.postprocess_on_error(self, params, env)
                    finally:
                        self._safe_env_save(env)
                    raise

            finally:
                # Post-process
                try:
                    try:
                        params['test_passed'] = str(test_passed)
                        env_process.postprocess(self, params, env)
                    except:  # nopep8 Old-style exceptions are not inherited from Exception()

                        stacktrace.log_exc_info(sys.exc_info(), 'avocado.test')
                        if test_passed:
                            raise
                        self.log.error(
                            "Exception raised during postprocessing:"
                            " %s",
                            sys.exc_info()[1])
                finally:
                    if self._safe_env_save(env) or params.get(
                            "env_cleanup", "no") == "yes":
                        env.destroy()  # Force-clean as it can't be stored

        except Exception as e:
            try:
                if params.get("abort_on_error") != "yes":
                    raise
                # Abort on error
                logging.info("Aborting job (%s)", e)
                if params.get("vm_type") == "qemu":
                    for vm in env.get_all_vms():
                        if vm.is_dead():
                            continue
                        logging.info("VM '%s' is alive.", vm.name)
                        for m in vm.monitors:
                            logging.info(
                                "It has a %s monitor unix socket at:"
                                " %s", m.protocol, m.filename)
                        logging.info(
                            "The command line used to start it was:"
                            "\n%s", vm.make_create_command())
                    raise exceptions.JobError("Abort requested (%s)" % e)
            finally:
                self.queue.put(
                    messages.StderrMessage.get(traceback.format_exc()))
                self.queue.put(messages.FinishedMessage.get('error'))
        self.queue.put(messages.FinishedMessage.get('pass'))