Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cloudinit/sources/DataSourceNoCloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cloudinit/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,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="):
Expand Down
18 changes: 18 additions & 0 deletions tests/unittests/test_ds_identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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': {
Expand Down
195 changes: 112 additions & 83 deletions tests/unittests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == []
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has anyone tried booting a freebsd image under these conditions to see what the result looks like, and what we could be looking for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igalic Was that one of the BSD people you pinged on the last ticket? Should I ping them here too? If we make an effort to reach out but they're unavailable, do you think the unit test changes are sufficient?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have roughly 3 *BSD people currently active:

of those, @goneri is the most experienced when it comes to NoCloud

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aloha,

Thank you @TheRealFalcon and @igalic, I will give a try to the patch.

Comment on lines +1017 to +1029
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to see these tests parameterised.


@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']
Comment on lines +1073 to +1089
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These too.


# vi: ts=4 expandtab
1 change: 1 addition & 0 deletions tools/.github-cla-signers
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dhensby
eandersson
landon912
lucasmoura
marlluslustosa
matthewruffell
nishigori
onitake
Expand Down
5 changes: 3 additions & 2 deletions tools/ds-identify
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +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=*|LABEL_FATBOOT=*)
label="${line#*=}";
labels="${labels}${label}${delim}";;
TYPE=*) ftype=${line#TYPE=};;
UUID=*) uuids="${uuids}${line#UUID=}$delim";;
esac
Expand Down