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

Proposed by Andres Rodriguez
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 1410
Proposed branch: lp:~andreserl/maas/lp1073462_fence_cdu_power_type
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 148 lines (+93/-0)
5 files modified
src/maasserver/models/node.py (+1/-0)
src/maasserver/power_parameters.py (+20/-0)
src/provisioningserver/enum.py (+4/-0)
src/provisioningserver/power/templates/fence_cdu.template (+54/-0)
src/provisioningserver/power/tests/test_poweraction.py (+14/-0)
To merge this branch: bzr merge lp:~andreserl/maas/lp1073462_fence_cdu_power_type
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Review via email: mp+140504@code.launchpad.net

Commit message

Add fence_cdu power type for SentrySwitch CDU's.

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Looks very nice.

Two small notes:

1. In python, when we have to line-break the arguments to a function call, we start doing so right after the opening parenthesis, so that the arguments start on a line of their own.

So instead of:

    call_function(one_argument,
        another_argument, final_argument)

...we say:

    call_function(
        one_argument, another_argument,
        final_argument)

2. It would be nice if the test explained (in a comment, doesn't need to be very long) how the error condition happens. As I understand it, you substitute "echo" for the power command, and when that command gets called, you get something that isn't recognized as a power state.

I think I probably did this myself at some point. But reading it back now, I realize it's not obvious. So for the sake of whoever maintains the code next, it would be helpful to point out this subtlety.

Jeroen

review: Approve
Revision history for this message
Andres Rodriguez (andreserl) wrote :

Hi Jeroen,

Thanks for the review!

[1] I don't understand it :). The only place where a line-break would be required is inside the test_fence_cdu_checks_state function, in the line 134 which calls render_template.... However, this line-break is correctly place for such call... The whole diff follows the same code as to what the code currently is:

134 + script = action.render_template(
135 + action.get_template(), power_change='on',
136 + power_address='mysystem', power_id='system',
137 + power_user='me', power_pass='me', fence_cdu='echo')

[2]: Fixed.

Thanks!

Revision history for this message
Raphaël Badin (rvb) wrote :

I think Jeroen was referring to that piece of code:

24 + 'power_id',
25 + forms.CharField(label="Power ID",
26 + required=False)),
27 + (
28 + 'power_address',
29 + forms.CharField(label="IP Address or Hostname",
30 + required=False)),

Instead of:

forms.CharField(label="Power ID",
    required=False))

You should write:

forms.CharField(
    label="Power ID", required=False))

Revision history for this message
MAAS Lander (maas-lander) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/maas-merger-trunk/159/console reported an error when processing this lp:~andreserl/maas/lp1073462_fence_cdu_power_type branch.
Not merging it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/maasserver/models/node.py'
--- src/maasserver/models/node.py 2012-12-18 12:31:47 +0000
+++ src/maasserver/models/node.py 2012-12-19 17:24:23 +0000
@@ -768,6 +768,7 @@
768768
769 power_params.setdefault('system_id', self.system_id)769 power_params.setdefault('system_id', self.system_id)
770 power_params.setdefault('virsh', '/usr/bin/virsh')770 power_params.setdefault('virsh', '/usr/bin/virsh')
771 power_params.setdefault('fence_cdu', '/usr/sbin/fence_cdu')
771 power_params.setdefault('ipmipower', '/usr/sbin/ipmipower')772 power_params.setdefault('ipmipower', '/usr/sbin/ipmipower')
772 power_params.setdefault(773 power_params.setdefault(
773 'ipmi_chassis_config', '/usr/sbin/ipmi-chassis-config')774 'ipmi_chassis_config', '/usr/sbin/ipmi-chassis-config')
774775
=== modified file 'src/maasserver/power_parameters.py'
--- src/maasserver/power_parameters.py 2012-09-17 17:27:02 +0000
+++ src/maasserver/power_parameters.py 2012-12-19 17:24:23 +0000
@@ -64,6 +64,26 @@
64 ],64 ],
65 required=False,65 required=False,
66 skip_check=True),66 skip_check=True),
67 POWER_TYPE.CDU:
68 DictCharField(
69 [
70 (
71 'power_id',
72 forms.CharField(label="Power ID",
73 required=False)),
74 (
75 'power_address',
76 forms.CharField(label="IP Address or Hostname",
77 required=False)),
78 (
79 'power_user',
80 forms.CharField(label="Username", required=False)),
81 (
82 'power_pass',
83 forms.CharField(label="Password", required=False)),
84 ],
85 required=False,
86 skip_check=True),
67 POWER_TYPE.IPMI:87 POWER_TYPE.IPMI:
68 DictCharField(88 DictCharField(
69 [89 [
7090
=== modified file 'src/provisioningserver/enum.py'
--- src/provisioningserver/enum.py 2012-09-17 17:27:02 +0000
+++ src/provisioningserver/enum.py 2012-12-19 17:24:23 +0000
@@ -33,6 +33,9 @@
33 # Network wake-up.33 # Network wake-up.
34 WAKE_ON_LAN = 'ether_wake'34 WAKE_ON_LAN = 'ether_wake'
3535
36 # Sentry Switch CDU's.
37 CDU = 'fence_cdu'
38
36 # IPMI (Intelligent Platform Management Interface).39 # IPMI (Intelligent Platform Management Interface).
37 IPMI = 'ipmi'40 IPMI = 'ipmi'
3841
@@ -40,6 +43,7 @@
40POWER_TYPE_CHOICES = (43POWER_TYPE_CHOICES = (
41 (POWER_TYPE.VIRSH, "virsh (virtual systems)"),44 (POWER_TYPE.VIRSH, "virsh (virtual systems)"),
42 (POWER_TYPE.WAKE_ON_LAN, "Wake-on-LAN"),45 (POWER_TYPE.WAKE_ON_LAN, "Wake-on-LAN"),
46 (POWER_TYPE.CDU, "Sentry Switch CDU"),
43 (POWER_TYPE.IPMI, "IPMI"),47 (POWER_TYPE.IPMI, "IPMI"),
44 )48 )
4549
4650
=== added file 'src/provisioningserver/power/templates/fence_cdu.template'
--- src/provisioningserver/power/templates/fence_cdu.template 1970-01-01 00:00:00 +0000
+++ src/provisioningserver/power/templates/fence_cdu.template 2012-12-19 17:24:23 +0000
@@ -0,0 +1,54 @@
1# -*- mode: shell-script -*-
2#
3# Control virtual system's "power" through virsh.
4#
5
6# Parameters.
7# Choose command for virsh to make the requested power change happen.
8power_change={{power_change}}
9power_address={{power_address}}
10power_user={{power_user}}
11power_pass={{power_pass}}
12power_id={{power_id}}
13fence_cdu={{fence_cdu}}
14
15
16formulate_power_command() {
17 if [ ${power_change} = 'on' ]
18 then
19 echo 'on'
20 else
21 echo 'off'
22 fi
23}
24
25
26# Express system's current state as expressed by virsh as "on" or "off".
27formulate_power_state() {
28 case $2 in
29 'on'|'ON') echo 'on' ;;
30 'off'|'OFF') echo 'off' ;;
31 *)
32 echo "Got unknown power state from fence_cdu: '$1'" >&2
33 exit 1
34 esac
35}
36
37
38# Issue command to virsh, for the given system.
39issue_fence_cdu_command() {
40 ${fence_cdu} -a ${power_address} -n ${power_id} -l ${power_user} -p ${power_pass} -o "$@"
41}
42
43
44# Get the given system's power state: 'on' or 'off'.
45get_power_state() {
46 fence_cdu_state=$(issue_fence_cdu_command status)
47 formulate_power_state ${fence_cdu_state}
48}
49
50
51if [ "$(get_power_state)" != "${power_change}" ]
52then
53 issue_fence_cdu_command $(formulate_power_command)
54fi
055
=== modified file 'src/provisioningserver/power/tests/test_poweraction.py'
--- src/provisioningserver/power/tests/test_poweraction.py 2012-10-05 16:33:37 +0000
+++ src/provisioningserver/power/tests/test_poweraction.py 2012-12-19 17:24:23 +0000
@@ -159,6 +159,20 @@
159 stdout, stderr = action.run_shell(script)159 stdout, stderr = action.run_shell(script)
160 self.assertIn("Got unknown power state from virsh", stderr)160 self.assertIn("Got unknown power state from virsh", stderr)
161161
162 def test_fence_cdu_checks_state(self):
163 # We can't test the fence_cdu template in detail (and it may be
164 # customized), but by making it use "echo" instead of a real
165 # fence_cdu we can make it get a bogus answer from its status check.
166 # The bogus answer is actually the rest of the fence_cdu command
167 # line. It will complain about this and fail.
168 action = PowerAction(POWER_TYPE.CDU)
169 script = action.render_template(
170 action.get_template(), power_change='on',
171 power_address='mysystem', power_id='system',
172 power_user='me', power_pass='me', fence_cdu='echo')
173 stdout, stderr = action.run_shell(script)
174 self.assertIn("Got unknown power state from fence_cdu", stderr)
175
162 def test_ipmi_checks_state(self):176 def test_ipmi_checks_state(self):
163 action = PowerAction(POWER_TYPE.IPMI)177 action = PowerAction(POWER_TYPE.IPMI)
164 script = action.render_template(178 script = action.render_template(