Comment 2 for bug 697093

Revision history for this message
Jim Baker (jimbaker) wrote : Re: Ensemble command should return nonzero status code for errors

This problem seems to be somewhat different than described in the bug report: as verified by actually running them, commands do in fact exit with nonzero status codes (specifically 1) if any errors are raised to the top level of the command. This is done by _handle_exit in juju.control.command.

However, the testing procedure doesn't work here. When tested, reactor.run is mocked out to be a no-op, and returns immediately; then sys.exit, which is almost mocked out, is immediately called next. This occurs before the command has a chance to complete and in particular before the yield on the deferred that is returned by setup_cli_reactor() in CLI tests.

This seems to be a difficult problem to fix so that the desired testing can be done. The run function in command cannot be async - it is what starts the reactor after all. stop should not just exit, the reactor should shut down cleanly. Nor can run do any blocking code and expect that some callback will unblock - the reactor is run in this thread.