diff options
author | Ryan Harper <ryan.harper@canonical.com> | 2020-02-07 16:52:06 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-07 17:52:06 -0500 |
commit | 890aca4777ab61e54b6b96d251c3022cbe0b108c (patch) | |
tree | 4618481ee9861868b2cec51cff0c1d749efa3b67 | |
parent | 616d0a60d8d6ef0fa024267e718b3ed0e3b6bbdc (diff) | |
download | vyos-cloud-init-890aca4777ab61e54b6b96d251c3022cbe0b108c.tar.gz vyos-cloud-init-890aca4777ab61e54b6b96d251c3022cbe0b108c.zip |
cc_disk_setup: add swap filesystem force flag (#207)
-rw-r--r-- | cloudinit/config/cc_disk_setup.py | 1 | ||||
-rw-r--r-- | tests/unittests/test_handler/test_handler_disk_setup.py | 18 |
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 |