6f2509
From cda350cffa9f04e0ba4fb787217c715a7c7fb777 Mon Sep 17 00:00:00 2001
6f2509
From: Eduardo Otubo <otubo@redhat.com>
6f2509
Date: Wed, 15 Apr 2020 09:40:11 +0200
6f2509
Subject: [PATCH] swap file "size" being used before checked if str (#315)
6f2509
6f2509
RH-Author: Eduardo Otubo <otubo@redhat.com>
6f2509
Message-id: <20200414163333.5424-1-otubo@redhat.com>
6f2509
Patchwork-id: 94678
6f2509
O-Subject: [RHEL-7.9 cloud-init PATCH] swap file "size" being used before checked if str (#315)
6f2509
Bugzilla: 1772505
6f2509
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
6f2509
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
6f2509
6f2509
commit 46cf23c28812d3e3ba0c570defd9a05628af5556
6f2509
Author: Eduardo Otubo <otubo@redhat.com>
6f2509
Date:   Tue Apr 14 17:45:14 2020 +0200
6f2509
6f2509
    swap file "size" being used before checked if str
6f2509
6f2509
    Swap file size variable was being used before checked if it's set to str
6f2509
    "auto". If set to "auto", it will break with:
6f2509
6f2509
      failed to setup swap: unsupported operand type(s) for /: 'str' and 'int'
6f2509
6f2509
    Signed-off-by: Eduardo Otubo <otubo@redhat.com>
6f2509
6f2509
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
6f2509
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
6f2509
---
6f2509
 cloudinit/config/cc_mounts.py | 2 +-
6f2509
 1 file changed, 1 insertion(+), 1 deletion(-)
6f2509
6f2509
diff --git a/cloudinit/config/cc_mounts.py b/cloudinit/config/cc_mounts.py
6f2509
index 4293844..0573026 100644
6f2509
--- a/cloudinit/config/cc_mounts.py
6f2509
+++ b/cloudinit/config/cc_mounts.py
6f2509
@@ -274,7 +274,6 @@ def setup_swapfile(fname, size=None, maxsize=None):
6f2509
     maxsize: the maximum size
6f2509
     """
6f2509
     swap_dir = os.path.dirname(fname)
6f2509
-    mibsize = str(int(size / (2 ** 20)))
6f2509
     if str(size).lower() == "auto":
6f2509
         try:
6f2509
             memsize = util.read_meminfo()['total']
6f2509
@@ -286,6 +285,7 @@ def setup_swapfile(fname, size=None, maxsize=None):
6f2509
         size = suggested_swapsize(fsys=swap_dir, maxsize=maxsize,
6f2509
                                   memsize=memsize)
6f2509
 
6f2509
+    mibsize = str(int(size / (2 ** 20)))
6f2509
     if not size:
6f2509
         LOG.debug("Not creating swap: suggested size was 0")
6f2509
         return
6f2509
-- 
6f2509
1.8.3.1
6f2509