summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloudinit/config/cc_disk_setup.py1
-rw-r--r--tests/unittests/test_handler/test_handler_disk_setup.py18
2 files changed, 19 insertions, 0 deletions
diff --git a/cloudinit/config/cc_disk_setup.py b/cloudinit/config/cc_disk_setup.py
index d8d0fcf1..0796cb7b 100644
--- a/cloudinit/config/cc_disk_setup.py
+++ b/cloudinit/config/cc_disk_setup.py
@@ -825,6 +825,7 @@ def lookup_force_flag(fs):
'btrfs': '-f',
'xfs': '-f',
'reiserfs': '-f',
+ 'swap': '-f',
}
if 'ext' in fs.lower():
diff --git a/tests/unittests/test_handler/test_handler_disk_setup.py b/tests/unittests/test_handler/test_handler_disk_setup.py
index 5afcacaf..0e51f17a 100644
--- a/tests/unittests/test_handler/test_handler_disk_setup.py
+++ b/tests/unittests/test_handler/test_handler_disk_setup.py
@@ -222,4 +222,22 @@ class TestMkfsCommandHandling(CiTestCase):
'-L', 'without_cmd', '-F', 'are', 'added'],
shell=False)
+ @mock.patch('cloudinit.config.cc_disk_setup.util.which')
+ def test_mkswap(self, m_which, subp, *args):
+ """mkfs observes extra_opts and overwrite settings when cmd is not
+ present."""
+ m_which.side_effect = iter([None, '/sbin/mkswap'])
+ cc_disk_setup.mkfs({
+ 'filesystem': 'swap',
+ 'device': '/dev/xdb1',
+ 'label': 'swap',
+ 'overwrite': True,
+ })
+
+ self.assertEqual([mock.call('mkfs.swap'), mock.call('mkswap')],
+ m_which.call_args_list)
+ subp.assert_called_once_with(
+ ['/sbin/mkswap', '/dev/xdb1', '-L', 'swap', '-f'], shell=False)
+
+#
# vi: ts=4 expandtab