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