Exemple #1
0
 def invoked(self, ctx):
     config = load_configs()
     print(_("Configuration files:"))
     for filename in config.filename_list:
         print(" - {}".format(filename))
     for variable in config.Meta.variable_list:
         print("   [{0}]".format(variable.section))
         print("   {0}={1}".format(
             variable.name, variable.__get__(config, config.__class__)))
     for section in config.Meta.section_list:
         print("   [{0}]".format(section.name))
         section_value = section.__get__(config, config.__class__)
         if section_value:
             for key, value in sorted(section_value.items()):
                 print("   {0}={1}".format(key, value))
     if config.problem_list:
         print(_("Problems:"))
         for problem in config.problem_list:
             if isinstance(problem, ValidationError):
                 print(
                     _(" - variable {0}: {1}").format(
                         problem.variable.name, problem.message))
             else:
                 print(" - {0}".format(problem.message))
         return 1
     else:
         print(_("No validation problems found"))
         return 0
Exemple #2
0
    def start_session(self, configuration):
        self._reset_sa()
        _logger.info("start_session: %r", configuration)
        session_title = 'checkbox-slave'
        session_desc = 'checkbox-slave session'
        session_type = 'checkbox-slave'

        self._launcher = load_configs()
        if configuration['launcher']:
            self._launcher.read_string(configuration['launcher'], False)
            if self._launcher.session_title:
                session_title = self._launcher.session_title
            if self._launcher.session_desc:
                session_desc = self._launcher.session_desc

        self._sa.use_alternate_configuration(self._launcher)

        if configuration['normal_user']:
            self._normal_user = configuration['normal_user']
        else:
            self._normal_user = self._launcher.normal_user
            if not self._normal_user:
                import pwd
                try:
                    self._normal_user = pwd.getpwuid(1000).pw_name
                    _logger.warning(
                        ("normal_user not supplied via config(s). "
                        "non-root jobs will run as %s"), self._normal_user)
                except KeyError:
                    raise RuntimeError(
                        ("normal_user not supplied via config(s). "
                        "Username for uid 1000 not found"))
        runner_kwargs = {
            'normal_user_provider': lambda: self._normal_user,
            'stdin': self._pipe_to_subproc,
            'extra_env': self.prepare_extra_env(),
        }
        self._sa.start_new_session(session_title, UnifiedRunner, runner_kwargs)
        new_blob = json.dumps({
            'description': session_desc,
            'type': session_type,
            'launcher': configuration['launcher'],
            'effective_normal_user': self._normal_user,
        }).encode("UTF-8")
        self._sa.update_app_blob(new_blob)
        self._sa.configure_application_restart(self._cmd_callback)

        self._session_id = self._sa.get_session_id()
        tps = self._sa.get_test_plans()
        filtered_tps = set()
        for filter in self._launcher.test_plan_filters:
            filtered_tps.update(fnmatch.filter(tps, filter))
        filtered_tps = list(filtered_tps)
        response = zip(filtered_tps, [self._sa.get_test_plan(
            tp).name for tp in filtered_tps])
        self._state = Started
        self._available_testplans = sorted(
            response, key=lambda x: x[1])  # sorted by name
        return self._available_testplans
Exemple #3
0
 def invoked(self, ctx):
     if ctx.args.version:
         from checkbox_ng.version import get_version_info
         for component, version in get_version_info().items():
             print("{}: {}".format(component, version))
         return
     if ctx.args.verify:
         # validation is always run, so if there were any errors the program
         # exited by now, so validation passed
         print(_("Launcher seems valid."))
         return
     if ctx.args.launcher:
         self.launcher = load_configs(ctx.args.launcher)
     else:
         self.launcher = DefaultLauncherDefinition()
     logging_level = {
         'normal': logging.WARNING,
         'verbose': logging.INFO,
         'debug': logging.DEBUG,
     }[self.launcher.verbosity]
     if not ctx.args.verbose and not ctx.args.debug:
         # Command line args take precendence
         logging.basicConfig(level=logging_level)
     try:
         self._C = Colorizer()
         self.ctx = ctx
         # now we have all the correct flags and options, so we need to
         # replace the previously built SA with the defaults
         self._configure_restart(ctx)
         self._prepare_transports()
         ctx.sa.use_alternate_configuration(self.launcher)
         if not self._maybe_resume_session():
             self._start_new_session()
             self._pick_jobs_to_run()
         if not self.ctx.sa.get_static_todo_list():
             return 0
         if 'submission_files' in self.launcher.stock_reports:
             print("Reports will be saved to: {}".format(self.base_dir))
         # we initialize the nb of attempts for all the selected jobs...
         for job_id in self.ctx.sa.get_dynamic_todo_list():
             job_state = self.ctx.sa.get_job_state(job_id)
             job_state.attempts = self.launcher.max_attempts
         # ... before running them
         self._run_jobs(self.ctx.sa.get_dynamic_todo_list())
         if self.is_interactive and not self.launcher.auto_retry:
             while True:
                 if not self._maybe_rerun_jobs():
                     break
         elif self.launcher.auto_retry:
             while True:
                 if not self._maybe_auto_rerun_jobs():
                     break
         self._export_results()
         ctx.sa.finalize_session()
         return 0 if ctx.sa.get_summary()['fail'] == 0 else 1
     except KeyboardInterrupt:
         return 1
    def start_session(self, configuration):
        self._reset_sa()
        _logger.debug("start_session: %r", configuration)
        session_title = 'checkbox-slave'
        session_desc = 'checkbox-slave session'

        self._launcher = load_configs()
        if configuration['launcher']:
            self._launcher.read_string(configuration['launcher'], False)
            session_title = self._launcher.session_title
            session_desc = self._launcher.session_desc

        self._sa.use_alternate_configuration(self._launcher)

        self._normal_user = self._launcher.normal_user
        if configuration['normal_user']:
            self._normal_user = configuration['normal_user']
        pass_provider = (None if self._passwordless_sudo else
                         self.get_decrypted_password)
        runner_kwargs = {
            'normal_user_provider': lambda: self._normal_user,
            'password_provider': pass_provider,
            'stdin': self._pipe_to_subproc,
            'extra_env': self.prepare_extra_env(),
        }
        self._sa.start_new_session(session_title, UnifiedRunner, runner_kwargs)
        self._sa.update_app_blob(
            json.dumps({
                'description': session_desc,
            }).encode("UTF-8"))
        self._sa.update_app_blob(
            json.dumps({
                'launcher': configuration['launcher'],
            }).encode("UTF-8"))

        self._session_id = self._sa.get_session_id()
        tps = self._sa.get_test_plans()
        filtered_tps = set()
        for filter in self._launcher.test_plan_filters:
            filtered_tps.update(fnmatch.filter(tps, filter))
        filtered_tps = list(filtered_tps)
        response = zip(
            filtered_tps,
            [self._sa.get_test_plan(tp).name for tp in filtered_tps])
        self._state = Started
        self._available_testplans = sorted(
            response, key=lambda x: x[1])  # sorted by name
        return self._available_testplans
Exemple #5
0
    def invoked(self, ctx):
        try:
            self._C = Colorizer()
            self.ctx = ctx

            self._configure_restart()
            config = load_configs()
            self.sa.use_alternate_configuration(config)
            self.sa.start_new_session(self.ctx.args.title or 'checkbox-run',
                                      UnifiedRunner)
            tps = self.sa.get_test_plans()
            self._configure_report()
            selection = ctx.args.PATTERN
            submission_message = self.ctx.args.message
            if len(selection) == 1 and selection[0] in tps:
                self.ctx.sa.update_app_blob(
                    json.dumps({
                        'testplan_id': selection[0],
                        'description': submission_message
                    }).encode("UTF-8"))
                self.just_run_test_plan(selection[0])
            else:
                self.ctx.sa.update_app_blob(
                    json.dumps({
                        'description': submission_message
                    }).encode("UTF-8"))
                self.sa.hand_pick_jobs(selection)
                print(self.C.header(_("Running Selected Jobs")))
                self._run_jobs(self.sa.get_dynamic_todo_list())
                # there might have been new jobs instantiated
                while True:
                    self.sa.hand_pick_jobs(ctx.args.PATTERN)
                    todos = self.sa.get_dynamic_todo_list()
                    if not todos:
                        break
                    self._run_jobs(self.sa.get_dynamic_todo_list())
            self.sa.finalize_session()
            self._print_results()
            return 0 if self.sa.get_summary()['fail'] == 0 else 1
        except KeyboardInterrupt:
            return 1
    def resume_by_id(self, session_id=None):
        self._launcher = load_configs()
        resume_candidates = list(self._sa.get_resumable_sessions())
        if not session_id:
            if not resume_candidates:
                print('No session to resume')
                return
            session_id = resume_candidates[0].id
        if session_id not in [s.id for s in resume_candidates]:
            print("Requested session not found")
            return
        _logger.warning("Resuming session: %r", session_id)
        self._normal_user = self._launcher.normal_user
        pass_provider = (None if self._passwordless_sudo else
                         self.get_decrypted_password)
        runner_kwargs = {
            'normal_user_provider': lambda: self._normal_user,
            'password_provider': pass_provider,
            'stdin': self._pipe_to_subproc,
            'extra_env': self.prepare_extra_env(),
        }
        meta = self._sa.resume_session(session_id, runner_kwargs=runner_kwargs)
        app_blob = json.loads(meta.app_blob.decode("UTF-8"))
        launcher = app_blob['launcher']
        self._launcher.read_string(launcher, False)
        self._sa.use_alternate_configuration(self._launcher)
        test_plan_id = app_blob['testplan_id']
        self._sa.select_test_plan(test_plan_id)
        self._sa.bootstrap()
        self._last_job = meta.running_job_name

        result_dict = {
            'outcome': IJobResult.OUTCOME_PASS,
            'comments': _("Automatically passed after resuming execution"),
        }
        result_path = os.path.join(self._sa.get_session_dir(), 'CHECKBOX_DATA',
                                   '__result')
        if os.path.exists(result_path):
            try:
                with open(result_path, 'rt') as f:
                    result_dict = json.load(f)
                    # the only really important field in the result is
                    # 'outcome' so let's make sure it doesn't contain
                    # anything stupid
                    if result_dict.get('outcome') not in [
                            'pass', 'fail', 'skip'
                    ]:
                        result_dict['outcome'] = IJobResult.OUTCOME_PASS
            except json.JSONDecodeError as e:
                pass
        result = MemoryJobResult(result_dict)
        if self._last_job:
            try:
                self._sa.use_job_result(self._last_job, result, True)
            except KeyError:
                raise SystemExit(self._last_job)

        # some jobs have already been run, so we need to update the attempts
        # count for future auto-rerunning
        if self._launcher.auto_retry:
            for job_id in [
                    job.id for job in self.get_rerun_candidates('auto')
            ]:
                job_state = self._sa.get_job_state(job_id)
                job_state.attempts = self._launcher.max_attempts - len(
                    job_state.result_history)

        self._state = TestsSelected