← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~smoser/cloud-init:fix/1766287-gce-nic-rename into cloud-init:master

 

Scott Moser has proposed merging ~smoser/cloud-init:fix/1766287-gce-nic-rename into cloud-init:master.

Commit message:
net: apply any needed renames after writing network config.

There is a race condition that can be reached if we do:
  a.) select network device as fallback
  b.) rename network devices
  c.) write network config
  d.) something else (possibly udev/systemd) renames network device.
  e.) network is brought up by system.

The change here is to do a, c, b, e.  The current belief is that
'd' will then occur after 'c' and before 'b'.  We may need a
'udevadm wait' to ensure this.

LP: #1766287

Requested reviews:
  cloud-init commiters (cloud-init-dev)
Related bugs:
  Bug #1766287 in cloud-init: "18.04 minimal images on GCE intermittently fail to set up networking "
  https://bugs.launchpad.net/cloud-init/+bug/1766287

For more details, see:
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/344181

see commit message
-- 
Your team cloud-init commiters is requested to review the proposed merge of ~smoser/cloud-init:fix/1766287-gce-nic-rename into cloud-init:master.
diff --git a/cloudinit/stages.py b/cloudinit/stages.py
index bc4ebc8..f38352c 100644
--- a/cloudinit/stages.py
+++ b/cloudinit/stages.py
@@ -630,27 +630,30 @@ class Init(object):
                 return (ncfg, loc)
         return (self.distro.generate_fallback_config(), "fallback")
 
-    def apply_network_config(self, bring_up):
-        netcfg, src = self._find_networking_config()
-        if netcfg is None:
-            LOG.info("network config is disabled by %s", src)
-            return
-
+    def _apply_network_config_names(self, netcfg):
         try:
             LOG.debug("applying net config names for %s", netcfg)
             self.distro.apply_network_config_names(netcfg)
         except Exception as e:
             LOG.warning("Failed to rename devices: %s", e)
 
+    def apply_network_config(self, bring_up):
+        netcfg, src = self._find_networking_config()
+        if netcfg is None:
+            LOG.info("network config is disabled by %s", src)
+            return
+
         if (self.datasource is not NULL_DATA_SOURCE and
                 not self.is_new_instance()):
+            self._apply_network_config_names(netcfg)
             LOG.debug("not a new instance. network config is not applied.")
             return
 
         LOG.info("Applying network configuration from %s bringup=%s: %s",
                  src, bring_up, netcfg)
         try:
-            return self.distro.apply_network_config(netcfg, bring_up=bring_up)
+            self.distro._apply_network_config(netcfg, bring_up=bring_up)
+            self._apply_network_config_names(netcfg)
         except net.RendererNotFoundError as e:
             LOG.error("Unable to render networking. Network config is "
                       "likely broken: %s", e)

Follow ups