Check same debian interface path everywhere

We had a special function for checking if a debian interface config file
exists but also manually constructed the path elsewhere to check if it
exists. Consolidate and drop the function since we already need the full
path in other places and once you have the full path os.path.exists is
the function you need.

Change-Id: I7a800b09699e0e86ee9df5988823b48910b57051
This commit is contained in:
Clark Boylan 2018-09-20 13:42:08 -07:00
parent 9e05a4209f
commit 7c41a80815
1 changed files with 8 additions and 8 deletions

View File

@ -759,11 +759,6 @@ def write_gentoo_interfaces(interfaces, sys_interfaces):
return files_to_write
def _exists_debian_interface(name):
file_to_check = '/etc/network/interfaces.d/{name}.cfg'.format(name=name)
return os.path.exists(file_to_check)
def _write_debian_bond_conf(interface_name, interface, sys_interfaces):
result = ""
if interface['mac_address']:
@ -802,6 +797,8 @@ def write_debian_interfaces(interfaces, sys_interfaces):
if not set(sys_interfaces).intersection(set(raw_macs)):
continue
# Determine the debian interface name and skip configuration for
# this interface if config already exists for it.
vlan_raw_device = None
if 'vlan_id' in interface:
# raw_macs will have a single entry if the vlan device is a
@ -819,7 +816,8 @@ def write_debian_interfaces(interfaces, sys_interfaces):
else:
interface_name = sys_interfaces[interface['mac_address']]
if _exists_debian_interface(interface_name):
iface_path = os.path.join(eni_d_path, '%s.cfg' % interface_name)
if os.path.exists(iface_path):
continue
iface_path = os.path.join(eni_d_path, '%s.cfg' % interface_name)
@ -923,9 +921,11 @@ def write_debian_interfaces(interfaces, sys_interfaces):
else:
files_to_write[iface_path] = header + result
# Configure any interfaces not mentioned in the config drive data for DHCP.
for mac, iname in sorted(
sys_interfaces.items(), key=lambda x: x[1]):
if _exists_debian_interface(iname):
iface_path = os.path.join(eni_d_path, '%s.cfg' % iname)
if os.path.exists(iface_path):
# This interface already has a config file, move on
continue
inter_macs = [intf['mac_address'] for intf in interfaces.values()]
@ -936,7 +936,7 @@ def write_debian_interfaces(interfaces, sys_interfaces):
continue
result = "auto {0}\n".format(iname)
result += "iface {0} inet dhcp\n".format(iname)
files_to_write[os.path.join(eni_d_path, "%s.cfg" % iname)] = result
files_to_write[iface_path] = result
return files_to_write