mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-06-12 19:15:31 +00:00
[PR #12121/6e6199ae backport][stable-12] parted: ignore MBR partition type codes in flags on SUSE systems (#12146)
parted: ignore MBR partition type codes in flags on SUSE systems (#12121)
* parted: ignore MBR partition type codes reported as flags by SUSE parted
SUSE's patched parted reports MBR partition type codes (e.g., type=8e for
Linux LVM) in the machine-parseable flags output. The module was trying to
unset these pseudo-flags via 'parted set N type=8e off', which is not a
valid parted command, causing the task to fail when using flags: [lvm] on
msdos-labelled disks on SUSE systems.
Fixes #6292
* feat(changelog): add fragment for PR 12121
* Update changelogs/fragments/12121-parted-suse-msdos-type-code.yml
---------
(cherry picked from commit 6e6199ae3d)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
789789f202
commit
31aabddc46
3 changed files with 103 additions and 3 deletions
|
|
@ -0,0 +1,5 @@
|
|||
bugfixes:
|
||||
- parted - ignore MBR partition type codes (for example ``type=8e``) reported as flags
|
||||
by some parted builds (for example on SUSE), which cannot be managed via the ``set`` command
|
||||
(https://github.com/ansible-collections/community.general/issues/6292,
|
||||
https://github.com/ansible-collections/community.general/pull/12121).
|
||||
|
|
@ -765,9 +765,12 @@ def main():
|
|||
if "esp" in flags and "boot" not in flags:
|
||||
flags.append("boot")
|
||||
|
||||
# Compute only the changes in flags status
|
||||
flags_off = list(set(partition["flags"]) - set(flags))
|
||||
flags_on = list(set(flags) - set(partition["flags"]))
|
||||
# Compute only the changes in flags status.
|
||||
# Some parted builds (e.g., SUSE) include MBR partition type codes (e.g.,
|
||||
# type=8e) in the flags output; these cannot be managed via the 'set' command.
|
||||
current_flags = [f for f in partition["flags"] if not re.match(r"^type=[0-9a-fA-F]+$", f)]
|
||||
flags_off = list(set(current_flags) - set(flags))
|
||||
flags_on = list(set(flags) - set(current_flags))
|
||||
|
||||
for f in flags_on:
|
||||
script += ["set", str(number), f, "on"]
|
||||
|
|
|
|||
|
|
@ -143,6 +143,59 @@ parted_dict3 = {
|
|||
}
|
||||
|
||||
|
||||
# Simulates SUSE-patched parted that exposes MBR type codes as flags.
|
||||
# Partition 1 has "lvm" set + SUSE adds "type=8e" as a pseudo-flag.
|
||||
parted_dict_suse_lvm = {
|
||||
"generic": {
|
||||
"dev": "/dev/sdb",
|
||||
"size": 286061.0,
|
||||
"unit": "mb",
|
||||
"table": "msdos",
|
||||
"model": "ATA TOSHIBA THNSFJ25",
|
||||
"logical_block": 512,
|
||||
"physical_block": 512,
|
||||
},
|
||||
"partitions": [
|
||||
{
|
||||
"num": 1,
|
||||
"begin": 1.05,
|
||||
"end": 106.0,
|
||||
"size": 105.0,
|
||||
"fstype": "",
|
||||
"name": "",
|
||||
"flags": ["lvm", "type=8e"],
|
||||
"unit": "mb",
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
# Simulates SUSE-patched parted where partition has no logical flags yet,
|
||||
# but SUSE reports "type=83" (Linux MBR type code) as a pseudo-flag.
|
||||
parted_dict_suse_noflag = {
|
||||
"generic": {
|
||||
"dev": "/dev/sdb",
|
||||
"size": 286061.0,
|
||||
"unit": "mb",
|
||||
"table": "msdos",
|
||||
"model": "ATA TOSHIBA THNSFJ25",
|
||||
"logical_block": 512,
|
||||
"physical_block": 512,
|
||||
},
|
||||
"partitions": [
|
||||
{
|
||||
"num": 1,
|
||||
"begin": 1.05,
|
||||
"end": 106.0,
|
||||
"size": 105.0,
|
||||
"fstype": "",
|
||||
"name": "",
|
||||
"flags": ["type=83"],
|
||||
"unit": "mb",
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
class TestParted(ModuleTestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
|
@ -453,6 +506,45 @@ class TestParted(ModuleTestCase):
|
|||
):
|
||||
self.execute_module(changed=True)
|
||||
|
||||
def test_suse_msdos_type_code_with_lvm_already_set(self):
|
||||
# When SUSE parted reports "type=8e" alongside "lvm" in the flags output,
|
||||
# the module must not try to unset the pseudo-flag (issue #6292).
|
||||
with set_module_args(
|
||||
{
|
||||
"device": "/dev/sdb",
|
||||
"number": 1,
|
||||
"state": "present",
|
||||
"flags": ["lvm"],
|
||||
}
|
||||
):
|
||||
with patch(
|
||||
"ansible_collections.community.general.plugins.modules.parted.get_device_info",
|
||||
return_value=parted_dict_suse_lvm,
|
||||
):
|
||||
self.execute_module(changed=False)
|
||||
|
||||
def test_suse_msdos_type_code_set_lvm_flag(self):
|
||||
# When SUSE parted only reports "type=83" (no logical flags) and the user
|
||||
# requests lvm, the module must set lvm without trying to unset type=83.
|
||||
with set_module_args(
|
||||
{
|
||||
"device": "/dev/sdb",
|
||||
"number": 1,
|
||||
"state": "present",
|
||||
"flags": ["lvm"],
|
||||
}
|
||||
):
|
||||
with patch(
|
||||
"ansible_collections.community.general.plugins.modules.parted.get_device_info",
|
||||
return_value=parted_dict_suse_noflag,
|
||||
):
|
||||
self.parted.reset_mock()
|
||||
self.execute_module(changed=True)
|
||||
self.assertEqual(
|
||||
self.parted.mock_calls,
|
||||
[call(["unit", "KiB", "set", "1", "lvm", "on"], "/dev/sdb", "optimal")],
|
||||
)
|
||||
|
||||
def test_version_info(self):
|
||||
"""Test that the parse_parted_version returns the expected tuple"""
|
||||
for key, value in parted_version_info.items():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue