Skip to content

Commit

Permalink
swap file "size" being used before checked if str (#315)
Browse files Browse the repository at this point in the history
Swap file size variable was being used before checked if it's set to str
"auto". If set to "auto", it will break with:

  failed to setup swap: unsupported operand type(s) for /: 'str' and 'int'

Signed-off-by: Eduardo Otubo <otubo@redhat.com>
RHBZ: 1772505
  • Loading branch information
otubo authored Apr 14, 2020
1 parent 48b15bf commit 46cf23c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion cloudinit/config/cc_mounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ def setup_swapfile(fname, size=None, maxsize=None):
maxsize: the maximum size
"""
swap_dir = os.path.dirname(fname)
mibsize = str(int(size / (2 ** 20)))
if str(size).lower() == "auto":
try:
memsize = util.read_meminfo()['total']
Expand All @@ -299,6 +298,7 @@ def setup_swapfile(fname, size=None, maxsize=None):
size = suggested_swapsize(fsys=swap_dir, maxsize=maxsize,
memsize=memsize)

mibsize = str(int(size / (2 ** 20)))
if not size:
LOG.debug("Not creating swap: suggested size was 0")
return
Expand Down

0 comments on commit 46cf23c

Please sign in to comment.