Merge lp://qastaging/~nobuto/charm-helpers/execd into lp://qastaging/charm-helpers

Proposed by Nobuto Murata
Status: Merged
Merged at revision: 636
Proposed branch: lp://qastaging/~nobuto/charm-helpers/execd
Merge into: lp://qastaging/charm-helpers
Diff against target: 75 lines (+20/-17)
2 files modified
charmhelpers/payload/execd.py (+3/-2)
tests/payload/test_execd.py (+17/-15)
To merge this branch: bzr merge lp://qastaging/~nobuto/charm-helpers/execd
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+306700@code.qastaging.launchpad.net

Description of the change

Don't ignore errors in execd_run and record error messages by default

As execd_run is a part of hook execution, it should fail when it has errors so that users can clearly notice the error and re-run the hook.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Yes, its unfortunate how much 'ignore errors by default' is used in charmhelpers when that is never the right thing to do for charms.

I've got one minor inline comment. We need at least one of the tests to call execd_run without the die_on_error argument so we can ensure the default is set correctly.

Note that reactive charms have this functionality built in (lib/charms/layer/execd.py), and its behaviour matches what is proposed here.

review: Needs Fixing
Revision history for this message
Nobuto Murata (nobuto) wrote :

Reflected review comments, but I found the test is failing with Python 3. I don't know how to handle this, but will look into it.

======================================================================
FAIL: tests.payload.test_execd.ExecDTestCase.test_execd_run_logs_exception
----------------------------------------------------------------------
testtools.testresult.real._StringException: Traceback (most recent call last):
  File "/home/nobuto/dev/charm-helpers_execd/.venv3/lib/python3.5/site-packages/mock.py", line 1201, in patched
    return func(*args, **keywargs)
  File "/home/nobuto/dev/charm-helpers_execd/tests/payload/test_execd.py", line 142, in test_execd_run_logs_exception
    log_.assert_called_with(expected_log)
  File "/home/nobuto/dev/charm-helpers_execd/.venv3/lib/python3.5/site-packages/mock.py", line 835, in assert_called_with
    raise AssertionError(msg)
AssertionError: Expected call: log('Error (1) running /tmp/tmp11nk64mu/exec.d/basenode/charm-pre-install. Output: stdout_from_pre_install\nstderr_from_pre_install\n')
Actual call: log("Error (1) running /tmp/tmp11nk64mu/exec.d/basenode/charm-pre-install. Output: b'stdout_from_pre_install\\nstderr_from_pre_install\\n'")

Revision history for this message
Stuart Bishop (stub) wrote :

execd_run() is doing "subprocess.check_output(submodule_path, stderr=stderr)", which returns a byte string rather than text. Change that to "subprocess.check_output(submodule_path, stderr=stderr, universal_newlines=True)" or similar to have it return the output as a standard text string (unicode).

Revision history for this message
Nobuto Murata (nobuto) wrote :

Thanks for the kind comment. I have pushed the change.

Revision history for this message
Stuart Bishop (stub) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches