sailesh1993 / rpms / cloud-init

Forked from rpms/cloud-init 10 months ago
Clone
591b7e
From 00b8210223ce3af97109df5cdb85b8e40541dd33 Mon Sep 17 00:00:00 2001
591b7e
From: Eduardo Otubo <otubo@redhat.com>
591b7e
Date: Tue, 28 Apr 2020 08:22:07 +0200
591b7e
Subject: [PATCH 3/3] cc_mounts: fix incorrect format specifiers (#316)
591b7e
591b7e
RH-Author: Eduardo Otubo <otubo@redhat.com>
591b7e
Message-id: <20200422130428.7663-4-otubo@redhat.com>
591b7e
Patchwork-id: 96034
591b7e
O-Subject: [RHEL-7.7.z/RHEL-7.8.z cloud-init PATCH 3/3] cc_mounts: fix incorrect format specifiers (#316)
591b7e
Bugzilla: 1801094
591b7e
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
591b7e
RH-Acked-by: Cathy Avery <cavery@redhat.com>
591b7e
591b7e
commit 9d7b35ce23aaf8741dd49b16e359c96591be3c76
591b7e
Author: Daniel Watkins <oddbloke@ubuntu.com>
591b7e
Date:   Wed Apr 15 16:53:08 2020 -0400
591b7e
591b7e
    cc_mounts: fix incorrect format specifiers (#316)
591b7e
591b7e
    LP: #1872836
591b7e
591b7e
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
591b7e
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
591b7e
---
591b7e
 cloudinit/config/cc_mounts.py         |  6 +++---
591b7e
 cloudinit/config/tests/test_mounts.py | 22 ++++++++++++++++++++++
591b7e
 2 files changed, 25 insertions(+), 3 deletions(-)
591b7e
 create mode 100644 cloudinit/config/tests/test_mounts.py
591b7e
591b7e
diff --git a/cloudinit/config/cc_mounts.py b/cloudinit/config/cc_mounts.py
591b7e
index 811781f..7c4e104 100644
591b7e
--- a/cloudinit/config/cc_mounts.py
591b7e
+++ b/cloudinit/config/cc_mounts.py
591b7e
@@ -226,17 +226,17 @@ def suggested_swapsize(memsize=None, maxsize=None, fsys=None):
591b7e
 def create_swapfile(fname, size):
591b7e
     """Size is in MiB."""
591b7e
 
591b7e
-    errmsg = "Failed to create swapfile '%s' of size %dMB via %s: %s"
591b7e
+    errmsg = "Failed to create swapfile '%s' of size %sMB via %s: %s"
591b7e
 
591b7e
     def create_swap(fname, size, method):
591b7e
         LOG.debug("Creating swapfile in '%s' on fstype '%s' using '%s'",
591b7e
                   fname, fstype, method)
591b7e
 
591b7e
         if method == "fallocate":
591b7e
-            cmd = ['fallocate', '-l', '%dM' % size, fname]
591b7e
+            cmd = ['fallocate', '-l', '%sM' % size, fname]
591b7e
         elif method == "dd":
591b7e
             cmd = ['dd', 'if=/dev/zero', 'of=%s' % fname, 'bs=1M',
591b7e
-                   'count=%d' % size]
591b7e
+                   'count=%s' % size]
591b7e
 
591b7e
         try:
591b7e
             util.subp(cmd, capture=True)
591b7e
diff --git a/cloudinit/config/tests/test_mounts.py b/cloudinit/config/tests/test_mounts.py
591b7e
new file mode 100644
591b7e
index 0000000..c7dad61
591b7e
--- /dev/null
591b7e
+++ b/cloudinit/config/tests/test_mounts.py
591b7e
@@ -0,0 +1,22 @@
591b7e
+# This file is part of cloud-init. See LICENSE file for license information.
591b7e
+from unittest import mock
591b7e
+
591b7e
+from cloudinit.config.cc_mounts import create_swapfile
591b7e
+
591b7e
+
591b7e
+M_PATH = 'cloudinit.config.cc_mounts.'
591b7e
+
591b7e
+
591b7e
+class TestCreateSwapfile:
591b7e
+
591b7e
+    @mock.patch(M_PATH + 'util.subp')
591b7e
+    def test_happy_path(self, m_subp, tmpdir):
591b7e
+        swap_file = tmpdir.join("swap-file")
591b7e
+        fname = str(swap_file)
591b7e
+
591b7e
+        # Some of the calls to util.subp should create the swap file; this
591b7e
+        # roughly approximates that
591b7e
+        m_subp.side_effect = lambda *args, **kwargs: swap_file.write('')
591b7e
+
591b7e
+        create_swapfile(fname, '')
591b7e
+        assert mock.call(['mkswap', fname]) in m_subp.call_args_list
591b7e
-- 
591b7e
1.8.3.1
591b7e