Merge lp:~andreserl/maas/fix_ipmi_command_execution into lp:~maas-committers/maas/trunk

Proposed by Andres Rodriguez
Status: Merged
Approved by: Andres Rodriguez
Approved revision: no longer in the source branch.
Merged at revision: 1199
Proposed branch: lp:~andreserl/maas/fix_ipmi_command_execution
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 34 lines (+8/-2)
1 file modified
src/provisioningserver/power/templates/ipmi.template (+8/-2)
To merge this branch: bzr merge lp:~andreserl/maas/fix_ipmi_command_execution
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Andres Rodriguez Pending
Review via email: mp+128358@code.launchpad.net

This proposal supersedes a proposal from 2012-10-06.

Commit message

Minor improvements to IPMI template

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote : Posted in a previous version of this proposal

This branch fixes the ipmi command executing as in a particular case it produced an error, due to recent changes I introduced. I'm approving this branch myself as there's no one to review and this gets the issue fixed. It has been tested.

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote : Posted in a previous version of this proposal

No commit message specified.

Revision history for this message
Gavin Panella (allenap) wrote : Posted in a previous version of this proposal

I think there are a couple of errors in here that need fixing, in a
follow-up branch now this has merged.

[1]

+formulate_power_command() {
+    case $1 in
+    'on') echo '--cycle --on-if-off' ;;
+    'off') echo '--off' ;;
+    *)
+        echo "Got unknown power state from ipmipower: '$2'" >&2

s/$2/$1/

[2]

+    ${ipmipower} -h ${power_address} -u ${power_user} -p ${power_pass} $*

"$@" is almost always a better choice than $*; the latter will cause
the shell to break arguments that contain white-space into multiple
arguments.

[3]

formulate_power_state() {
     case $2 in

I know you didn't change this, but what does $2 refer to? Please add
comments describing the arguments to this function, and to
formulate_power_command().

review: Needs Fixing
Revision history for this message
Gavin Panella (allenap) :
review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

No commit message specified.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/provisioningserver/power/templates/ipmi.template'
2--- src/provisioningserver/power/templates/ipmi.template 2012-10-06 04:10:16 +0000
3+++ src/provisioningserver/power/templates/ipmi.template 2012-10-06 16:29:23 +0000
4@@ -12,16 +12,22 @@
5 ipmi_chassis_config={{ipmi_chassis_config}}
6 config={{config_dir}}/{{ipmi_config}}
7
8+# Determines the power command needed to execute the desired
9+# action. This function receives ${power_change} as argument.
10 formulate_power_command() {
11 case $1 in
12 'on') echo '--cycle --on-if-off' ;;
13 'off') echo '--off' ;;
14 *)
15- echo "Got unknown power state from ipmipower: '$2'" >&2
16+ echo "Got unknown power state from ipmipower: '$1'" >&2
17 exit 1
18 esac
19 }
20
21+# Determines the current state on which the machine finds itself.
22+# The argument passed comes from IPMI's stat command in the form:
23+# <ipmi-ip-address>: <on/off>
24+# This function evaluates whether it was <on/off>.
25 formulate_power_state() {
26 case $2 in
27 'on') echo 'on' ;;
28@@ -38,7 +44,7 @@
29 echo workaround |\
30 ${ipmi_chassis_config} -h ${power_address} -u ${power_user} -p ${power_pass} --commit --filename ${config}
31 echo workaround |\
32- ${ipmipower} -h ${power_address} -u ${power_user} -p ${power_pass} $*
33+ ${ipmipower} -h ${power_address} -u ${power_user} -p ${power_pass} "$@"
34 }
35
36