Merge lp:~jtv/maas/bug-1391139 into lp:~maas-committers/maas/trunk

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: no longer in the source branch.
Merged at revision: 3375
Proposed branch: lp:~jtv/maas/bug-1391139
Merge into: lp:~maas-committers/maas/trunk
Prerequisite: lp:~jtv/maas/unify-get_name_and_vlan_from_cluster_interface
Diff against target: 47 lines (+20/-2)
2 files modified
src/maasserver/utils/interfaces.py (+3/-0)
src/maasserver/utils/tests/test_interfaces.py (+17/-2)
To merge this branch: bzr merge lp:~jtv/maas/bug-1391139
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Review via email: mp+241739@code.launchpad.net

Commit message

Fix failure to parse VLAN tags in network interfaces that combine a VLAN and an alias in just the wrong way.

The bug manifested in migration 0099.

Description of the change

Small fix, but based on massive cleanup branch. If I'm on the wrong track, I'll just scuttle the two and forget about the bug.

Jeroen

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/utils/interfaces.py'
2--- src/maasserver/utils/interfaces.py 2014-11-13 20:15:20 +0000
3+++ src/maasserver/utils/interfaces.py 2014-11-13 20:15:20 +0000
4@@ -49,6 +49,9 @@
5 vlan_tag = None
6 if '.' in name:
7 _, vlan_tag = name.split('.', 1)
8+ if ':' in vlan_tag:
9+ # Nasty: there's an alias after the VLAN tag.
10+ vlan_tag, _ = vlan_tag.split(':', 1)
11 name = name.replace('.', '-')
12 name = name.replace(':', '-')
13 network_name = "-".join((cluster_name, name))
14
15=== modified file 'src/maasserver/utils/tests/test_interfaces.py'
16--- src/maasserver/utils/tests/test_interfaces.py 2014-11-13 20:15:20 +0000
17+++ src/maasserver/utils/tests/test_interfaces.py 2014-11-13 20:15:20 +0000
18@@ -80,8 +80,7 @@
19 (expected_name, '%d' % vlan_tag),
20 get_name_and_vlan_from_cluster_interface(cluster, interface))
21
22- def test_returns_name_with_crazy_colon_and_vlan(self):
23- # For truly twisted network admins.
24+ def test_returns_name_with_alias_and_vlan_tag(self):
25 cluster = factory.make_name('cluster')
26 base_interface = self.make_interface()
27 vlan_tag = factory.make_vlan_tag()
28@@ -96,3 +95,19 @@
29 self.assertEqual(
30 (expected_name, '%d' % vlan_tag),
31 get_name_and_vlan_from_cluster_interface(cluster, interface))
32+
33+ def test_returns_name_with_vlan_tag_and_alias(self):
34+ cluster = factory.make_name('cluster')
35+ base_interface = self.make_interface()
36+ vlan_tag = factory.make_vlan_tag()
37+ alias = randint(0, 99)
38+ interface = '%s.%d:%d' % (base_interface, vlan_tag, alias)
39+ expected_name = '%s-%s-%d-%d' % (
40+ cluster,
41+ base_interface,
42+ vlan_tag,
43+ alias,
44+ )
45+ self.assertEqual(
46+ (expected_name, '%d' % vlan_tag),
47+ get_name_and_vlan_from_cluster_interface(cluster, interface))