Ejemplo n.º 1
0
 def test_create_with_unit_list(self, **mocks):
     """
     verify that SessionManager.create_with_unit_list() correctly sets up
     storage repository and creates session directories
     """
     mocks['SessionStorage'].create.return_value = mock.MagicMock(
         spec_set=SessionStorage)
     # Mock unit list
     unit_list = mock.Mock(name='unit_list')
     # Create the new manager
     manager = SessionManager.create_with_unit_list(unit_list)
     # Ensure that a state object was created
     mocks['SessionState'].assert_called_with(unit_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)
     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 create_manager(self, storage):
        """
        Create or resume a session that handles most of the stuff needed to run
        jobs.

        This sets the attr:`_manager` which enables :meth:`manager`,
        :meth:`state` and :meth:`storage` properties.

        The created session state has the on_job_added signal connected to
        :meth:`on_job_added()`.

        :raises SessionResumeError:
            If the session cannot be resumed for any reason.
        """
        all_units = list(
            itertools.chain(*[p.unit_list for p in self.provider_list]))
        try:
            if storage is not None:
                self._manager = SessionManager.load_session(all_units, storage)
            else:
                self._manager = SessionManager.create_with_unit_list(all_units)
        except DependencyDuplicateError as exc:
            # Handle possible DependencyDuplicateError that can happen if
            # someone is using plainbox for job development.
            print(
                self.C.RED(
                    _("The job database you are currently using is broken")))
            print(
                self.C.RED(
                    _("At least two jobs contend for the id {0}").format(
                        exc.job.id)))
            print(
                self.C.RED(
                    _("First job defined in: {0}").format(exc.job.origin)))
            print(
                self.C.RED(
                    _("Second job defined in: {0}").format(
                        exc.duplicate_job.origin)))
            raise SystemExit(exc)
        except SessionResumeError as exc:
            print(self.C.RED(exc))
            print(self.C.RED(_("This session cannot be resumed")))
            raise
        else:
            # Connect the on_job_added signal. We use it to mark the test loop
            # for re-execution and to update the list of desired jobs.
            self.state.on_job_added.connect(self.on_job_added)
Ejemplo n.º 3
0
 def invoked(self, ctx):
     manager_list = []
     for submission in ctx.args.submission:
         tmpdir = TemporaryDirectory()
         self.job_list = []
         self.category_list = []
         session_title = self._parse_submission(submission, tmpdir)
         manager = SessionManager.create_with_unit_list(self.job_list +
                                                        self.category_list)
         manager.state.metadata.title = session_title
         for job in self.job_list:
             self._populate_session_state(job, manager.state)
         manager_list.append(manager)
     exporter = self._create_exporter(
         'com.canonical.plainbox::html-multi-page')
     with open(ctx.args.output_file, 'wb') as stream:
         exporter.dump_from_session_manager_list(manager_list, stream)
     print(ctx.args.output_file)