← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~smoser/cloud-init:bug/1647708-azure-ephemeral2 into cloud-init:master

 

Scott Moser has proposed merging ~smoser/cloud-init:bug/1647708-azure-ephemeral2 into cloud-init:master.

Requested reviews:
  cloud init development team (cloud-init-dev)
Related bugs:
  Bug #1647708 in cloud-init (Ubuntu): "Ephemeral disk on xenial is not mounted at boot"
  https://bugs.launchpad.net/ubuntu/+source/cloud-init/+bug/1647708

For more details, see:
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/312841
-- 
Your team cloud init development team is requested to review the proposed merge of ~smoser/cloud-init:bug/1647708-azure-ephemeral2 into cloud-init:master.
diff --git a/cloudinit/config/cc_mounts.py b/cloudinit/config/cc_mounts.py
index 452c9e8..c4d125d 100644
--- a/cloudinit/config/cc_mounts.py
+++ b/cloudinit/config/cc_mounts.py
@@ -327,6 +327,8 @@ def handle(_name, cfg, cloud, log, _args):
     if "mounts" in cfg:
         cfgmnt = cfg["mounts"]
 
+    LOG.debug("mounts configuration is %s", cfgmnt)
+
     for i in range(len(cfgmnt)):
         # skip something that wasn't a list
         if not isinstance(cfgmnt[i], list):
@@ -423,37 +425,53 @@ def handle(_name, cfg, cloud, log, _args):
         cc_lines.append('\t'.join(line))
 
     fstab_lines = []
+    removed = []
     for line in util.load_file(FSTAB_PATH).splitlines():
         try:
             toks = WS.split(line)
             if toks[3].find(comment) != -1:
+                removed.append(line)
                 continue
         except Exception:
             pass
         fstab_lines.append(line)
 
-    fstab_lines.extend(cc_lines)
-    contents = "%s\n" % ('\n'.join(fstab_lines))
-    util.write_file(FSTAB_PATH, contents)
-
-    if needswap:
-        try:
-            util.subp(("swapon", "-a"))
-        except Exception:
-            util.logexc(log, "Activating swap via 'swapon -a' failed")
-
     for d in dirs:
         try:
             util.ensure_dir(d)
         except Exception:
             util.logexc(log, "Failed to make '%s' config-mount", d)
 
-    activate_cmd = ["mount", "-a"]
+    sadds = [WS.sub(" ", n) for n in cc_lines]
+    sdrops = [WS.sub(" ", n) for n in removed]
+
+    sops = (["- " + drop for drop in sdrops if drop not in sadds] +
+            ["+ " + add for add in sadds if add not in sdrops])
+
+    if len(sops) == 0:
+        log.debug("No changes to /etc/fstab made.")
+        return True
+    else:
+        log.debug("Changes to fstab: %s", sops)
+
+    fstab_lines.extend(cc_lines)
+    contents = "%s\n" % ('\n'.join(fstab_lines))
+    util.write_file(FSTAB_PATH, contents)
+
+    activate_cmds = []
+    if needswap:
+        activate_cmds.append(["swapon", "-a"])
+
+    activate_cmds.append(["mount", "-a"])
     if uses_systemd:
-        activate_cmd = ["systemctl", "daemon-reload"]
-    fmt = "Activate mounts: %s:" + ' '.join(activate_cmd)
-    try:
-        util.subp(activate_cmd)
-        LOG.debug(fmt, "PASS")
-    except util.ProcessExecutionError:
-        util.logexc(log, fmt, "FAIL")
+        activate_cmds.append(["systemctl", "daemon-reload"])
+
+    fmt = "Activating mounts with: %s"
+    for cmd in activate_cmds:
+        fmt = "Activate mounts: %s:" + ' '.join(cmd)
+        try:
+            util.subp(cmd)
+            log.debug(fmt, "PASS")
+        except util.ProcessExecutionError:
+            log.debug(fmt, "FAIL")
+            util.logexc(log, fmt, "FAIL")

Follow ups