From 90105f3b570d09a088c53391bb4383d2bd32bc4a Mon Sep 17 00:00:00 2001 From: Paul Belanger Date: Wed, 7 Sep 2016 15:47:08 -0400 Subject: [PATCH] Index networks using id, not links Rather then creating our own index for networks, use the existing ID that already exists from config-drive. This help is clouds where multiple networks use the same link. Change-Id: I412541effdfdda6f8d11f2b4d8ce9d6ca9e9c165 Signed-off-by: Paul Belanger --- glean/cmd.py | 17 +++++++++++++---- glean/tests/test_glean.py | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/glean/cmd.py b/glean/cmd.py index 9eaf346..691cb9f 100644 --- a/glean/cmd.py +++ b/glean/cmd.py @@ -146,7 +146,9 @@ def write_redhat_interfaces(interfaces, sys_interfaces): interface_name = "{0}.{1}".format( vlan_raw_device, interface['vlan_id']) elif 'bond_mode' in interface: - interface_name = iname + # It is possible our interface does not have a link, so fall back + # to iname which is the link id. + interface_name = interface.get('link', iname) else: interface_name = sys_interfaces[interface['mac_address']] @@ -314,8 +316,11 @@ def write_gentoo_interfaces(interfaces, sys_interfaces): if len(raw_macs) == 1: interface_name = sys_interfaces[raw_macs[0]] else: + # It is possible our interface does not have a link, so + # fall back to interface id. interface_name = next( - intf['id'] for intf in interfs if 'bond_mode' in intf) + intf.get('link', intf['id']) for intf in interfs + if 'bond_mode' in intf) files_to_write.update( _write_gentoo_interface(interface_name, interfs)) _setup_gentoo_network_init(interface_name, interfs) @@ -379,7 +384,9 @@ def write_debian_interfaces(interfaces, sys_interfaces): interface_name = "{0}.{1}".format(vlan_raw_device, interface['vlan_id']) elif 'bond_mode' in interface: - interface_name = iname + # It is possible our interface does not have a link, so fall back + # to iname which is the link id. + interface_name = interface.get('link', iname) else: interface_name = sys_interfaces[interface['mac_address']] @@ -573,7 +580,9 @@ def get_config_drive_interfaces(net): continue link.update(network) link['id'] = i - interfaces[i] = link + # NOTE(pabelanger): Make sure we index by the existing network id, + # rather then creating out own. + interfaces[network['id']] = link return interfaces diff --git a/glean/tests/test_glean.py b/glean/tests/test_glean.py index aed5452..3324b66 100644 --- a/glean/tests/test_glean.py +++ b/glean/tests/test_glean.py @@ -31,8 +31,8 @@ sample_data_path = os.path.join( distros = ['Ubuntu', 'Debian', 'Fedora', 'RedHat', 'CentOS', 'Gentoo'] styles = ['hp', 'rax', 'liberty', 'nokey'] ips = {'hp': '127.0.1.1', - 'rax': '10.208.169.118', - 'liberty': '192.0.2.2', + 'rax': '23.253.229.154', + 'liberty': '23.253.229.154', 'nokey': '127.0.1.1'} built_scenarios = []