Merge lp:~blake-rouse/maas/fix-1401983 into lp:~maas-committers/maas/trunk

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 3425
Proposed branch: lp:~blake-rouse/maas/fix-1401983
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 73 lines (+31/-5)
2 files modified
src/maasserver/api/pxeconfig.py (+9/-4)
src/maasserver/api/tests/test_pxeconfig.py (+22/-1)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-1401983
Reviewer Review Type Date Requested Status
Jason Hobbs (community) Approve
Newell Jensen (community) Approve
Review via email: mp+244646@code.launchpad.net

Commit message

Previously every PXE request would update the nodes pxe_mac link even if it was already that value. This make sure that it is only update when the mac address that was PXE booted changes.

To post a comment you must log in.
Revision history for this message
Newell Jensen (newell-jensen) wrote :

LGTM.

review: Approve
Revision history for this message
Jason Hobbs (jason-hobbs) wrote :

approve

review: Approve
Revision history for this message
Andres Rodriguez (andreserl) wrote :
Download full text (3.8 KiB)

Great! I think we need a backport to 1.7
On Dec 12, 2014 2:24 PM, "Blake Rouse" <email address hidden> wrote:

> Blake Rouse has proposed merging lp:~blake-rouse/maas/fix-1401983 into
> lp:maas.
>
> Commit message:
> Previously every PXE request would update the nodes pxe_mac link even if
> it was already that value. This make sure that it is only update when the
> mac address that was PXE booted changes.
>
> Requested reviews:
> MAAS Maintainers (maas-maintainers)
> Related bugs:
> Bug #1401983 in MAAS: "Exception: deadlock detected"
> https://bugs.launchpad.net/maas/+bug/1401983
>
> For more details, see:
> https://code.launchpad.net/~blake-rouse/maas/fix-1401983/+merge/244646
> --
> You are subscribed to branch lp:maas.
>
> === modified file 'src/maasserver/api/pxeconfig.py'
> --- src/maasserver/api/pxeconfig.py 2014-12-09 15:51:13 +0000
> +++ src/maasserver/api/pxeconfig.py 2014-12-12 19:23:43 +0000
> @@ -168,10 +168,15 @@
> node = get_node_from_mac_string(request_mac)
>
> if node is not None:
> - # Update the record of which MAC address and cluster interface
> - # this node uses to PXE boot.
> - node.pxe_mac = MACAddress.objects.get(mac_address=request_mac)
> - node.save()
> + # Only update the PXE booting interface for the node if it has
> + # changed.
> + if (node.pxe_mac is None or
> + node.pxe_mac.mac_address != request_mac):
> + node.pxe_mac = MACAddress.objects.get(mac_address=request_mac)
> + node.save()
> +
> + # Update the record of the cluster interface this node uses
> + # to PXE boot.
> update_mac_cluster_interfaces(request_ip, request_mac,
> node.nodegroup)
>
> if node is None or node.get_boot_purpose() == "commissioning":
>
> === modified file 'src/maasserver/api/tests/test_pxeconfig.py'
> --- src/maasserver/api/tests/test_pxeconfig.py 2014-12-09 15:51:13 +0000
> +++ src/maasserver/api/tests/test_pxeconfig.py 2014-12-12 19:23:43 +0000
> @@ -40,6 +40,7 @@
> Config,
> Event,
> MACAddress,
> + Node,
> )
> from maasserver.preseed import (
> compose_enlistment_preseed_url,
> @@ -501,9 +502,19 @@
> description,
> Event.objects.get(node=node).description)
>
> - def test_pxeconfig_updates_pxe_mac_for_existing_node(self):
> + def test_pxeconfig_sets_pxe_mac_when_empty(self):
> + node = factory.make_Node(mac=True)
> + mac = node.macaddress_set.first()
> + params = self.get_default_params()
> + params['mac'] = mac.mac_address
> + self.client.get(reverse('pxeconfig'), params)
> + node = reload_object(node)
> + self.assertEqual(mac, node.pxe_mac)
> +
> + def test_pxeconfig_updates_pxe_mac_when_changed(self):
> node = factory.make_Node()
> node.pxe_mac = factory.make_MACAddress(node=node)
> + node.save()
> mac = factory.make_MACAddress(node=node)
> params = self.get_default_params()
> params['mac'] = mac.mac_address
> @@ -511,6 +522,16 @@
> node = reload_object(node)
> self.assertEqual(mac, node.pxe_mac)
>
>...

Read more...

Revision history for this message
Jason Hobbs (jason-hobbs) wrote :

This also seems to help the performance issue in oil.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/api/pxeconfig.py'
2--- src/maasserver/api/pxeconfig.py 2014-12-09 15:51:13 +0000
3+++ src/maasserver/api/pxeconfig.py 2014-12-12 19:23:43 +0000
4@@ -168,10 +168,15 @@
5 node = get_node_from_mac_string(request_mac)
6
7 if node is not None:
8- # Update the record of which MAC address and cluster interface
9- # this node uses to PXE boot.
10- node.pxe_mac = MACAddress.objects.get(mac_address=request_mac)
11- node.save()
12+ # Only update the PXE booting interface for the node if it has
13+ # changed.
14+ if (node.pxe_mac is None or
15+ node.pxe_mac.mac_address != request_mac):
16+ node.pxe_mac = MACAddress.objects.get(mac_address=request_mac)
17+ node.save()
18+
19+ # Update the record of the cluster interface this node uses
20+ # to PXE boot.
21 update_mac_cluster_interfaces(request_ip, request_mac, node.nodegroup)
22
23 if node is None or node.get_boot_purpose() == "commissioning":
24
25=== modified file 'src/maasserver/api/tests/test_pxeconfig.py'
26--- src/maasserver/api/tests/test_pxeconfig.py 2014-12-09 15:51:13 +0000
27+++ src/maasserver/api/tests/test_pxeconfig.py 2014-12-12 19:23:43 +0000
28@@ -40,6 +40,7 @@
29 Config,
30 Event,
31 MACAddress,
32+ Node,
33 )
34 from maasserver.preseed import (
35 compose_enlistment_preseed_url,
36@@ -501,9 +502,19 @@
37 description,
38 Event.objects.get(node=node).description)
39
40- def test_pxeconfig_updates_pxe_mac_for_existing_node(self):
41+ def test_pxeconfig_sets_pxe_mac_when_empty(self):
42+ node = factory.make_Node(mac=True)
43+ mac = node.macaddress_set.first()
44+ params = self.get_default_params()
45+ params['mac'] = mac.mac_address
46+ self.client.get(reverse('pxeconfig'), params)
47+ node = reload_object(node)
48+ self.assertEqual(mac, node.pxe_mac)
49+
50+ def test_pxeconfig_updates_pxe_mac_when_changed(self):
51 node = factory.make_Node()
52 node.pxe_mac = factory.make_MACAddress(node=node)
53+ node.save()
54 mac = factory.make_MACAddress(node=node)
55 params = self.get_default_params()
56 params['mac'] = mac.mac_address
57@@ -511,6 +522,16 @@
58 node = reload_object(node)
59 self.assertEqual(mac, node.pxe_mac)
60
61+ def test_pxeconfig_doesnt_update_pxe_mac_when_same(self):
62+ node = factory.make_Node()
63+ node.pxe_mac = factory.make_MACAddress(node=node)
64+ node.save()
65+ params = self.get_default_params()
66+ params['mac'] = node.pxe_mac.mac_address
67+ mock_save = self.patch(Node, 'save')
68+ self.client.get(reverse('pxeconfig'), params)
69+ self.assertThat(mock_save, MockNotCalled())
70+
71 def test_pxeconfig_returns_commissioning_os_series_for_other_oses(self):
72 osystem = Config.objects.get_config('default_osystem')
73 release = Config.objects.get_config('default_distro_series')