Exemplo n.º 1
0
    def run(self):
        # Grab a reference to the thread-local state for this thread and put
        # it somewhere that other threads can see it, so that we can be signalled
        # to shut down
        self._subprocess_abort = AgentShell.thread_state.abort

        # We are now stoppable
        self._started.set()

        daemon_log.info(
            "%s.run: %s %s %s" %
            (self.__class__.__name__, self.id, self.action, self.args))
        try:
            AgentShell.thread_state.enable_save()

            agent_daemon_context = AgentDaemonContext(
                self.manager._session._client.sessions._sessions)

            result = self.manager._session._client.action_plugins.run(
                self.action, agent_daemon_context, self.args)
        except CallbackAfterResponse as e:
            self.manager.respond_with_callback(
                self.id, e, AgentShell.thread_state.get_subprocesses())
        except AgentShell.SubprocessAborted:
            self.manager.cancelled(self.id)
        except Exception:
            backtrace = "\n".join(
                traceback.format_exception(*(sys.exc_info())))

            self.manager.fail(self.id, backtrace,
                              AgentShell.thread_state.get_subprocesses())
        else:
            self.manager.succeed(self.id, result,
                                 AgentShell.thread_state.get_subprocesses())
Exemplo n.º 2
0
 def test_run_direct_success_with_context(self):
     """
     Test that we can run an action using ActionPluginManager as the
     daemon would.
     """
     result = ActionPluginManager().run('action_one_with_context',
                                        AgentDaemonContext([]),
                                        {'arg1': "arg1_test"})
     self.assertEqual(result, ACTION_ONE_WITH_CONTEXT_RETVAL)
Exemplo n.º 3
0
    def run(self):
        # Grab a reference to the thread-local state for this thread and put
        # it somewhere that other threads can see it, so that we can be signalled
        # to shut down
        self._subprocess_abort = AgentShell.thread_state.abort

        # We are now stoppable
        self._started.set()

        daemon_log.info("%s.run: %s %s %s" % (self.__class__.__name__, self.id, self.action, self.args))
        try:
            AgentShell.thread_state.enable_save()

            agent_daemon_context = AgentDaemonContext(self.manager._session._client.sessions._sessions)

            result = self.manager._session._client.action_plugins.run(self.action, agent_daemon_context, self.args)
        except CallbackAfterResponse, e:
            self.manager.respond_with_callback(self.id, e, AgentShell.thread_state.get_subprocesses())