Do not crash on failing to add default route
CNI spec 0.3.1 states that plugins should expect that default route is
already set by some other CNI plugin, and handle such situations
gracefully. This is particularly needed to work with multus.
Closes-Bug:
# under the License.
import abc
+import errno
import six
import os_vif
@@ -91,8 +92,15 @@ def _configure_l3(vif, ifname, netns, is_default_gateway):
routes.add(gateway=str(route.gateway),
dst=str(route.cidr)).commit()
if is_default_gateway and hasattr(subnet, 'gateway'):
+ try:
routes.add(gateway=str(subnet.gateway),
dst='default').commit()
+ except pyroute2.NetlinkError as ex:
+ if ex.code != errno.EEXIST:
+ raise
+ LOG.debug("Default route already exists in pod for vif=%s."
+ " Did not overwrite with requested gateway=%s",
+ vif, subnet.gateway)
def _need_configure_l3(vif):
