summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2014-10-01 15:29:45 -0400
committerScott Moser <smoser@ubuntu.com>2014-10-01 15:29:45 -0400
commitc8b3a21b4e4f5b50767c5df3641a11ad02975e4d (patch)
tree4efca3112771900bd12213f5615d44d8e50328d7 /cloudinit
parent31f415e3582a912c2172d8c450f14fd35c43f0b6 (diff)
downloadvyos-cloud-init-c8b3a21b4e4f5b50767c5df3641a11ad02975e4d.tar.gz
vyos-cloud-init-c8b3a21b4e4f5b50767c5df3641a11ad02975e4d.zip
check for existing file in /proc/swaps to be safe.
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/config/cc_mounts.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/cloudinit/config/cc_mounts.py b/cloudinit/config/cc_mounts.py
index 0c3ce15e..33fe4ddc 100644
--- a/cloudinit/config/cc_mounts.py
+++ b/cloudinit/config/cc_mounts.py
@@ -201,6 +201,20 @@ def handle_swapcfg(swapcfg):
LOG.debug("no need to setup swap")
return
+ if os.path.exists(fname):
+ if not os.path.exists("/proc/swaps"):
+ LOG.debug("swap file %s existed. no /proc/swaps. Being safe.",
+ fname)
+ return
+ try:
+ for line in util.load_file("/proc/swaps").splitlines():
+ if line.startswith(fname + " "):
+ LOG.debug("swap file %s already used", fname)
+ return
+ except:
+ LOG.warn("swap file %s existed. Error reading /proc/swaps", fname)
+ return
+
try:
if isinstance(size, str) and size != "auto":
size = util.human2bytes(size)