Merge ~mpontillo/maas:fix-websocket-claim-auto-ips--bug-1804557 into maas:master

Proposed by Mike Pontillo on 2018-11-22
Status: Merged
Approved by: Mike Pontillo on 2018-11-22
Approved revision: dd514aac6eae9127f9be2401e798d0eb21bc64b8
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~mpontillo/maas:fix-websocket-claim-auto-ips--bug-1804557
Merge into: maas:master
Diff against target: 49 lines (+26/-1)
2 files modified
src/maasserver/models/node.py (+4/-1)
src/maasserver/models/tests/test_node.py (+22/-0)
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) 2018-11-22 Approve on 2018-11-22
MAAS Lander unittests Pending
Review via email: mp+359164@code.launchpad.net

Commit message

LP: #1804557 - Fix claiming IP addresses for new interfaces over the WebSocket

To post a comment you must log in.
Andres Rodriguez (andreserl) wrote :

Lgtm!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/models/node.py b/src/maasserver/models/node.py
2index 18beda4..3e8872e 100644
3--- a/src/maasserver/models/node.py
4+++ b/src/maasserver/models/node.py
5@@ -3275,7 +3275,10 @@ class Node(CleanSave, TimestampedModel):
6 def claim_auto_ips(self):
7 """Assign IP addresses to all interface links set to AUTO."""
8 exclude_addresses = set()
9- for interface in self.interface_set.all():
10+ # Query for the interfaces again here; if we use the cached
11+ # interface_set, we could skip a newly-created bridge if it was created
12+ # at deployment time.
13+ for interface in Interface.objects.filter(node=self):
14 claimed_ips = interface.claim_auto_ips(
15 exclude_addresses=exclude_addresses)
16 for ip in claimed_ips:
17diff --git a/src/maasserver/models/tests/test_node.py b/src/maasserver/models/tests/test_node.py
18index 91cdef9..1cf5a41 100644
19--- a/src/maasserver/models/tests/test_node.py
20+++ b/src/maasserver/models/tests/test_node.py
21@@ -5681,6 +5681,28 @@ class TestNodeNetworking(MAASTransactionServerTestCase):
22 ]
23 self.assertItemsEqual(interfaces, observed_interfaces)
24
25+ def test_claim_auto_ips_calls_claim_auto_ips_on_new_added_interface(self):
26+ node = factory.make_Node()
27+ interfaces = [
28+ factory.make_Interface(INTERFACE_TYPE.PHYSICAL, node=node)
29+ for _ in range(2)
30+ ]
31+ mock_claim_auto_ips = self.patch_autospec(Interface, "claim_auto_ips")
32+ node = Node.objects.filter(
33+ id=node.id).prefetch_related('interface_set').first()
34+ # Add in the third interface after we create the node with the cached
35+ # interface_set.
36+ new_iface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL, node=node)
37+ interfaces.append(new_iface)
38+ node.claim_auto_ips()
39+ # Since the interfaces are not ordered, which they dont need to be
40+ # we extract the passed interface to each call.
41+ observed_interfaces = [
42+ call[0][0]
43+ for call in mock_claim_auto_ips.call_args_list
44+ ]
45+ self.assertItemsEqual(interfaces, observed_interfaces)
46+
47 def test_release_interface_config_calls_release_auto_ips_on_all(self):
48 node = factory.make_Node()
49 interfaces = [

Subscribers

People subscribed via source and target branches