diff options
author | Anh Vo <anhvo@microsoft.com> | 2022-11-18 14:31:27 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-18 12:31:27 -0700 |
commit | 24bf6147712655fc36a5d714a081853ea37e0312 (patch) | |
tree | 017929db04526540df9d0569c6dcd14527df7561 /cloudinit/net | |
parent | e2fb079a72402b59c5476d64d23331f7f1c5e945 (diff) | |
download | cloud-init-git-24bf6147712655fc36a5d714a081853ea37e0312.tar.gz |
net: skip duplicate mac check for netvsc nic and its VF (#1853)
When accelerated network is enabled on Azure, the host presents
two network interfaces with the same mac address to the VM:
a synthetic nic (netvsc) and a VF nic, which is enslaved to the synthetic
nic.
The net module is already excluding slave nics when enumerating
interfaces. However, if cloud-init starts enumerating after the kernel
makes the VF visible to userspace, but before the enslaving has finished,
cloud-init will see two nics with duplicate mac.
This change will skip the duplicate mac error if one of the two nics
with duplicate mac is a netvsc nic
LP: #1844191
Diffstat (limited to 'cloudinit/net')
-rw-r--r-- | cloudinit/net/__init__.py | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py index 4bc48676..0a41a2d4 100644 --- a/cloudinit/net/__init__.py +++ b/cloudinit/net/__init__.py @@ -1000,15 +1000,45 @@ def get_interfaces_by_mac_on_linux(blacklist_drivers=None) -> dict: Bridges and any devices that have a 'stolen' mac are excluded.""" ret: dict = {} - for name, mac, _driver, _devid in get_interfaces( + driver_map: dict = {} + for name, mac, driver, _devid in get_interfaces( blacklist_drivers=blacklist_drivers ): if mac in ret: - raise RuntimeError( - "duplicate mac found! both '%s' and '%s' have mac '%s'" - % (name, ret[mac], mac) + raise_duplicate_mac_error = True + msg = "duplicate mac found! both '%s' and '%s' have mac '%s'." % ( + name, + ret[mac], + mac, ) + # Hyper-V netvsc driver will register a VF with the same mac + # + # The VF will be enslaved to the master nic shortly after + # registration. If cloud-init starts enumerating the interfaces + # before the completion of the enslaving process, it will see + # two different nics with duplicate mac. Cloud-init should ignore + # the slave nic (which does not have hv_netvsc driver). + if driver != driver_map[mac]: + if driver_map[mac] == "hv_netvsc": + LOG.warning( + msg + " Ignoring '%s' due to driver '%s' and " + "'%s' having driver hv_netvsc." + % (name, driver, ret[mac]) + ) + continue + if driver == "hv_netvsc": + raise_duplicate_mac_error = False + LOG.warning( + msg + " Ignoring '%s' due to driver '%s' and " + "'%s' having driver hv_netvsc." + % (ret[mac], driver_map[mac], name) + ) + + if raise_duplicate_mac_error: + raise RuntimeError(msg) + ret[mac] = name + driver_map[mac] = driver # Pretend that an Infiniband GUID is an ethernet address for Openstack # configuration purposes |