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

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 3323
Proposed branch: lp:~blake-rouse/maas/fix-1401983-1.7
Merge into: lp:maas/1.7
Diff against target: 69 lines (+28/-4)
2 files modified
src/maasserver/api/pxeconfig.py (+6/-3)
src/maasserver/api/tests/test_pxeconfig.py (+22/-1)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-1401983-1.7
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+244655@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
Blake Rouse (blake-rouse) wrote :

Self-approve for backport.

review: Approve

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

Subscribers

People subscribed via source and target branches

to all changes: