Skip to content

Commit

Permalink
device_part_info: do not recurse if we did not match anything (#5169)
Browse files Browse the repository at this point in the history
First off, the recursion was bogus, because it called the wrong
function, but more importantly, it would lead to infinite recursion
anyway, even if we called the right one.

Throw a ValueError instead, because we've most likely been called with a
bogus value. Add a test to show that.

Sponsored by: The FreeBSD Foundation
  • Loading branch information
igalic authored and holmanb committed May 31, 2024
1 parent bbb7f62 commit dff0212
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cloudinit/distros/bsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,5 @@ def device_part_info(devpath: str) -> tuple:
if m:
return m["dev"], m["part_slice"]

return distros.Distro.device_part_info(devpath)
# the input is bogus and we need to bail
raise ValueError(f"Invalid value for devpath: '{devpath}'")
6 changes: 6 additions & 0 deletions tests/unittests/config/test_cc_growpart.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,12 @@ class TestDevicePartInfo:
does_not_raise(),
id="bsd_mbr_slice_and_partition",
),
pytest.param(
"zroot/ROOТ/default",
(),
pytest.raises(ValueError),
id="zfs_dataset",
),
),
)
def test_device_part_info(self, devpath, expected, raised_exception):
Expand Down

0 comments on commit dff0212

Please sign in to comment.