summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMina Galić <me+git@igalic.co>2020-11-02 18:01:41 +0100
committerGitHub <noreply@github.com>2020-11-02 12:01:41 -0500
commit34f8e2213c42106b3e1568b5c5aac5565df954e3 (patch)
tree87c2ddea1981ecfc36b1cf12441a0f7ccbbdaf84
parent815a790cafc4e78edc5a2b631396d7fedb424bcf (diff)
downloadvyos-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.
-rw-r--r--cloudinit/tests/test_util.py35
-rw-r--r--cloudinit/util.py14
2 files changed, 45 insertions, 4 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):
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 83727544..b8856af1 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -418,6 +418,11 @@ def multi_log(text, console=True, stderr=True,
@lru_cache()
+def is_Linux():
+ return 'Linux' in platform.system()
+
+
+@lru_cache()
def is_BSD():
return 'BSD' in platform.system()
@@ -1661,16 +1666,17 @@ def mount_cb(device, callback, data=None, mtype=None,
_type=type(mtype)))
# clean up 'mtype' input a bit based on platform.
- platsys = platform.system().lower()
- if platsys == "linux":
+ if is_Linux():
if mtypes is None:
mtypes = ["auto"]
- elif platsys.endswith("bsd"):
+ elif is_BSD():
if mtypes is None:
- mtypes = ['ufs', 'cd9660', 'vfat']
+ mtypes = ['ufs', 'cd9660', 'msdos']
for index, mtype in enumerate(mtypes):
if mtype == "iso9660":
mtypes[index] = "cd9660"
+ if mtype in ["vfat", "msdosfs"]:
+ mtypes[index] = "msdos"
else:
# we cannot do a smart "auto", so just call 'mount' once with no -t
mtypes = ['']