示例#1
0
def main(args):
    if "FAKE_GLOBAL_PACKAGE_STORE" in os.environ:
        return run_task_handler(FakeGlobalReporter, args)
    elif "FAKE_PACKAGE_STORE" in os.environ:
        return run_task_handler(FakeReporter, args)
    else:
        return run_task_handler(PackageReporter, args)
示例#2
0
    def test_run_task_handler_when_already_locked_and_quiet_option(self):
        lock_path(os.path.join(self.data_path, "package", "default.lock"))

        try:
            run_task_handler(PackageTaskHandler,
                             ["-c", self.config_filename, "--quiet"])
        except SystemExit as e:
            self.assertEqual(str(e), "")
        else:
            self.fail("SystemExit not raised")
示例#3
0
    def test_run_task_handler_when_already_locked(self):

        lock_path(os.path.join(self.data_path, "package", "default.lock"))

        try:
            run_task_handler(PackageTaskHandler, ["-c", self.config_filename])
        except SystemExit as e:
            self.assertIn("default is already running", str(e))
        else:
            self.fail("SystemExit not raised")
示例#4
0
    def test_errors_are_printed_and_exit_program(self, init_logging_mock):
        class MyException(Exception):
            pass

        self.log_helper.ignore_errors(MyException)

        class HandlerMock(PackageTaskHandler):
            def run(self):
                return fail(MyException("Hey error"))

        # Ok now for some real stuff

        def assert_log(ignored):
            self.assertIn("MyException", self.logfile.getvalue())
            init_logging_mock.assert_called_once_with(ANY, "handler-mock")

        result = run_task_handler(HandlerMock, ["-c", self.config_filename],
                                  reactor=FakeReactor())

        return result.addCallback(assert_log)
示例#5
0
def main(args):
    if os.getpgrp() != os.getpid():
        os.setsid()
    return run_task_handler(PackageChanger, args)
示例#6
0
    def test_run_task_handler(self, lock_path_mock, init_logging_mock,
                              reactor_class_mock, connector_class_mock, umask):
        """
        The L{run_task_handler} function creates and runs the given task
        handler with the proper arguments.
        """
        # Mock the different parts of run_task_handler(), to ensure it
        # does what it's supposed to do, without actually creating files
        # and starting processes.

        # This is a slightly lengthy one, so bear with me.

        # Prepare the mock objects.
        connector_mock = Mock(name="mock-connector")
        connector_class_mock.return_value = connector_mock

        handler_args = []

        class HandlerMock(PackageTaskHandler):
            def __init__(self, *args):
                handler_args.extend(args)
                super(HandlerMock, self).__init__(*args)

        call_when_running = []
        reactor_mock = Mock(name="mock-reactor")
        reactor_class_mock.return_value = reactor_mock
        reactor_mock.call_when_running.side_effect = call_when_running.append
        reactor_mock.run.side_effect = lambda: call_when_running[0]()

        def assert_task_handler(ignored):

            store, facade, broker, config, reactor = handler_args

            # Verify the arguments passed to the reporter constructor.
            self.assertEqual(type(store), PackageStore)
            self.assertEqual(type(facade), AptFacade)
            self.assertEqual(type(broker), LazyRemoteBroker)
            self.assertEqual(type(config), PackageTaskHandlerConfiguration)
            self.assertIn("mock-reactor", repr(reactor))

            # Let's see if the store path is where it should be.
            filename = os.path.join(self.data_path, "package", "database")
            store.add_available([1, 2, 3])
            other_store = PackageStore(filename)
            self.assertEqual(other_store.get_available(), [1, 2, 3])

            # Check the hash=>id database directory as well
            self.assertTrue(
                os.path.exists(
                    os.path.join(self.data_path, "package", "hash-id")))

        result = run_task_handler(HandlerMock, ["-c", self.config_filename])

        # Assert that we acquired a lock as the same task handler should
        # never have two instances running in parallel.  The 'default'
        # below comes from the queue_name attribute.
        lock_path_mock.assert_called_once_with(
            os.path.join(self.data_path, "package", "default.lock"))

        # Once locking is done, it's safe to start logging without
        # corrupting the file.  We don't want any output unless it's
        # breaking badly, so the quiet option should be set.
        init_logging_mock.assert_called_once_with(ANY, "handler-mock")

        connector_mock.disconnect.assert_called_once_with()
        reactor_mock.call_later.assert_called_once_with(0, ANY)

        # We also expect the umask to be set appropriately before running the
        # commands
        umask.assert_called_once_with(0o22)

        return result.addCallback(assert_task_handler)
示例#7
0
def main(args):
    if os.getpgrp() != os.getpid():
        os.setsid()
    return run_task_handler(ReleaseUpgrader, args)