Skip to content

Commit

Permalink
feat(freebsd): support freebsd find part by gptid and ufsid (#5122)
Browse files Browse the repository at this point in the history
freebsd obtained device partition name by the function find_freebsd_part,
the params of function is the device name mounted,  usually is first  field
of /etc/fstab ,  like /dev/gpt/rootfs,  but freebsd fstab also support gptid or
ufsid for a unique id to identify partitions, like /dev/gptid/xxx,
/dev/ufsid/xxx,  update function to  support
  • Loading branch information
jinkkkang committed Apr 8, 2024
1 parent 0a3a5e2 commit 42becf1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cloudinit/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2631,7 +2631,7 @@ def find_freebsd_part(fs):
return splitted[0]
elif len(splitted) == 3:
return splitted[2]
elif splitted[2] in ["label", "gpt", "ufs"]:
elif splitted[2] in ["label", "gpt", "gptid", "ufs", "ufsid"]:
target_label = fs[5:]
(part, _err) = subp.subp(["glabel", "status", "-s"])
for labels in part.split("\n"):
Expand Down
26 changes: 26 additions & 0 deletions tests/unittests/distros/test_freebsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,32 @@ def test_find_freebsd_part_gpt(self, mock_subp):
res = find_freebsd_part("/dev/gpt/rootfs")
self.assertEqual("vtbd0p3", res)

@mock.patch("cloudinit.subp.subp")
def test_find_freebsd_part_gptid(self, mock_subp):
glabel_out = """
gpt/bootfs N/A vtbd0p1
gpt/efiesp N/A vtbd0p2
gpt/swapfs N/A vtbd0p3
gptid/4cd084b4-7fb4-11ee-a7ba-002590ec5bf2 N/A vtbd0p4
"""
mock_subp.return_value = (glabel_out, "")
res = find_freebsd_part(
"/dev/gptid/4cd084b4-7fb4-11ee-a7ba-002590ec5bf2"
)
self.assertEqual("vtbd0p4", res)

@mock.patch("cloudinit.subp.subp")
def test_find_freebsd_part_ufsid(self, mock_subp):
glabel_out = """
gpt/bootfs N/A vtbd0p1
gpt/efiesp N/A vtbd0p2
gpt/swapfs N/A vtbd0p3
ufsid/654e0663786f5131 N/A vtbd0p4
"""
mock_subp.return_value = (glabel_out, "")
res = find_freebsd_part("/dev/ufsid/654e0663786f5131")
self.assertEqual("vtbd0p4", res)

def test_get_path_dev_freebsd_label(self):
mnt_list = """
/dev/label/rootfs / ufs rw 1 1
Expand Down
1 change: 1 addition & 0 deletions tools/.github-cla-signers
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Jehops
jf
jfroche
Jille
jinkkkang
JohnKepplers
johnsonshi
jordimassaguerpla
Expand Down

0 comments on commit 42becf1

Please sign in to comment.