return only the filename, as it might be all known

This commit is contained in:
Scott Moser 2014-10-01 15:58:30 -04:00
parent 27d6712ab2
commit c028cff9c9

View File

@ -181,7 +181,7 @@ def setup_swapfile(fname, size=None, maxsize=None):
except Exception as e: except Exception as e:
raise IOError("Failed %s: %s" % (msg, e)) raise IOError("Failed %s: %s" % (msg, e))
return fname, size return fname
def handle_swapcfg(swapcfg): def handle_swapcfg(swapcfg):
@ -204,16 +204,16 @@ def handle_swapcfg(swapcfg):
if not os.path.exists("/proc/swaps"): if not os.path.exists("/proc/swaps"):
LOG.debug("swap file %s existed. no /proc/swaps. Being safe.", LOG.debug("swap file %s existed. no /proc/swaps. Being safe.",
fname) fname)
return return fname
try: try:
for line in util.load_file("/proc/swaps").splitlines(): for line in util.load_file("/proc/swaps").splitlines():
if line.startswith(fname + " "): if line.startswith(fname + " "):
LOG.debug("swap file %s already in use.", fname) LOG.debug("swap file %s already in use.", fname)
return return fname
LOG.debug("swap file %s existed, but not in /proc/swaps", fname) LOG.debug("swap file %s existed, but not in /proc/swaps", fname)
except: except:
LOG.warn("swap file %s existed. Error reading /proc/swaps", fname) LOG.warn("swap file %s existed. Error reading /proc/swaps", fname)
return return fname
try: try:
if isinstance(size, str) and size != "auto": if isinstance(size, str) and size != "auto":
@ -317,7 +317,7 @@ def handle(_name, cfg, cloud, log, _args):
swapret = handle_swapcfg(cfg.get('swap', {})) swapret = handle_swapcfg(cfg.get('swap', {}))
if swapret: if swapret:
actlist.append([swapret[0], "none", "swap", "sw", "0", "0"]) actlist.append([swapret, "none", "swap", "sw", "0", "0"])
if len(actlist) == 0: if len(actlist) == 0:
log.debug("No modifications to fstab needed.") log.debug("No modifications to fstab needed.")