summaryrefslogtreecommitdiff
path: root/tests/unittests/test_util.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unittests/test_util.py')
-rw-r--r--tests/unittests/test_util.py195
1 files changed, 112 insertions, 83 deletions
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
index 409dba61..72c56967 100644
--- a/tests/unittests/test_util.py
+++ b/tests/unittests/test_util.py
@@ -967,96 +967,125 @@ class TestGetProcEnv(helpers.TestCase):
self.assertEqual(my_ppid, util.get_proc_ppid(my_pid))
-@mock.patch('cloudinit.subp.subp')
-def test_find_devs_with_openbsd(m_subp):
- m_subp.return_value = (
- 'cd0:,sd0:630d98d32b5d3759,sd1:,fd0:', ''
- )
- devlist = util.find_devs_with_openbsd()
- assert devlist == ['/dev/cd0a', '/dev/sd1i']
-
-
-@mock.patch('cloudinit.subp.subp')
-def test_find_devs_with_openbsd_with_criteria(m_subp):
- m_subp.return_value = (
- 'cd0:,sd0:630d98d32b5d3759,sd1:,fd0:', ''
- )
- devlist = util.find_devs_with_openbsd(criteria="TYPE=iso9660")
- assert devlist == ['/dev/cd0a']
-
-
-@mock.patch('glob.glob')
-def test_find_devs_with_freebsd(m_glob):
- def fake_glob(pattern):
- msdos = ["/dev/msdosfs/EFISYS"]
- iso9660 = ["/dev/iso9660/config-2"]
- if pattern == "/dev/msdosfs/*":
- return msdos
- elif pattern == "/dev/iso9660/*":
- return iso9660
- raise Exception
- m_glob.side_effect = fake_glob
-
- devlist = util.find_devs_with_freebsd()
- assert set(devlist) == set([
- '/dev/iso9660/config-2', '/dev/msdosfs/EFISYS'])
- devlist = util.find_devs_with_freebsd(criteria="TYPE=iso9660")
- assert devlist == ['/dev/iso9660/config-2']
- devlist = util.find_devs_with_freebsd(criteria="TYPE=vfat")
- assert devlist == ['/dev/msdosfs/EFISYS']
-
-
-@mock.patch("cloudinit.subp.subp")
-def test_find_devs_with_netbsd(m_subp):
- side_effect_values = [
- ("ld0 dk0 dk1 cd0", ""),
- (
+class TestFindDevs:
+ @mock.patch('cloudinit.subp.subp')
+ def test_find_devs_with(self, m_subp):
+ m_subp.return_value = (
+ '/dev/sda1: UUID="some-uuid" TYPE="ext4" PARTUUID="some-partid"',
+ ''
+ )
+ devlist = util.find_devs_with()
+ assert devlist == [
+ '/dev/sda1: UUID="some-uuid" TYPE="ext4" PARTUUID="some-partid"']
+
+ devlist = util.find_devs_with("LABEL_FATBOOT=A_LABEL")
+ assert devlist == [
+ '/dev/sda1: UUID="some-uuid" TYPE="ext4" PARTUUID="some-partid"']
+
+ @mock.patch('cloudinit.subp.subp')
+ def test_find_devs_with_openbsd(self, m_subp):
+ m_subp.return_value = (
+ 'cd0:,sd0:630d98d32b5d3759,sd1:,fd0:', ''
+ )
+ devlist = util.find_devs_with_openbsd()
+ assert devlist == ['/dev/cd0a', '/dev/sd1i']
+
+ @mock.patch('cloudinit.subp.subp')
+ def test_find_devs_with_openbsd_with_criteria(self, m_subp):
+ m_subp.return_value = (
+ 'cd0:,sd0:630d98d32b5d3759,sd1:,fd0:', ''
+ )
+ devlist = util.find_devs_with_openbsd(criteria="TYPE=iso9660")
+ assert devlist == ['/dev/cd0a']
+
+ # lp: #1841466
+ devlist = util.find_devs_with_openbsd(criteria="LABEL_FATBOOT=A_LABEL")
+ assert devlist == ['/dev/cd0a', '/dev/sd1i']
+
+ @mock.patch('glob.glob')
+ def test_find_devs_with_freebsd(self, m_glob):
+ def fake_glob(pattern):
+ msdos = ["/dev/msdosfs/EFISYS"]
+ iso9660 = ["/dev/iso9660/config-2"]
+ if pattern == "/dev/msdosfs/*":
+ return msdos
+ elif pattern == "/dev/iso9660/*":
+ return iso9660
+ raise Exception
+ m_glob.side_effect = fake_glob
+
+ devlist = util.find_devs_with_freebsd()
+ assert set(devlist) == set([
+ '/dev/iso9660/config-2', '/dev/msdosfs/EFISYS'])
+
+ devlist = util.find_devs_with_freebsd(criteria="TYPE=iso9660")
+ assert devlist == ['/dev/iso9660/config-2']
+
+ devlist = util.find_devs_with_freebsd(criteria="TYPE=vfat")
+ assert devlist == ['/dev/msdosfs/EFISYS']
+
+ # lp: #1841466
+ devlist = util.find_devs_with_freebsd(criteria="LABEL_FATBOOT=A_LABEL")
+ assert devlist == []
+
+ @mock.patch("cloudinit.subp.subp")
+ def test_find_devs_with_netbsd(self, m_subp):
+ side_effect_values = [
+ ("ld0 dk0 dk1 cd0", ""),
(
- "mscdlabel: CDIOREADTOCHEADER: "
- "Inappropriate ioctl for device\n"
- "track (ctl=4) at sector 0\n"
- "disklabel not written\n"
+ (
+ "mscdlabel: CDIOREADTOCHEADER: "
+ "Inappropriate ioctl for device\n"
+ "track (ctl=4) at sector 0\n"
+ "disklabel not written\n"
+ ),
+ "",
),
- "",
- ),
- (
(
- "mscdlabel: CDIOREADTOCHEADER: "
- "Inappropriate ioctl for device\n"
- "track (ctl=4) at sector 0\n"
- "disklabel not written\n"
+ (
+ "mscdlabel: CDIOREADTOCHEADER: "
+ "Inappropriate ioctl for device\n"
+ "track (ctl=4) at sector 0\n"
+ "disklabel not written\n"
+ ),
+ "",
),
- "",
- ),
- (
(
- "mscdlabel: CDIOREADTOCHEADER: "
- "Inappropriate ioctl for device\n"
- "track (ctl=4) at sector 0\n"
- "disklabel not written\n"
+ (
+ "mscdlabel: CDIOREADTOCHEADER: "
+ "Inappropriate ioctl for device\n"
+ "track (ctl=4) at sector 0\n"
+ "disklabel not written\n"
+ ),
+ "",
),
- "",
- ),
- (
(
- "track (ctl=4) at sector 0\n"
- 'ISO filesystem, label "config-2", '
- "creation time: 2020/03/31 17:29\n"
- "adding as 'a'\n"
+ (
+ "track (ctl=4) at sector 0\n"
+ 'ISO filesystem, label "config-2", '
+ "creation time: 2020/03/31 17:29\n"
+ "adding as 'a'\n"
+ ),
+ "",
),
- "",
- ),
- ]
- m_subp.side_effect = side_effect_values
- devlist = util.find_devs_with_netbsd()
- assert set(devlist) == set(
- ["/dev/ld0", "/dev/dk0", "/dev/dk1", "/dev/cd0"]
- )
- m_subp.side_effect = side_effect_values
- devlist = util.find_devs_with_netbsd(criteria="TYPE=iso9660")
- assert devlist == ["/dev/cd0"]
- m_subp.side_effect = side_effect_values
- devlist = util.find_devs_with_netbsd(criteria="TYPE=vfat")
- assert devlist == ["/dev/ld0", "/dev/dk0", "/dev/dk1"]
+ ]
+ m_subp.side_effect = side_effect_values
+ devlist = util.find_devs_with_netbsd()
+ assert set(devlist) == set(
+ ["/dev/ld0", "/dev/dk0", "/dev/dk1", "/dev/cd0"]
+ )
+
+ m_subp.side_effect = side_effect_values
+ devlist = util.find_devs_with_netbsd(criteria="TYPE=iso9660")
+ assert devlist == ["/dev/cd0"]
+
+ m_subp.side_effect = side_effect_values
+ devlist = util.find_devs_with_netbsd(criteria="TYPE=vfat")
+ assert devlist == ["/dev/ld0", "/dev/dk0", "/dev/dk1"]
+
+ # lp: #1841466
+ m_subp.side_effect = side_effect_values
+ devlist = util.find_devs_with_netbsd(criteria="LABEL_FATBOOT=A_LABEL")
+ assert devlist == ['/dev/ld0', '/dev/dk0', '/dev/dk1', '/dev/cd0']
# vi: ts=4 expandtab