mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-23 04:09:04 +00:00
* parted: add unit_preserve_case option to fix unit case in return value Adds O(unit_preserve_case) feature flag (bool, default None) to control the case of the ``unit`` field in the module return value. Previously the unit was always lowercased (e.g. ``kib``), making it impossible to feed ``disk.unit`` back as the ``unit`` parameter without a validation error. With O(unit_preserve_case=true) the unit is returned in its original mixed case (e.g. ``KiB``), matching the accepted input values. The default (None) emits a deprecation notice; the default will become V(true) in community.general 14.0.0. Fixes #1860 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * parted: add changelog fragment for PR #11813 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * adjustments from review * Comment 15.0.0 deprecation in option decription. * parted: fix unit test calls to parse_partition_info after signature change Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * parted: fix unit_preserve_case - parted outputs lowercase units in machine mode Parted's machine-parseable output always uses lowercase unit suffixes (e.g. ``kib``, ``mib``) regardless of what was passed to the ``unit`` parameter. Removing the explicit ``.lower()`` call was therefore not enough to preserve case. Add a ``canonical_unit()`` helper that maps a unit string to its canonical mixed-case form using ``parted_units`` as the reference, and use it instead of a bare identity when ``unit_preserve_case=true``. Also fix a yamllint violation in the DOCUMENTATION block (missing space after ``#`` in inline comments). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Update plugins/modules/parted.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/parted.py Co-authored-by: Felix Fontein <felix@fontein.de> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Felix Fontein <felix@fontein.de>
123 lines
3.1 KiB
YAML
123 lines
3.1 KiB
YAML
# Copyright (c) 2021, Alexei Znamensky
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
- name: Install parted
|
|
package:
|
|
name: parted
|
|
state: present
|
|
when: ansible_facts.os_family == 'Alpine'
|
|
|
|
- name: Create empty file
|
|
community.general.filesize:
|
|
path: /bigfile
|
|
size: 1GiB
|
|
notify: Remove file
|
|
|
|
- name: Obtain loop device name
|
|
command:
|
|
cmd: losetup -f
|
|
changed_when: false
|
|
register: losetup_name
|
|
|
|
- name: Create loopback device
|
|
command:
|
|
cmd: losetup -f /bigfile
|
|
changed_when: true
|
|
register: losetup_cmd
|
|
notify: Remove loopback device
|
|
|
|
- name: Create first partition
|
|
community.general.parted:
|
|
device: "{{ losetup_name.stdout }}"
|
|
number: 1
|
|
state: present
|
|
fs_type: ext4
|
|
part_end: "50%"
|
|
register: partition1
|
|
|
|
- name: Make filesystem
|
|
community.general.filesystem:
|
|
device: "{{ losetup_name.stdout }}p1"
|
|
fstype: ext4
|
|
register: fs1_succ
|
|
|
|
- name: Make filesystem (fail)
|
|
community.general.filesystem:
|
|
device: "{{ losetup_name.stdout }}p2"
|
|
fstype: ext4
|
|
ignore_errors: true
|
|
register: fs_fail
|
|
|
|
- name: Create second partition
|
|
community.general.parted:
|
|
device: "{{ losetup_name.stdout }}"
|
|
number: 2
|
|
state: present
|
|
fs_type: ext4
|
|
part_start: "{{ partition1.partitions[0].end + 1 }}KiB"
|
|
part_end: "100%"
|
|
register: partition2
|
|
|
|
- name: Make filesystem
|
|
community.general.filesystem:
|
|
device: "{{ losetup_name.stdout }}p2"
|
|
fstype: ext4
|
|
register: fs2_succ
|
|
|
|
- name: Remove first partition
|
|
community.general.parted:
|
|
device: "{{ losetup_name.stdout }}"
|
|
number: 1
|
|
state: absent
|
|
register: partition_rem1
|
|
|
|
- name: Assert results
|
|
assert:
|
|
that:
|
|
- partition1 is changed
|
|
- fs1_succ is changed
|
|
- fs_fail is failed
|
|
- fs_fail is not changed
|
|
- partition2 is changed
|
|
- partition2.partitions | length == 2
|
|
- fs2_succ is changed
|
|
- partition_rem1 is changed
|
|
- partition_rem1.partitions | length == 1
|
|
|
|
- name: Get partition info with unit_preserve_case=true
|
|
community.general.parted:
|
|
device: "{{ losetup_name.stdout }}"
|
|
state: info
|
|
unit: KiB
|
|
unit_preserve_case: true
|
|
register: info_preserve_true
|
|
|
|
- name: Get partition info with unit_preserve_case=false
|
|
community.general.parted:
|
|
device: "{{ losetup_name.stdout }}"
|
|
state: info
|
|
unit: KiB
|
|
unit_preserve_case: false
|
|
register: info_preserve_false
|
|
|
|
- name: Assert unit_preserve_case results
|
|
assert:
|
|
that:
|
|
- info_preserve_true.disk.unit == "KiB"
|
|
- info_preserve_true.partitions[0].unit == "KiB"
|
|
- info_preserve_false.disk.unit == "kib"
|
|
- info_preserve_false.partitions[0].unit == "kib"
|
|
|
|
- name: Use returned unit as input (round-trip) - regression test for issue 1860
|
|
community.general.parted:
|
|
device: "{{ losetup_name.stdout }}"
|
|
state: info
|
|
unit: "{{ info_preserve_true.disk.unit }}"
|
|
unit_preserve_case: true
|
|
register: info_roundtrip
|
|
|
|
- name: Assert round-trip succeeds and unit is consistent
|
|
assert:
|
|
that:
|
|
- info_roundtrip.disk.unit == info_preserve_true.disk.unit
|