diff options
author | Scott Moser <smoser@brickies.net> | 2016-08-22 16:51:43 -0400 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2016-08-22 16:58:12 -0400 |
commit | 40a2f621b05c11ed6397a1735b6bfff0ea07b097 (patch) | |
tree | 43b37e8ae24e6c40f85c352ad8f97725b1a88a05 /cloudinit | |
parent | 64522efe710faf6fa1615dbb60a2fc4cc8a7c278 (diff) | |
download | vyos-cloud-init-40a2f621b05c11ed6397a1735b6bfff0ea07b097.tar.gz vyos-cloud-init-40a2f621b05c11ed6397a1735b6bfff0ea07b097.zip |
network: fix get_interface_mac for bond slave, read_sys_net for ENOTDIR
When using get_interface_mac, on a system with bond slaves, it would
return the bond_master's address. That isn't expected, and causes
problems in a caller like get_interfaces_by_mac which would then seem to
find duplicate macs on the system.
Additionally, in read_sys_net catch a errno.ENOTDIR error as ENOENT.
Opening a path as a file that has <existing_file>/anything will will raise
ENOTDIR rather than ENOENT. This handles that case in read_sys_net as a
if the file did not exist.
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/net/__init__.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py index 21cc602b..7e58bfea 100644 --- a/cloudinit/net/__init__.py +++ b/cloudinit/net/__init__.py @@ -36,7 +36,7 @@ def read_sys_net(devname, path, translate=None, enoent=None, keyerror=None): try: contents = util.load_file(sys_dev_path(devname, path)) except (OSError, IOError) as e: - if getattr(e, 'errno', None) == errno.ENOENT: + if getattr(e, 'errno', None) in (errno.ENOENT, errno.ENOTDIR): if enoent is not None: return enoent raise @@ -347,7 +347,12 @@ def _rename_interfaces(renames, strict_present=True, strict_busy=True, def get_interface_mac(ifname): """Returns the string value of an interface's MAC Address""" - return read_sys_net(ifname, "address", enoent=False) + path = "address" + if os.path.isdir(sys_dev_path(ifname, "bonding_slave")): + # for a bond slave, get the nic's hwaddress, not the address it + # is using because its part of a bond. + path = "bonding_slave/perm_hwaddr" + return read_sys_net(ifname, path, enoent=False) def get_interfaces_by_mac(devs=None): |