Merge ~cgrabowski/maas:fix_vlan_discovery into maas:master

Proposed by Christian Grabowski
Status: Merged
Approved by: Alberto Donato
Approved revision: 50f817870f78b6fadfe6f7c0e371d92ef7a93d0c
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~cgrabowski/maas:fix_vlan_discovery
Merge into: maas:master
Diff against target: 71 lines (+7/-15)
3 files modified
src/maasserver/models/interface.py (+2/-10)
src/maasserver/models/tests/test_interface.py (+2/-2)
src/maasserver/models/tests/test_node.py (+3/-3)
Reviewer Review Type Date Requested Status
Alberto Donato (community) Approve
MAAS Lander Needs Fixing
Review via email: mp+424987@code.launchpad.net

Commit message

update report_neighbours test

ignore observed vlan if already exists

Description of the change

This addresses LP:1978981 by instead of updating the existing VLAN's fabric, it ignores the report. This does change the fix for LP:1975477 in that its original fix would identify the existing VLAN by finding a matching subnet if possible, and updating its fabric to the observed one, avoiding the collision prior. So this now both avoids the collision issue and prevents the vlan from being moved unexpectedly.

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

UNIT TESTS
-b fix_vlan_discovery lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/12987/console
COMMIT: 50f817870f78b6fadfe6f7c0e371d92ef7a93d0c

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

LGTM +1

review: Approve
Revision history for this message
Adam Collard (adam-collard) wrote :

jenkins: !test

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/models/interface.py b/src/maasserver/models/interface.py
2index e61e672..e58701f 100644
3--- a/src/maasserver/models/interface.py
4+++ b/src/maasserver/models/interface.py
5@@ -1548,16 +1548,8 @@ class Interface(CleanSave, TimestampedModel):
6
7 if ip:
8 subnet = Subnet.objects.get_best_subnet_for_ip(ip)
9- if subnet:
10- vlan = subnet.vlan
11- vlan.fabric = fabric
12- vlan.save()
13- maaslog.info(
14- "%s: Automatically updated VLAN %d (observed on %s).",
15- self.get_log_string(),
16- vid,
17- vlan.fabric.get_name(),
18- )
19+ # VLAN already exists, don't update it
20+ if subnet and subnet.vlan.vid == vid:
21 return
22
23 vlan, created = VLAN.objects.get_or_create(
24diff --git a/src/maasserver/models/tests/test_interface.py b/src/maasserver/models/tests/test_interface.py
25index 8356f5f..53f37f3 100644
26--- a/src/maasserver/models/tests/test_interface.py
27+++ b/src/maasserver/models/tests/test_interface.py
28@@ -4105,7 +4105,7 @@ class TestReportVID(MAASServerTestCase):
29 new_vlan.description,
30 )
31
32- def test_report_vid_handles_existing_vlan(self):
33+ def test_report_vid_does_not_modify_existing_vlan(self):
34 fabric1 = factory.make_Fabric()
35 fabric2 = factory.make_Fabric()
36 observing_vlan = fabric1.get_default_vlan()
37@@ -4117,7 +4117,7 @@ class TestReportVID(MAASServerTestCase):
38 neighbour_vlan.vid, ip=subnet2.get_next_ip_for_allocation()
39 )
40 neighbour_vlan.refresh_from_db()
41- self.assertEqual(observing_vlan.fabric, neighbour_vlan.fabric)
42+ self.assertEqual(observing_vlan.fabric, fabric1)
43
44
45 class TestInterfaceGetDefaultBridgeName(MAASServerTestCase):
46diff --git a/src/maasserver/models/tests/test_node.py b/src/maasserver/models/tests/test_node.py
47index 50042f2..4a607d8 100644
48--- a/src/maasserver/models/tests/test_node.py
49+++ b/src/maasserver/models/tests/test_node.py
50@@ -10957,7 +10957,7 @@ class TestReportNeighbours(MAASServerTestCase):
51 [call(3, ip=neighbours[0]["ip"]), call(7, ip=neighbours[1]["ip"])]
52 )
53
54- def test_updates_fabric_of_existing_vlan(self):
55+ def test_does_not_updates_fabric_of_existing_vlan(self):
56 rack = factory.make_RackController()
57 observing_fabric = factory.make_Fabric()
58 other_fabric = factory.make_Fabric()
59@@ -10978,10 +10978,10 @@ class TestReportNeighbours(MAASServerTestCase):
60 ]
61 rack.report_neighbours(neighbours)
62 observed_vlan.refresh_from_db()
63- self.assertEqual(observing_fabric, observed_vlan.fabric)
64+ self.assertEqual(other_fabric, observed_vlan.fabric)
65 self.assertEqual(
66 VLAN.objects.filter(
67- vid=observed_vlan.vid, fabric=observing_fabric
68+ vid=observed_vlan.vid, fabric=other_fabric
69 ).count(),
70 1,
71 )

Subscribers

People subscribed via source and target branches