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

Proposed by Scott Moser
Status: Merged
Merged at revision: c9c9197a3210ac24a039a4096214150d0e8cebb8
Proposed branch: ~smoser/cloud-init:bug/1647708-azure-ephemeral2
Merge into: cloud-init:master
Diff against target: 83 lines (+34/-18)
1 file modified
cloudinit/config/cc_mounts.py (+34/-18)
Reviewer Review Type Date Requested Status
cloud-init Commiters Pending
Review via email: mp+312841@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ryan Harper (raharper) :
Revision history for this message
Scott Moser (smoser) wrote :

I addressed your comments mainly by simplifying the change to not do the diff-like change.
We definitely have some cleanup to do on this module, i'td be nice to get most of it out of 'handle' and add some unit tests.

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/config/cc_mounts.py b/cloudinit/config/cc_mounts.py
2index 452c9e8..0c796b1 100644
3--- a/cloudinit/config/cc_mounts.py
4+++ b/cloudinit/config/cc_mounts.py
5@@ -327,6 +327,8 @@ def handle(_name, cfg, cloud, log, _args):
6 if "mounts" in cfg:
7 cfgmnt = cfg["mounts"]
8
9+ LOG.debug("mounts configuration is %s", cfgmnt)
10+
11 for i in range(len(cfgmnt)):
12 # skip something that wasn't a list
13 if not isinstance(cfgmnt[i], list):
14@@ -423,37 +425,51 @@ def handle(_name, cfg, cloud, log, _args):
15 cc_lines.append('\t'.join(line))
16
17 fstab_lines = []
18+ removed = []
19 for line in util.load_file(FSTAB_PATH).splitlines():
20 try:
21 toks = WS.split(line)
22 if toks[3].find(comment) != -1:
23+ removed.append(line)
24 continue
25 except Exception:
26 pass
27 fstab_lines.append(line)
28
29+ for d in dirs:
30+ try:
31+ util.ensure_dir(d)
32+ except Exception:
33+ util.logexc(log, "Failed to make '%s' config-mount", d)
34+
35+ sadds = [WS.sub(" ", n) for n in cc_lines]
36+ sdrops = [WS.sub(" ", n) for n in removed]
37+
38+ sops = (["- " + drop for drop in sdrops if drop not in sadds] +
39+ ["+ " + add for add in sadds if add not in sdrops])
40+
41 fstab_lines.extend(cc_lines)
42 contents = "%s\n" % ('\n'.join(fstab_lines))
43 util.write_file(FSTAB_PATH, contents)
44
45+ activate_cmds = []
46 if needswap:
47- try:
48- util.subp(("swapon", "-a"))
49- except Exception:
50- util.logexc(log, "Activating swap via 'swapon -a' failed")
51+ activate_cmds.append(["swapon", "-a"])
52
53- for d in dirs:
54+ if len(sops) == 0:
55+ log.debug("No changes to /etc/fstab made.")
56+ else:
57+ log.debug("Changes to fstab: %s", sops)
58+ activate_cmds.append(["mount", "-a"])
59+ if uses_systemd:
60+ activate_cmds.append(["systemctl", "daemon-reload"])
61+
62+ fmt = "Activating swap and mounts with: %s"
63+ for cmd in activate_cmds:
64+ fmt = "Activate mounts: %s:" + ' '.join(cmd)
65 try:
66- util.ensure_dir(d)
67- except Exception:
68- util.logexc(log, "Failed to make '%s' config-mount", d)
69-
70- activate_cmd = ["mount", "-a"]
71- if uses_systemd:
72- activate_cmd = ["systemctl", "daemon-reload"]
73- fmt = "Activate mounts: %s:" + ' '.join(activate_cmd)
74- try:
75- util.subp(activate_cmd)
76- LOG.debug(fmt, "PASS")
77- except util.ProcessExecutionError:
78- util.logexc(log, fmt, "FAIL")
79+ util.subp(cmd)
80+ log.debug(fmt, "PASS")
81+ except util.ProcessExecutionError:
82+ log.warn(fmt, "FAIL")
83+ util.logexc(log, fmt, "FAIL")

Subscribers

People subscribed via source and target branches