Merge lp:~allenap/maas/guess-address-for-alias--1.5 into lp:maas/1.5

Proposed by Gavin Panella on 2014-07-30
Status: Merged
Approved by: Gavin Panella on 2014-07-30
Approved revision: 2294
Merged at revision: 2293
Proposed branch: lp:~allenap/maas/guess-address-for-alias--1.5
Merge into: lp:maas/1.5
Diff against target: 76 lines (+42/-2)
2 files modified
src/metadataserver/address.py (+2/-2)
src/metadataserver/tests/test_address.py (+40/-0)
To merge this branch: bzr merge lp:~allenap/maas/guess-address-for-alias--1.5
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve on 2014-07-30
Review via email: mp+228818@code.launchpad.net

Commit message

Backport r2616 and r2621 from trunk:

- Make guess_server_address() work with aliased interface names.

- Test find_default_interface() with aliased interfaces. Rename incorrectly named tests for tagged interfaces, then add actual tests for aliased interfaces.

To post a comment you must log in.
Gavin Panella (allenap) wrote :

Selfie.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/metadataserver/address.py'
2--- src/metadataserver/address.py 2013-10-15 11:35:10 +0000
3+++ src/metadataserver/address.py 2014-07-30 10:39:23 +0000
4@@ -63,13 +63,13 @@
5 """
6 route_lines = list(ip_route_output)
7 for line in route_lines:
8- match = re.match('default\s+.*\sdev\s+(\w+)', line)
9+ match = re.match('default\s+.*\sdev\s+([^\s]+)', line)
10 if match is not None:
11 return match.groups()[0]
12
13 # Still nothing? Try the first recognizable interface in the list.
14 for line in route_lines:
15- match = re.match('\s*(?:\S+\s+)*dev\s+(\w+)', line)
16+ match = re.match('\s*(?:\S+\s+)*dev\s+([^\s]+)', line)
17 if match is not None:
18 return match.groups()[0]
19 return None
20
21=== modified file 'src/metadataserver/tests/test_address.py'
22--- src/metadataserver/tests/test_address.py 2013-10-15 11:35:10 +0000
23+++ src/metadataserver/tests/test_address.py 2014-07-30 10:39:23 +0000
24@@ -59,6 +59,26 @@
25 self.assertEqual(
26 'eth1', address.find_default_interface(sample_ip_route))
27
28+ def test_find_default_interface_finds_default_tagged_interface(self):
29+ sample_ip_route = [
30+ "default via 10.20.64.1 dev eth0.2",
31+ "10.14.0.0/16 dev br0 proto kernel scope link src 10.14.4.1",
32+ "10.90.90.0/24 dev br0 proto kernel scope link src 10.90.90.1",
33+ "169.254.0.0/16 dev br0 scope link metric 1000",
34+ ]
35+ self.assertEqual(
36+ 'eth0.2', address.find_default_interface(sample_ip_route))
37+
38+ def test_find_default_interface_finds_default_aliased_interface(self):
39+ sample_ip_route = [
40+ "default via 10.20.64.1 dev eth0:2",
41+ "10.14.0.0/16 dev br0 proto kernel scope link src 10.14.4.1",
42+ "10.90.90.0/24 dev br0 proto kernel scope link src 10.90.90.1",
43+ "169.254.0.0/16 dev br0 scope link metric 1000",
44+ ]
45+ self.assertEqual(
46+ 'eth0:2', address.find_default_interface(sample_ip_route))
47+
48 def test_find_default_interface_makes_a_guess_if_no_default(self):
49 sample_ip_route = [
50 "10.0.0.0/24 dev eth2 proto kernel scope link src 10.0.0.11 "
51@@ -69,6 +89,26 @@
52 self.assertEqual(
53 'eth2', address.find_default_interface(sample_ip_route))
54
55+ def test_find_default_tagged_interface_makes_a_guess_if_no_default(self):
56+ sample_ip_route = [
57+ "10.0.0.0/24 dev eth2.4 proto kernel scope link src 10.0.0.11 "
58+ "metric 2",
59+ "10.1.0.0/24 dev virbr0 proto kernel scope link src 10.1.0.1",
60+ "10.1.1.0/24 dev virbr1 proto kernel scope link src 10.1.1.1",
61+ ]
62+ self.assertEqual(
63+ 'eth2.4', address.find_default_interface(sample_ip_route))
64+
65+ def test_find_default_aliased_interface_makes_a_guess_if_no_default(self):
66+ sample_ip_route = [
67+ "10.0.0.0/24 dev eth2:4 proto kernel scope link src 10.0.0.11 "
68+ "metric 2",
69+ "10.1.0.0/24 dev virbr0 proto kernel scope link src 10.1.0.1",
70+ "10.1.1.0/24 dev virbr1 proto kernel scope link src 10.1.1.1",
71+ ]
72+ self.assertEqual(
73+ 'eth2:4', address.find_default_interface(sample_ip_route))
74+
75 def test_find_default_interface_returns_None_on_failure(self):
76 self.assertIsNone(address.find_default_interface([]))
77

Subscribers

People subscribed via source and target branches

to all changes: