Merge lp:~gz/maas/detailed_poweractionfail_1155175 into lp:~maas-committers/maas/trunk
Status: | Merged |
---|---|
Approved by: | Martin Packman |
Approved revision: | no longer in the source branch. |
Merged at revision: | 1456 |
Proposed branch: | lp:~gz/maas/detailed_poweractionfail_1155175 |
Merge into: | lp:~maas-committers/maas/trunk |
Diff against target: |
145 lines (+40/-32) 2 files modified
src/provisioningserver/power/poweraction.py (+18/-17) src/provisioningserver/power/tests/test_poweraction.py (+22/-15) |
To merge this branch: | bzr merge lp:~gz/maas/detailed_poweractionfail_1155175 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Julian Edwards (community) | Approve | ||
Review via email: mp+153425@code.launchpad.net |
Commit message
Give more detailed error message on failures from power management scripts
Description of the change
Give more detailed error message on failures from power management scripts.
This changes how the scripts are called a little to take advantage of nicer wrappers included in Python 2.7, and customises the PowerActionFail exception type to stringify with more details.
How exactly we want the output shown is an open question, currently it's just on (at least one) new line in the error string, perhaps indenting or otherwise wrapping it would be preferable.
Docstring update was needed, part of it (taking **kwargs) is just wrong, and the return is entirely ignored in real code so should probably not be promised.
Some testing specifics were fiddled with, just to make a couple of changes slightly neater.
--
Thanks for the branch Martin, a definite improvement. I am a little concerned about one of the changes in [2] below so marking needs-fixing for that.
Cheers.
[1]
53 + output = subprocess. check_output( subprocess. STDOUT, close_fds=True)
54 + commands, shell=True, stderr=
55 + except Exception as e:
Catching a bare Exception is bad form, can you be more specific? The original caught OSError.
[2]
56 + raise PowerActionFail (self, e)
57 + # This output is only examined in tests, execute just ignores it
58 + return output
You've changed this from a PIPE to using the parent's FDs. I wrote the original code and although I can't remember why I used a PIPE I am pretty sure I had a good reason, so I reckon you should change it back to PIPE. I have a sneaking suspicion that some of the scripts caused a hang or something weird in the output from the celery process.
I should have added a comment about it :/
[3]
Our coding standards say to add a line break immediately after an opening parenthesis, so can you fix the following bits please:
86 + self.assertThat (lambda: pa.render_ template( template) , MatchesExceptio n(PowerActionFa il, template_ name))) )
87 + Raises(
88 + ".*name 'mac' is not defined at line \d+ column \d+ "
89 + "in file %s" % re.escape(
snip....
95 def test_execute_ raises_ PowerActionFail _when_script_ fails(self) : template_ file("this_ is_not_ valid_shell" ) es(PowerActionF ail, self.run_action, path) (lambda: self.run_ action( path), MatchesExceptio n(PowerActionFa il, raises_ PowerActionFail _with_output( self): template_ file("echo reason for failure; exit 1") (lambda: self.run_ action( path), MatchesExceptio n(PowerActionFa il, ".*:\nreason for failure")))
96 path = self._create_
97 - exception = self.assertRais
98 - self.assertEqual(
99 - "ether_wake failed with return code 127", exception.message)
100 + self.assertThat
101 + Raises(
102 + "ether_wake failed.* return.* 127")))
103 +
104 + def test_execute_
105 + path = self._create_
106 + self.assertThat
107 + Raises(