def test_create_with_job_list(self, **mocks): """ verify that SessionManager.create_with_job_list() correctly sets up storage repository and creates session directories """ # Mock job list job_list = mock.Mock(name='job_list') # Create the new manager manager = SessionManager.create_with_job_list(job_list) # Ensure that a state object was created mocks['SessionState'].assert_called_with(job_list) state = mocks['SessionState']() # Ensure that a default repository was created mocks['SessionStorageRepository'].assert_called_with() repo = mocks['SessionStorageRepository']() # Ensure that a storage was created, with repository location and # without legacy mode turned on mocks['SessionStorage'].create.assert_called_with(repo.location, False) storage = mocks['SessionStorage'].create() # Ensure that a default directories were created mocks['WellKnownDirsHelper'].assert_called_with(storage) helper = mocks['WellKnownDirsHelper']() helper.populate.assert_called_with() # Ensure that the resulting manager has correct data inside self.assertEqual(manager.state, state) self.assertEqual(manager.storage, storage)
def test_create_with_job_list(self, **mocks): """ verify that SessionManager.create_with_job_list() correctly sets up storage repository and creates session directories """ # Mock job list job_list = mock.Mock(name='job_list') # Create the new manager manager = SessionManager.create_with_job_list(job_list) # Ensure that a state object was created mocks['SessionState'].assert_called_with(job_list) state = mocks['SessionState']() # Ensure that a default repository was created mocks['SessionStorageRepository'].assert_called_with() repo = mocks['SessionStorageRepository']() # Ensure that a storage was created, with repository location and # without legacy mode turned on mocks['SessionStorage'].create.assert_called_with(repo.location, False) storage = mocks['SessionStorage'].create() # Ensure that a default directories were created mocks['WellKnownDirsHelper'].assert_called_with(storage) helper = mocks['WellKnownDirsHelper']() helper.populate.assert_called_with() # Ensure that the resulting manager has correct data inside self.assertEqual(manager.state, state) self.assertEqual(manager.storage, storage)
def run(self): ns = self.ns job_list = self.get_job_list(ns) previous_session_file = SessionStorageRepository().get_last_storage() resume_in_progress = False if previous_session_file: if self.is_interactive: if self.ask_for_resume(): resume_in_progress = True manager = SessionManager.load_session( job_list, previous_session_file) self._maybe_skip_last_job_after_resume(manager) else: resume_in_progress = True manager = SessionManager.load_session(job_list, previous_session_file) if not resume_in_progress: # Create a session that handles most of the stuff needed to run # jobs try: manager = SessionManager.create_with_job_list(job_list, legacy_mode=True) except DependencyDuplicateError as exc: # Handle possible DependencyDuplicateError that can happen if # someone is using plainbox for job development. print("The job database you are currently using is broken") print("At least two jobs contend for the name {0}".format( exc.job.id)) print("First job defined in: {0}".format(exc.job.origin)) print("Second job defined in: {0}".format( exc.duplicate_job.origin)) raise SystemExit(exc) manager.state.metadata.title = " ".join(sys.argv) if self.is_interactive: if self.display is None: self.display = get_display() if self.settings['welcome_text']: self.display.run(ShowWelcome( self.settings['welcome_text'])) if not self.whitelists: whitelists = [] for p in self.provider_list: if p.name in self.settings['default_providers']: whitelists.extend( [w.name for w in p.get_builtin_whitelists()]) selection = self.display.run( ShowMenu("Suite selection", whitelists)) if not selection: raise SystemExit('No whitelists selected, aborting...') for s in selection: self.whitelists.append( get_whitelist_by_name(self.provider_list, whitelists[s])) else: self.whitelists.append( get_whitelist_by_name(self.provider_list, self.settings['default_whitelist'])) manager.checkpoint() if self.is_interactive and not resume_in_progress: # Pre-run all local jobs desired_job_list = select_jobs(manager.state.job_list, [ CompositeQualifier(self.whitelists + [NonLocalJobQualifier(inclusive=False)]) ]) self._update_desired_job_list(manager, desired_job_list) # Ask the password before anything else in order to run local jobs # requiring privileges if self._auth_warmup_needed(manager): print("[ Authentication ]".center(80, '=')) return_code = authenticate_warmup() if return_code: raise SystemExit(return_code) self._local_only = True self._run_jobs(ns, manager) self._local_only = False if not resume_in_progress: # Run the rest of the desired jobs desired_job_list = select_jobs(manager.state.job_list, self.whitelists) self._update_desired_job_list(manager, desired_job_list) if self.is_interactive: # Ask the password before anything else in order to run jobs # requiring privileges if self._auth_warmup_needed(manager): print("[ Authentication ]".center(80, '=')) return_code = authenticate_warmup() if return_code: raise SystemExit(return_code) tree = SelectableJobTreeNode.create_tree( manager.state.run_list, legacy_mode=True) title = 'Choose tests to run on your system:' if self.display is None: self.display = get_display() self.display.run(ScrollableTreeNode(tree, title)) self._update_desired_job_list(manager, tree.selection) estimated_duration_auto, estimated_duration_manual = \ manager.state.get_estimated_duration() if estimated_duration_auto: print( "Estimated duration is {:.2f} " "for automated jobs.".format(estimated_duration_auto)) else: print("Estimated duration cannot be " "determined for automated jobs.") if estimated_duration_manual: print("Estimated duration is {:.2f} " "for manual jobs.".format(estimated_duration_manual)) else: print("Estimated duration cannot be " "determined for manual jobs.") self._run_jobs(ns, manager) manager.destroy() # FIXME: sensible return value return 0
def run(self): ns = self.ns job_list = self.get_job_list(ns) previous_session_file = SessionStorageRepository().get_last_storage() resume_in_progress = False if previous_session_file: if self.is_interactive: if self.ask_for_resume(): resume_in_progress = True manager = SessionManager.load_session( job_list, previous_session_file) self._maybe_skip_last_job_after_resume(manager) else: resume_in_progress = True manager = SessionManager.load_session( job_list, previous_session_file) if not resume_in_progress: # Create a session that handles most of the stuff needed to run # jobs try: manager = SessionManager.create_with_job_list( job_list, legacy_mode=True) except DependencyDuplicateError as exc: # Handle possible DependencyDuplicateError that can happen if # someone is using plainbox for job development. print("The job database you are currently using is broken") print("At least two jobs contend for the name {0}".format( exc.job.id)) print("First job defined in: {0}".format(exc.job.origin)) print("Second job defined in: {0}".format( exc.duplicate_job.origin)) raise SystemExit(exc) manager.state.metadata.title = " ".join(sys.argv) if self.is_interactive: if self.display is None: self.display = get_display() if self.settings['welcome_text']: self.display.run( ShowWelcome(self.settings['welcome_text'])) if not self.whitelists: whitelists = [] for p in self.provider_list: if p.name in self.settings['default_providers']: whitelists.extend( [w.name for w in p.get_builtin_whitelists()]) selection = self.display.run(ShowMenu("Suite selection", whitelists)) if not selection: raise SystemExit('No whitelists selected, aborting...') for s in selection: self.whitelists.append( get_whitelist_by_name(self.provider_list, whitelists[s])) else: self.whitelists.append( get_whitelist_by_name( self.provider_list, self.settings['default_whitelist'])) manager.checkpoint() if self.is_interactive and not resume_in_progress: # Pre-run all local jobs desired_job_list = select_jobs( manager.state.job_list, [CompositeQualifier( self.whitelists + [NonLocalJobQualifier(inclusive=False)] )]) self._update_desired_job_list(manager, desired_job_list) # Ask the password before anything else in order to run local jobs # requiring privileges if self._auth_warmup_needed(manager): print("[ Authentication ]".center(80, '=')) return_code = authenticate_warmup() if return_code: raise SystemExit(return_code) self._local_only = True self._run_jobs(ns, manager) self._local_only = False if not resume_in_progress: # Run the rest of the desired jobs desired_job_list = select_jobs(manager.state.job_list, self.whitelists) self._update_desired_job_list(manager, desired_job_list) if self.is_interactive: # Ask the password before anything else in order to run jobs # requiring privileges if self._auth_warmup_needed(manager): print("[ Authentication ]".center(80, '=')) return_code = authenticate_warmup() if return_code: raise SystemExit(return_code) tree = SelectableJobTreeNode.create_tree( manager.state.run_list, legacy_mode=True) title = 'Choose tests to run on your system:' if self.display is None: self.display = get_display() self.display.run(ScrollableTreeNode(tree, title)) self._update_desired_job_list(manager, tree.selection) estimated_duration_auto, estimated_duration_manual = \ manager.state.get_estimated_duration() if estimated_duration_auto: print( "Estimated duration is {:.2f} " "for automated jobs.".format(estimated_duration_auto)) else: print( "Estimated duration cannot be " "determined for automated jobs.") if estimated_duration_manual: print( "Estimated duration is {:.2f} " "for manual jobs.".format(estimated_duration_manual)) else: print( "Estimated duration cannot be " "determined for manual jobs.") self._run_jobs(ns, manager) manager.destroy() # FIXME: sensible return value return 0