Merge lp:~newell-jensen/maas/ipmi-regex-return-output-when-no-match into lp:maas/1.9

Proposed by Newell Jensen on 2016-04-25
Status: Merged
Approved by: Newell Jensen on 2016-04-25
Approved revision: 4567
Merged at revision: 4567
Proposed branch: lp:~newell-jensen/maas/ipmi-regex-return-output-when-no-match
Merge into: lp:maas/1.9
Diff against target: 62 lines (+6/-12)
2 files modified
src/provisioningserver/drivers/power/ipmi.py (+3/-6)
src/provisioningserver/drivers/power/tests/test_ipmi.py (+3/-6)
To merge this branch: bzr merge lp:~newell-jensen/maas/ipmi-regex-return-output-when-no-match
Reviewer Review Type Date Requested Status
Andres Rodriguez 2016-04-25 Approve on 2016-04-25
Review via email: mp+292859@code.launchpad.net

Commit message

Return output from ipmipower for _issue_ipmi_command when there is no match with the regex.

To post a comment you must log in.
Andres Rodriguez (andreserl) wrote :

lgtm!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/provisioningserver/drivers/power/ipmi.py'
2--- src/provisioningserver/drivers/power/ipmi.py 2016-04-25 16:30:09 +0000
3+++ src/provisioningserver/drivers/power/ipmi.py 2016-04-25 21:27:11 +0000
4@@ -25,7 +25,6 @@
5 from provisioningserver.drivers.power import (
6 PowerAuthError,
7 PowerDriver,
8- PowerError,
9 PowerFatalError,
10 )
11 from provisioningserver.logger import get_maas_logger
12@@ -99,13 +98,11 @@
13 "Failed to power %s %s: %s" % (
14 power_change, power_address, e.output_as_unicode))
15 else:
16- match = re.search(":\s*(on|off|ok)", output)
17+ match = re.search(":\s*(on|off)", output)
18 if match is None:
19- raise PowerError(
20- "IPMI Power Driver unable to extract node power"
21- " state from: %s" % output)
22+ return output
23 else:
24- # If there is a match this should be either on/off/ok
25+ # If there is a match this will be either on/off
26 return match.group(1)
27
28 def _issue_ipmi_command(
29
30=== modified file 'src/provisioningserver/drivers/power/tests/test_ipmi.py'
31--- src/provisioningserver/drivers/power/tests/test_ipmi.py 2016-04-23 00:17:34 +0000
32+++ src/provisioningserver/drivers/power/tests/test_ipmi.py 2016-04-25 21:27:11 +0000
33@@ -30,7 +30,6 @@
34 from provisioningserver.drivers.power import (
35 ipmi as ipmi_module,
36 PowerAuthError,
37- PowerError,
38 PowerFatalError,
39 )
40 from provisioningserver.drivers.power.ipmi import (
41@@ -313,7 +312,7 @@
42 PowerFatalError, ipmi_power_driver._issue_ipmi_command,
43 'on', **context)
44
45- def test__issue_ipmi_command_crashes_when_unable_to_find_match(self):
46+ def test__issue_ipmi_command_returns_output_when_no_regex_match(self):
47 _, _, _, _, _, _, _, context = make_parameters()
48 ipmi_power_driver = IPMIPowerDriver()
49 popen_mock = self.patch(ipmi_module, 'Popen')
50@@ -322,10 +321,8 @@
51 process.returncode = 0
52 call_and_check_mock = self.patch(ipmi_module, 'call_and_check')
53 call_and_check_mock.return_value = "Rubbish"
54-
55- self.assertRaises(
56- PowerError, ipmi_power_driver._issue_ipmi_command,
57- 'on', **context)
58+ result = ipmi_power_driver._issue_ipmi_command('on', **context)
59+ self.assertEqual(result, "Rubbish")
60
61 def test_power_on_calls__issue_ipmi_command(self):
62 _, _, _, _, _, _, _, context = make_parameters()

Subscribers

People subscribed via source and target branches