From 17d0358a1122fb307cd247a3d6faef312d17c945 Mon Sep 17 00:00:00 2001 From: Marllus Lustosa Date: Tue, 21 Jul 2020 18:09:01 -0300 Subject: [PATCH 1/6] Fixing the problem of the new name LABEL_FATBOOT in new SO, like Buster and Ubuntu 20.04 --- cloudinit/sources/DataSourceNoCloud.py | 1 + tools/ds-identify | 2 ++ 2 files changed, 3 insertions(+) diff --git a/cloudinit/sources/DataSourceNoCloud.py b/cloudinit/sources/DataSourceNoCloud.py index e8856920db3..6b88741a369 100644 --- a/cloudinit/sources/DataSourceNoCloud.py +++ b/cloudinit/sources/DataSourceNoCloud.py @@ -41,6 +41,7 @@ def _get_devices(self, label): label_list = util.find_devs_with("LABEL=%s" % label.upper()) label_list.extend(util.find_devs_with("LABEL=%s" % label.lower())) + label_list.extend( util.find_devs_with("LABEL_FATBOOT=%s" % label)) devlist = list(set(fslist) & set(label_list)) devlist.sort(reverse=True) diff --git a/tools/ds-identify b/tools/ds-identify index 071cdc0cadd..ebd05d98227 100755 --- a/tools/ds-identify +++ b/tools/ds-identify @@ -268,6 +268,8 @@ read_fs_info() { dev=${line#DEVNAME=};; LABEL=*) label="${line#LABEL=}"; labels="${labels}${line#LABEL=}${delim}";; + LABEL_FATBOOT=*) label="${line#LABEL_FATBOOT=}"; + labels="${labels}${line#LABEL_FATBOOT=}${delim}";; TYPE=*) ftype=${line#TYPE=};; UUID=*) uuids="${uuids}${line#UUID=}$delim";; esac From 568d243b59e2d57ae29e060e01bcbc5bed4b6086 Mon Sep 17 00:00:00 2001 From: Marllus Lustosa Date: Tue, 21 Jul 2020 19:28:04 -0300 Subject: [PATCH 2/6] cla-signers --- tools/.github-cla-signers | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/.github-cla-signers b/tools/.github-cla-signers index ae2fae91d07..5f4dc79b617 100644 --- a/tools/.github-cla-signers +++ b/tools/.github-cla-signers @@ -7,6 +7,7 @@ dhensby eandersson landon912 lucasmoura +marlluslustosa matthewruffell nishigori onitake From 1926510307ff67ac7072cb6438c86683da4e8075 Mon Sep 17 00:00:00 2001 From: Marllus Lustosa Date: Tue, 21 Jul 2020 19:34:40 -0300 Subject: [PATCH 3/6] removing inadequate code space --- cloudinit/sources/DataSourceNoCloud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudinit/sources/DataSourceNoCloud.py b/cloudinit/sources/DataSourceNoCloud.py index 6b88741a369..e408d7303ca 100644 --- a/cloudinit/sources/DataSourceNoCloud.py +++ b/cloudinit/sources/DataSourceNoCloud.py @@ -41,7 +41,7 @@ def _get_devices(self, label): label_list = util.find_devs_with("LABEL=%s" % label.upper()) label_list.extend(util.find_devs_with("LABEL=%s" % label.lower())) - label_list.extend( util.find_devs_with("LABEL_FATBOOT=%s" % label)) + label_list.extend(util.find_devs_with("LABEL_FATBOOT=%s" % label)) devlist = list(set(fslist) & set(label_list)) devlist.sort(reverse=True) From e4ac5ff9ee80678fcd91d5509e7d050b4bb42ee1 Mon Sep 17 00:00:00 2001 From: Marllus Lustosa Date: Tue, 21 Jul 2020 19:37:33 -0300 Subject: [PATCH 4/6] removing inadequate code space - ds-identify --- tools/ds-identify | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ds-identify b/tools/ds-identify index ebd05d98227..d58b365b900 100755 --- a/tools/ds-identify +++ b/tools/ds-identify @@ -269,7 +269,7 @@ read_fs_info() { LABEL=*) label="${line#LABEL=}"; labels="${labels}${line#LABEL=}${delim}";; LABEL_FATBOOT=*) label="${line#LABEL_FATBOOT=}"; - labels="${labels}${line#LABEL_FATBOOT=}${delim}";; + labels="${labels}${line#LABEL_FATBOOT=}${delim}";; TYPE=*) ftype=${line#TYPE=};; UUID=*) uuids="${uuids}${line#UUID=}$delim";; esac From cf01c6a03e0a9d1bfdbb2a403c6854d3e5ee26ec Mon Sep 17 00:00:00 2001 From: Marllus Lustosa Date: Wed, 22 Jul 2020 12:36:09 -0300 Subject: [PATCH 5/6] Update ds-identify --- tools/ds-identify | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/ds-identify b/tools/ds-identify index d58b365b900..4e5700fc604 100755 --- a/tools/ds-identify +++ b/tools/ds-identify @@ -266,10 +266,9 @@ read_fs_info() { isodevs="${isodevs},${dev}=$label" ftype=""; dev=""; label=""; dev=${line#DEVNAME=};; - LABEL=*) label="${line#LABEL=}"; - labels="${labels}${line#LABEL=}${delim}";; - LABEL_FATBOOT=*) label="${line#LABEL_FATBOOT=}"; - labels="${labels}${line#LABEL_FATBOOT=}${delim}";; + LABEL=*|LABEL_FATBOOT=*) + label="${line#*=}"; + labels="${labels}${label}${delim}";; TYPE=*) ftype=${line#TYPE=};; UUID=*) uuids="${uuids}${line#UUID=}$delim";; esac From 71ecefbc50a6b2955f2b25b455e3f0f757a4e936 Mon Sep 17 00:00:00 2001 From: James Falcon Date: Wed, 29 Jul 2020 15:33:54 -0500 Subject: [PATCH 6/6] Fix find_devs_with_freebsd and add tests --- cloudinit/util.py | 1 + tests/unittests/test_ds_identify.py | 18 +++ tests/unittests/test_util.py | 195 ++++++++++++++++------------ 3 files changed, 131 insertions(+), 83 deletions(-) diff --git a/cloudinit/util.py b/cloudinit/util.py index b6f1117f1e4..8c3738b96dd 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -1111,6 +1111,7 @@ def close_stdin(): def find_devs_with_freebsd(criteria=None, oformat='device', tag=None, no_cache=False, path=None): + devlist = [] if not criteria: return glob.glob("/dev/msdosfs/*") + glob.glob("/dev/iso9660/*") if criteria.startswith("LABEL="): diff --git a/tests/unittests/test_ds_identify.py b/tests/unittests/test_ds_identify.py index cb57f2d04be..9314b244249 100644 --- a/tests/unittests/test_ds_identify.py +++ b/tests/unittests/test_ds_identify.py @@ -577,6 +577,10 @@ def test_nocloud_upper(self): """NoCloud is found with uppercase filesystem label.""" self._test_ds_found('NoCloudUpper') + def test_nocloud_fatboot(self): + """NoCloud fatboot label - LP: #184166.""" + self._test_ds_found('NoCloud-fatboot') + def test_nocloud_seed(self): """Nocloud seed directory.""" self._test_ds_found('NoCloud-seed') @@ -816,6 +820,20 @@ def _print_run_output(rc, out, err, cfg, files): 'dev/vdb': 'pretend iso content for cidata\n', } }, + 'NoCloud-fatboot': { + 'ds': 'NoCloud', + 'mocks': [ + MOCK_VIRT_IS_XEN, + {'name': 'blkid', 'ret': 0, + 'out': blkid_out( + BLKID_UEFI_UBUNTU + + [{'DEVNAME': 'xvdb', 'TYPE': 'vfat', 'SEC_TYPE': 'msdos', + 'UUID': '355a-4FC2', 'LABEL_FATBOOT': 'cidata'}])}, + ], + 'files': { + 'dev/vdb': 'pretend iso content for cidata\n', + } + }, 'NoCloud-seed': { 'ds': 'NoCloud', 'files': { diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py index 409dba61c52..72c569673d2 100644 --- a/tests/unittests/test_util.py +++ b/tests/unittests/test_util.py @@ -967,96 +967,125 @@ def test_get_proc_ppid(self): 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