Merge lp:~blake-rouse/maas/fix-1554999 into lp:~maas-committers/maas/trunk

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 4795
Proposed branch: lp:~blake-rouse/maas/fix-1554999
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 93 lines (+56/-3)
2 files modified
src/provisioningserver/utils/network.py (+17/-1)
src/provisioningserver/utils/tests/test_network.py (+39/-2)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-1554999
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Approve
Review via email: mp+289283@code.launchpad.net

Commit message

Include ethernet interfaces when no other interface types exist.

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

lgtm! Just one non-blocker comment!

review: Approve
Revision history for this message
Blake Rouse (blake-rouse) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/provisioningserver/utils/network.py'
2--- src/provisioningserver/utils/network.py 2016-03-12 03:19:19 +0000
3+++ src/provisioningserver/utils/network.py 2016-03-16 19:28:17 +0000
4@@ -625,12 +625,28 @@
5 exclude_types = ["loopback", "ipip"]
6 if not running_in_container():
7 exclude_types.append("ethernet")
8+ original_ipaddr_info = get_ip_addr()
9 ipaddr_info = {
10 name: ipaddr
11- for name, ipaddr in get_ip_addr().items()
12+ for name, ipaddr in original_ipaddr_info.items()
13 if (ipaddr["type"] not in exclude_types and
14 not ipaddr["type"].startswith("unknown-"))
15 }
16+
17+ # It's not always 100% that we can determine that this machine is running
18+ # in a container. To handle this case we include "ethernet" interfaces
19+ # when no other interfaces could be identified. See lp:1554999.
20+ if len(ipaddr_info) == 0 and "ethernet" in exclude_types:
21+ # No interfaces have been discovered from "ip addr" excluding
22+ # "ethernet". Re-filter including ethernet.
23+ exclude_types.remove("ethernet")
24+ ipaddr_info = {
25+ name: ipaddr
26+ for name, ipaddr in original_ipaddr_info.items()
27+ if (ipaddr["type"] not in exclude_types and
28+ not ipaddr["type"].startswith("unknown-"))
29+ }
30+
31 for name, ipaddr in ipaddr_info.items():
32 iface_type = "physical"
33 parents = []
34
35=== modified file 'src/provisioningserver/utils/tests/test_network.py'
36--- src/provisioningserver/utils/tests/test_network.py 2016-03-12 03:19:19 +0000
37+++ src/provisioningserver/utils/tests/test_network.py 2016-03-16 19:28:17 +0000
38@@ -837,8 +837,14 @@
39 }
40 self.assertInterfacesResult(ip_addr, {}, {}, MatchesDict({}))
41
42- def test__ignores_ethernet(self):
43+ def test__ignores_ethernet_when_physical(self):
44 ip_addr = {
45+ "eth0": {
46+ "type": "ethernet.physical",
47+ "mac": factory.make_mac_address(),
48+ "flags": ["UP"],
49+ "inet": [],
50+ },
51 "vnet": {
52 "type": "ethernet",
53 "mac": factory.make_mac_address(),
54@@ -846,7 +852,38 @@
55 "inet": ["192.168.122.2/24"],
56 },
57 }
58- self.assertInterfacesResult(ip_addr, {}, {}, MatchesDict({}))
59+ expected_result = MatchesDict({
60+ "eth0": MatchesDict({
61+ "type": Equals("physical"),
62+ "mac_address": Equals(ip_addr["eth0"]["mac"]),
63+ "enabled": Is(True),
64+ "parents": Equals([]),
65+ "links": Equals([]),
66+ "source": Equals("ipaddr"),
67+ }),
68+ })
69+ self.assertInterfacesResult(ip_addr, {}, {}, expected_result)
70+
71+ def test__includes_ethernet_when_only_ethernet(self):
72+ ip_addr = {
73+ "vnet": {
74+ "type": "ethernet",
75+ "mac": factory.make_mac_address(),
76+ "flags": ["UP"],
77+ "inet": [],
78+ },
79+ }
80+ expected_result = MatchesDict({
81+ "vnet": MatchesDict({
82+ "type": Equals("physical"),
83+ "mac_address": Equals(ip_addr["vnet"]["mac"]),
84+ "enabled": Is(True),
85+ "parents": Equals([]),
86+ "links": Equals([]),
87+ "source": Equals("ipaddr"),
88+ }),
89+ })
90+ self.assertInterfacesResult(ip_addr, {}, {}, expected_result)
91
92 def test__ignores_ipip(self):
93 ip_addr = {