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

Proposed by Mike Pontillo
Status: Merged
Approved by: Mike Pontillo
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) Approve
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.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

Lgtm!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/maasserver/models/node.py b/src/maasserver/models/node.py
index 18beda4..3e8872e 100644
--- a/src/maasserver/models/node.py
+++ b/src/maasserver/models/node.py
@@ -3275,7 +3275,10 @@ class Node(CleanSave, TimestampedModel):
3275 def claim_auto_ips(self):3275 def claim_auto_ips(self):
3276 """Assign IP addresses to all interface links set to AUTO."""3276 """Assign IP addresses to all interface links set to AUTO."""
3277 exclude_addresses = set()3277 exclude_addresses = set()
3278 for interface in self.interface_set.all():3278 # Query for the interfaces again here; if we use the cached
3279 # interface_set, we could skip a newly-created bridge if it was created
3280 # at deployment time.
3281 for interface in Interface.objects.filter(node=self):
3279 claimed_ips = interface.claim_auto_ips(3282 claimed_ips = interface.claim_auto_ips(
3280 exclude_addresses=exclude_addresses)3283 exclude_addresses=exclude_addresses)
3281 for ip in claimed_ips:3284 for ip in claimed_ips:
diff --git a/src/maasserver/models/tests/test_node.py b/src/maasserver/models/tests/test_node.py
index 91cdef9..1cf5a41 100644
--- a/src/maasserver/models/tests/test_node.py
+++ b/src/maasserver/models/tests/test_node.py
@@ -5681,6 +5681,28 @@ class TestNodeNetworking(MAASTransactionServerTestCase):
5681 ]5681 ]
5682 self.assertItemsEqual(interfaces, observed_interfaces)5682 self.assertItemsEqual(interfaces, observed_interfaces)
56835683
5684 def test_claim_auto_ips_calls_claim_auto_ips_on_new_added_interface(self):
5685 node = factory.make_Node()
5686 interfaces = [
5687 factory.make_Interface(INTERFACE_TYPE.PHYSICAL, node=node)
5688 for _ in range(2)
5689 ]
5690 mock_claim_auto_ips = self.patch_autospec(Interface, "claim_auto_ips")
5691 node = Node.objects.filter(
5692 id=node.id).prefetch_related('interface_set').first()
5693 # Add in the third interface after we create the node with the cached
5694 # interface_set.
5695 new_iface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL, node=node)
5696 interfaces.append(new_iface)
5697 node.claim_auto_ips()
5698 # Since the interfaces are not ordered, which they dont need to be
5699 # we extract the passed interface to each call.
5700 observed_interfaces = [
5701 call[0][0]
5702 for call in mock_claim_auto_ips.call_args_list
5703 ]
5704 self.assertItemsEqual(interfaces, observed_interfaces)
5705
5684 def test_release_interface_config_calls_release_auto_ips_on_all(self):5706 def test_release_interface_config_calls_release_auto_ips_on_all(self):
5685 node = factory.make_Node()5707 node = factory.make_Node()
5686 interfaces = [5708 interfaces = [

Subscribers

People subscribed via source and target branches