Merge lp:~julian-edwards/maas/localboot-amt into lp:~maas-committers/maas/trunk

Proposed by Julian Edwards
Status: Merged
Approved by: Julian Edwards
Approved revision: no longer in the source branch.
Merged at revision: 3247
Proposed branch: lp:~julian-edwards/maas/localboot-amt
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 88 lines (+31/-3)
3 files modified
etc/maas/templates/power/amt.template (+12/-3)
src/maasserver/models/node.py (+8/-0)
src/maasserver/models/tests/test_node.py (+11/-0)
To merge this branch: bzr merge lp:~julian-edwards/maas/localboot-amt
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Review via email: mp+238232@code.launchpad.net

Commit message

Pass a boot_mode option to power templates (which says whether it's a local or a pxe boot) and make the amt template use it. This is to fix a bug with amt where it was always trying to use PXE power-up and resulted in a previously-deployed node failing to power up properly as it tried to PXE.

Description of the change

(This has tested working on my local rig)

To post a comment you must log in.
Revision history for this message
Raphaël Badin (rvb) wrote :

Nicely done! I've tested this on my NUCs as well and it works as expected.

review: Approve
Revision history for this message
Julian Edwards (julian-edwards) wrote :

Thanks for the review!

On Tuesday 14 Oct 2014 07:14:39 you wrote:
> Review: Approve
>
> Nicely done! I've tested this on my NUCs as well and it works as expected.

Ta.

> > +# boot_mode tells us whether we're pxe booting or local booting. For
> > local
> > +# booting, the argument to amttool must be empty (NOT 'hd', it doesn't
> > work!). +if [ "$boot_mode" = 'local' ]; then
> > + boot_mode=''
> > +fi
>
> The discrepancy between the passed 'boot_mode' and what the amt command uses
> makes reusing the same variable awkward I think. How about using
> 'boot_mode' as the name of the variable MAAS passes and something else, for
> instance 'amt_boot_mode', for the parameter AMT consumes? I think it would
> make the template more readable.

Sure. I was just trying to keep the template concise.

> > +
> > + # boot_mode is something that tells the template whether this is
> > + # a PXE boot or a local HD boot.
>
> I'd explain that this is something that the power templates can use but that
> it is mostly useful for the power types that don't support having a PXE
> config that says "Boot from local disk." AFAIK, none of the other power
> types need this: they can always PXE boot and they simply use a special PXE
> config when MAAS wants the nodes to boot from local disk.

Actually most power types do support this! IPMI is already using it, but it
uses a fixed config file. It would be nice to drive it from here instead at
some point.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'etc/maas/templates/power/amt.template'
2--- etc/maas/templates/power/amt.template 2014-10-01 20:44:21 +0000
3+++ etc/maas/templates/power/amt.template 2014-10-14 09:28:38 +0000
4@@ -13,6 +13,7 @@
5 power_change={{power_change}}
6 power_pass={{power_pass}}
7 ip_address={{ip_address}}
8+boot_mode={{boot_mode}}
9
10 # The user specified power_address overrides any automatically determined
11 # ip_address.
12@@ -20,6 +21,14 @@
13 ip_address=$power_address
14 fi
15
16+# boot_mode tells us whether we're pxe booting or local booting. For local
17+# booting, the argument to amttool must be empty (NOT 'hd', it doesn't work!).
18+if [ "$boot_mode" = 'local' ]; then
19+ amt_boot_mode=''
20+else
21+ amt_boot_mode=$boot_mode
22+fi
23+
24
25 # Exit with failure message.
26 # Parameters: exit code, and error message.
27@@ -82,9 +91,9 @@
28 }
29
30
31-# Power-cycle the machine, and boot it using PXE.
32+# Power-cycle the machine, and boot it using the requested boot mode.
33 restart() {
34- issue_amt_command powercycle pxe
35+ issue_amt_command powercycle "$amt_boot_mode"
36 }
37
38
39@@ -95,7 +104,7 @@
40 for attempts in $(seq 0 10)
41 do
42 # Issue the AMT command; amttool will prompt for confirmation.
43- yes | issue_amt_command powerup pxe
44+ yes | issue_amt_command powerup "$amt_boot_mode"
45 if [ "$(query_state)" = 'on' ]
46 then
47 # Success. Machine is on.
48
49=== modified file 'src/maasserver/models/node.py'
50--- src/maasserver/models/node.py 2014-10-13 01:40:27 +0000
51+++ src/maasserver/models/node.py 2014-10-14 09:28:38 +0000
52@@ -1208,6 +1208,14 @@
53 if primary_mac is not None:
54 mac = primary_mac.mac_address.get_raw()
55 power_params['mac_address'] = mac
56+
57+ # boot_mode is something that tells the template whether this is
58+ # a PXE boot or a local HD boot.
59+ if self.status == NODE_STATUS.DEPLOYED:
60+ power_params['boot_mode'] = 'local'
61+ else:
62+ power_params['boot_mode'] = 'pxe'
63+
64 return power_params
65
66 def get_effective_power_info(self):
67
68=== modified file 'src/maasserver/models/tests/test_node.py'
69--- src/maasserver/models/tests/test_node.py 2014-10-13 01:37:07 +0000
70+++ src/maasserver/models/tests/test_node.py 2014-10-14 09:28:38 +0000
71@@ -544,6 +544,17 @@
72 params = node.get_effective_power_parameters()
73 self.assertEqual("qemu://localhost/system", params["power_address"])
74
75+ def test_get_effective_power_parameters_sets_local_boot_mode(self):
76+ node = factory.make_Node(status=NODE_STATUS.DEPLOYED)
77+ params = node.get_effective_power_parameters()
78+ self.assertEqual("local", params['boot_mode'])
79+
80+ def test_get_effective_power_parameters_sets_pxe_boot_mode(self):
81+ status = factory.pick_enum(NODE_STATUS, but_not=[NODE_STATUS.DEPLOYED])
82+ node = factory.make_Node(status=status)
83+ params = node.get_effective_power_parameters()
84+ self.assertEqual("pxe", params['boot_mode'])
85+
86 def test_get_effective_power_info_is_False_for_unset_power_type(self):
87 node = factory.make_Node(power_type="")
88 self.assertEqual(