diff options
author | Mina Galić <me+git@igalic.co> | 2020-11-02 18:01:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-02 12:01:41 -0500 |
commit | 34f8e2213c42106b3e1568b5c5aac5565df954e3 (patch) | |
tree | 87c2ddea1981ecfc36b1cf12441a0f7ccbbdaf84 /cloudinit/tests | |
parent | 815a790cafc4e78edc5a2b631396d7fedb424bcf (diff) | |
download | vyos-cloud-init-34f8e2213c42106b3e1568b5c5aac5565df954e3.tar.gz vyos-cloud-init-34f8e2213c42106b3e1568b5c5aac5565df954e3.zip |
util: fix mounting of vfat on *BSD (#637)
Fix mounting of vfat filesystems by normalizing the different names for
vfat to "msdos" which works across BSDs.
Diffstat (limited to 'cloudinit/tests')
-rw-r--r-- | cloudinit/tests/test_util.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/cloudinit/tests/test_util.py b/cloudinit/tests/test_util.py index 77714928..b7a302f1 100644 --- a/cloudinit/tests/test_util.py +++ b/cloudinit/tests/test_util.py @@ -730,6 +730,41 @@ class TestMountCb: """already_mounted_device_and_mountdict, but return only the device""" return already_mounted_device_and_mountdict[0] + @pytest.mark.parametrize( + "mtype,expected", + [ + # While the filesystem is called iso9660, the mount type is cd9660 + ("iso9660", "cd9660"), + # vfat is generally called "msdos" on BSD + ("vfat", "msdos"), + # judging from man pages, only FreeBSD has this alias + ("msdosfs", "msdos"), + # Test happy path + ("ufs", "ufs") + ], + ) + @mock.patch("cloudinit.util.is_Linux", autospec=True) + @mock.patch("cloudinit.util.is_BSD", autospec=True) + @mock.patch("cloudinit.util.subp.subp") + @mock.patch("cloudinit.temp_utils.tempdir", autospec=True) + def test_normalize_mtype_on_bsd( + self, m_tmpdir, m_subp, m_is_BSD, m_is_Linux, mtype, expected + ): + m_is_BSD.return_value = True + m_is_Linux.return_value = False + m_tmpdir.return_value.__enter__ = mock.Mock( + autospec=True, return_value="/tmp/fake" + ) + m_tmpdir.return_value.__exit__ = mock.Mock( + autospec=True, return_value=True + ) + callback = mock.Mock(autospec=True) + + util.mount_cb('/dev/fake0', callback, mtype=mtype) + assert mock.call( + ["mount", "-o", "ro", "-t", expected, "/dev/fake0", "/tmp/fake"], + update_env=None) in m_subp.call_args_list + @pytest.mark.parametrize("invalid_mtype", [int(0), float(0.0), dict()]) def test_typeerror_raised_for_invalid_mtype(self, invalid_mtype): with pytest.raises(TypeError): |