Merge ~sombrafam/maas:fix-dhcp-snnipets into maas:master

Proposed by Erlon R. Cruz
Status: Merged
Approved by: Björn Tillenius
Approved revision: 8fa3f80fe60ef305e20b607d884867e80b7d9360
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~sombrafam/maas:fix-dhcp-snnipets
Merge into: maas:master
Diff against target: 105 lines (+59/-3)
2 files modified
src/maasserver/dhcp.py (+27/-3)
src/maasserver/tests/test_dhcp.py (+32/-0)
Reviewer Review Type Date Requested Status
Björn Tillenius Approve
MAAS Lander Needs Fixing
Alberto Donato (community) Approve
Review via email: mp+391758@code.launchpad.net

Commit message

LP #1809939: dhcp snippet create fail when dhcp subnet is relayed

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b fix-dhcp-snnipets lp:~sombrafam/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/8483/console
COMMIT: 4f13131d8602e078f3b65f359ba007fed041b9cc

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b fix-dhcp-snnipets lp:~sombrafam/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/8498/console
COMMIT: 791cbbed5442b73bf1a6feee091445b62a4ae8ae

review: Needs Fixing
Revision history for this message
Erlon R. Cruz (sombrafam) wrote :

Folks, not sure why the tests above are falling. Can you post the CI logs? The tests I added are passing locally. But, I see several other failures not related to my changes.

Revision history for this message
Dan Streetman (ddstreet) wrote :

you need to run 'make format'

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b fix-dhcp-snnipets lp:~sombrafam/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 32bff2e22a5f436d1ab89c990d59f850a3977b74

review: Approve
Revision history for this message
Alberto Donato (ack) wrote :

Looks good, just a minor nit inline

review: Approve
Revision history for this message
Björn Tillenius (bjornt) wrote :

I think you need to move the fix to another place. See inline comment.

review: Needs Fixing
Revision history for this message
Erlon R. Cruz (sombrafam) wrote :

Hi Björn, please check m inline suggestion.

Revision history for this message
Björn Tillenius (bjornt) :
Revision history for this message
Erlon R. Cruz (sombrafam) :
Revision history for this message
Björn Tillenius (bjornt) :
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b fix-dhcp-snnipets lp:~sombrafam/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/9680/console
COMMIT: ad58af79e08299801c0c914a431751ee519d9613

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b fix-dhcp-snnipets lp:~sombrafam/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 458986983d4cbe0ba7a6d8ad291e9c8cacd00287

review: Approve
Revision history for this message
Björn Tillenius (bjornt) wrote :

Thanks for the fixes! It's looking better now. I still have some comments inline, but it's mostly about style.

I was going to ask you to write a tests for the changes in validate_dhcp_config(), but looking at the existing tests, I suspect it's more work that it's worth... so I'm going to that slip by.

review: Needs Fixing
Revision history for this message
Erlon R. Cruz (sombrafam) wrote :

Ok, good to know. I have added the filter function to the node mixin, but Im curions to nkow why we need to leave them if they are not being used anywere?

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b fix-dhcp-snnipets lp:~sombrafam/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/9706/console
COMMIT: 8fa3f80fe60ef305e20b607d884867e80b7d9360

review: Needs Fixing
Revision history for this message
Björn Tillenius (bjornt) wrote :

Thanks, this is ready to land now!

Even though the subnet filter methods aren't called directly, I think they are called by our filtering/search enging, which get constructs the method name as a string and gets it using getattr(). That's why it won't show up in a simple grep.

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNABLE TO START LANDING

STATUS: MISSING COMMIT MESSAGE

Revision history for this message
MAAS Lander (maas-lander) wrote :
Revision history for this message
MAAS Lander (maas-lander) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/maasserver/dhcp.py b/src/maasserver/dhcp.py
index d903aab..33b89e5 100644
--- a/src/maasserver/dhcp.py
+++ b/src/maasserver/dhcp.py
@@ -36,6 +36,7 @@ from maasserver.models import (
36 Service,36 Service,
37 StaticIPAddress,37 StaticIPAddress,
38 Subnet,38 Subnet,
39 VLAN,
39)40)
40from maasserver.rpc import getAllClients, getClientFor, getRandomClient41from maasserver.rpc import getAllClients, getClientFor, getRandomClient
41from maasserver.utils.orm import transactional42from maasserver.utils.orm import transactional
@@ -961,6 +962,27 @@ def configure_dhcp(rack_controller):
961 raise ipv6_exc962 raise ipv6_exc
962963
963964
965def get_racks_by_subnet(subnet):
966 """Return the set of racks with at least one interface configured on the
967 specified subnet.
968 """
969 racks = RackController.objects.filter(
970 interface__ip_addresses__subnet__in=[subnet]
971 )
972
973 if subnet.vlan.relay_vlan_id:
974 relay_vlan = VLAN.objects.get(id=subnet.vlan.relay_vlan_id)
975 racks = racks.union(
976 RackController.objects.filter(
977 id__in=[
978 relay_vlan.primary_rack_id,
979 relay_vlan.secondary_rack_id,
980 ]
981 )
982 )
983 return racks
984
985
964def validate_dhcp_config(test_dhcp_snippet=None):986def validate_dhcp_config(test_dhcp_snippet=None):
965 """Validate a DHCPD config with uncommitted values.987 """Validate a DHCPD config with uncommitted values.
966988
@@ -995,9 +1017,7 @@ def validate_dhcp_config(test_dhcp_snippet=None):
995 if test_dhcp_snippet is not None:1017 if test_dhcp_snippet is not None:
996 if test_dhcp_snippet.subnet is not None:1018 if test_dhcp_snippet.subnet is not None:
997 rack_controller = find_connected_rack(1019 rack_controller = find_connected_rack(
998 RackController.objects.filter_by_subnets(1020 get_racks_by_subnet(test_dhcp_snippet.subnet)
999 [test_dhcp_snippet.subnet]
1000 )
1001 )1021 )
1002 elif test_dhcp_snippet.node is not None:1022 elif test_dhcp_snippet.node is not None:
1003 rack_controller = find_connected_rack(1023 rack_controller = find_connected_rack(
@@ -1006,6 +1026,10 @@ def validate_dhcp_config(test_dhcp_snippet=None):
1006 # If no rack controller is linked to the DHCPSnippet its a global DHCP1026 # If no rack controller is linked to the DHCPSnippet its a global DHCP
1007 # snippet which we can test anywhere.1027 # snippet which we can test anywhere.
1008 if rack_controller is None:1028 if rack_controller is None:
1029 log.msg(
1030 "Could not find a rack controller for the snippet. Trying "
1031 "random client"
1032 )
1009 try:1033 try:
1010 client = getRandomClient()1034 client = getRandomClient()
1011 except NoConnectionsAvailable:1035 except NoConnectionsAvailable:
diff --git a/src/maasserver/tests/test_dhcp.py b/src/maasserver/tests/test_dhcp.py
index ee0aba5..3e898da 100644
--- a/src/maasserver/tests/test_dhcp.py
+++ b/src/maasserver/tests/test_dhcp.py
@@ -3191,6 +3191,38 @@ class TestValidateDHCPConfig(MAASTransactionServerTestCase):
3191 ),3191 ),
3192 )3192 )
31933193
3194 def test_get_racks_by_subnet_relayed(self):
3195 rack1 = factory.make_RackController()
3196 factory.make_RackController()
3197 vlan1_primary = factory.make_VLAN(dhcp_on=True, primary_rack=rack1)
3198 vlan2_secondary = factory.make_VLAN(
3199 dhcp_on=False, primary_rack=rack1, relay_vlan=vlan1_primary
3200 )
3201
3202 factory.make_Subnet(vlan=vlan1_primary, cidr="10.20.30.0/24")
3203 subnet2 = factory.make_Subnet(
3204 vlan=vlan2_secondary, cidr="10.20.31.0/24"
3205 )
3206 self.assertItemsEqual([rack1], dhcp.get_racks_by_subnet(subnet2))
3207
3208 def test_get_racks_by_subnet_rack_primary(self):
3209 rack1 = factory.make_RackController()
3210 factory.make_RackController()
3211 vlan1_primary = factory.make_VLAN(dhcp_on=True, primary_rack=rack1)
3212 subnet1 = factory.make_Subnet(vlan=vlan1_primary, cidr="10.20.30.0/24")
3213
3214 interface = factory.make_Interface(
3215 INTERFACE_TYPE.PHYSICAL, node=rack1, vlan=vlan1_primary
3216 )
3217
3218 factory.make_StaticIPAddress(
3219 alloc_type=IPADDRESS_TYPE.AUTO,
3220 subnet=subnet1,
3221 interface=interface,
3222 )
3223
3224 self.assertItemsEqual([rack1], dhcp.get_racks_by_subnet(subnet1))
3225
3194 def test_returns_no_errors_when_valid(self):3226 def test_returns_no_errors_when_valid(self):
3195 rack_controller, config = self.create_rack_controller()3227 rack_controller, config = self.create_rack_controller()
3196 self.prepare_rpc(rack_controller)3228 self.prepare_rpc(rack_controller)

Subscribers

People subscribed via source and target branches