Make os-net-config idempotent with Linux bonds and MAC mapping

This small change fixes a serious bug in os-net-config which made
mapping NICs by MAC address not idempotent if Linux bonds were used.

The first time os-net-config runs, it sees the MAC address of each
interface, then it sets up the bond. On subsequent runs, any
non-primary interfaces have taken the MAC address of the primary
interface in the bond. At this time, they all show the same MAC
address. This causes the mapping to fail, and it appears that
the system has fewer matching interfaces than it had before.

The impact of this bug is that bonding doesn't work for
anyone doing mapping by MAC address. This is known to be affecting
installations with a particular 3rd-party Neutron plugin vendor.

This change simply looks for the permanent hardware address under
the bonding_slave directory, if it exists.

Change-Id: I5b0087370f74ecc319d2285b0f9f5f3dd951dbc2
This commit is contained in:
Dan Sneddon 2016-06-30 15:56:52 -07:00
parent f742dcbda0
commit 6036a16671
1 changed files with 7 additions and 0 deletions

View File

@ -42,6 +42,13 @@ def get_file_data(filename):
def interface_mac(name):
try: # If the iface is part of a Linux bond, the real MAC is only here.
with open('/sys/class/net/%s/bonding_slave/perm_hwaddr' % name,
'r') as f:
return f.read().rstrip()
except IOError:
pass # Iface is not part of a bond, continue
try:
with open('/sys/class/net/%s/address' % name, 'r') as f:
return f.read().rstrip()