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
=== modified file 'src/provisioningserver/utils/network.py'
--- src/provisioningserver/utils/network.py 2016-03-12 03:19:19 +0000
+++ src/provisioningserver/utils/network.py 2016-03-16 19:28:17 +0000
@@ -625,12 +625,28 @@
625 exclude_types = ["loopback", "ipip"]625 exclude_types = ["loopback", "ipip"]
626 if not running_in_container():626 if not running_in_container():
627 exclude_types.append("ethernet")627 exclude_types.append("ethernet")
628 original_ipaddr_info = get_ip_addr()
628 ipaddr_info = {629 ipaddr_info = {
629 name: ipaddr630 name: ipaddr
630 for name, ipaddr in get_ip_addr().items()631 for name, ipaddr in original_ipaddr_info.items()
631 if (ipaddr["type"] not in exclude_types and632 if (ipaddr["type"] not in exclude_types and
632 not ipaddr["type"].startswith("unknown-"))633 not ipaddr["type"].startswith("unknown-"))
633 }634 }
635
636 # It's not always 100% that we can determine that this machine is running
637 # in a container. To handle this case we include "ethernet" interfaces
638 # when no other interfaces could be identified. See lp:1554999.
639 if len(ipaddr_info) == 0 and "ethernet" in exclude_types:
640 # No interfaces have been discovered from "ip addr" excluding
641 # "ethernet". Re-filter including ethernet.
642 exclude_types.remove("ethernet")
643 ipaddr_info = {
644 name: ipaddr
645 for name, ipaddr in original_ipaddr_info.items()
646 if (ipaddr["type"] not in exclude_types and
647 not ipaddr["type"].startswith("unknown-"))
648 }
649
634 for name, ipaddr in ipaddr_info.items():650 for name, ipaddr in ipaddr_info.items():
635 iface_type = "physical"651 iface_type = "physical"
636 parents = []652 parents = []
637653
=== modified file 'src/provisioningserver/utils/tests/test_network.py'
--- src/provisioningserver/utils/tests/test_network.py 2016-03-12 03:19:19 +0000
+++ src/provisioningserver/utils/tests/test_network.py 2016-03-16 19:28:17 +0000
@@ -837,8 +837,14 @@
837 }837 }
838 self.assertInterfacesResult(ip_addr, {}, {}, MatchesDict({}))838 self.assertInterfacesResult(ip_addr, {}, {}, MatchesDict({}))
839839
840 def test__ignores_ethernet(self):840 def test__ignores_ethernet_when_physical(self):
841 ip_addr = {841 ip_addr = {
842 "eth0": {
843 "type": "ethernet.physical",
844 "mac": factory.make_mac_address(),
845 "flags": ["UP"],
846 "inet": [],
847 },
842 "vnet": {848 "vnet": {
843 "type": "ethernet",849 "type": "ethernet",
844 "mac": factory.make_mac_address(),850 "mac": factory.make_mac_address(),
@@ -846,7 +852,38 @@
846 "inet": ["192.168.122.2/24"],852 "inet": ["192.168.122.2/24"],
847 },853 },
848 }854 }
849 self.assertInterfacesResult(ip_addr, {}, {}, MatchesDict({}))855 expected_result = MatchesDict({
856 "eth0": MatchesDict({
857 "type": Equals("physical"),
858 "mac_address": Equals(ip_addr["eth0"]["mac"]),
859 "enabled": Is(True),
860 "parents": Equals([]),
861 "links": Equals([]),
862 "source": Equals("ipaddr"),
863 }),
864 })
865 self.assertInterfacesResult(ip_addr, {}, {}, expected_result)
866
867 def test__includes_ethernet_when_only_ethernet(self):
868 ip_addr = {
869 "vnet": {
870 "type": "ethernet",
871 "mac": factory.make_mac_address(),
872 "flags": ["UP"],
873 "inet": [],
874 },
875 }
876 expected_result = MatchesDict({
877 "vnet": MatchesDict({
878 "type": Equals("physical"),
879 "mac_address": Equals(ip_addr["vnet"]["mac"]),
880 "enabled": Is(True),
881 "parents": Equals([]),
882 "links": Equals([]),
883 "source": Equals("ipaddr"),
884 }),
885 })
886 self.assertInterfacesResult(ip_addr, {}, {}, expected_result)
850887
851 def test__ignores_ipip(self):888 def test__ignores_ipip(self):
852 ip_addr = {889 ip_addr = {