juju command should have tests for return nonzero status code on errors

Bug #697093 reported by Jim Baker
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pyjuju
Triaged
Low
Unassigned

Bug Description

Currently the ensemble command will return a zero status code for execution errors. (Parsing errors, because of the use of argparse, returns the de facto standard status code of 2.) Presumably we should use status code 1, but regardless it should not be 0.

The mocking in control tests should be changed to reflect this, that is self.setup_exit(1) instead of self.setup_exit(0).

Tags: cli
Jim Baker (jimbaker)
description: updated
Changed in ensemble:
milestone: none → capetown
importance: Undecided → Low
tags: added: cli
Changed in ensemble:
milestone: capetown → budapest
Changed in ensemble:
milestone: budapest → dublin
Changed in ensemble:
milestone: dublin → none
Jim Baker (jimbaker)
Changed in ensemble:
milestone: none → eureka
assignee: nobody → Jim Baker (jimbaker)
Revision history for this message
Clint Byrum (clint-fewbar) wrote :

Raising to Medium. This can be worked around, but it would promote better practices to always return sane error codes.

Changed in ensemble:
importance: Low → Medium
Revision history for this message
Jim Baker (jimbaker) wrote :

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.

Changed in juju:
assignee: Jim Baker (jimbaker) → nobody
milestone: eureka → florence
Changed in juju:
status: New → Confirmed
Changed in juju:
milestone: florence → galapagos
summary: - Ensemble command should return nonzero status code for errors
+ juju command should have tests for return nonzero status code on errors
Changed in juju:
importance: Medium → Low
Changed in juju:
milestone: galapagos → none
Curtis Hovey (sinzui)
Changed in juju:
status: Confirmed → Triaged
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.