1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

parted: proper fix for change of partition label case (#594) (#986)

* parted: proper fix for change of partition label case
calling mkpart even when partition existed before mklabel call, fixes #522

* changelog fragment for parted fix #522

* Update changelogs/fragments/522-parted_change_label.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* typo in comment

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 4931fb2681)

Co-authored-by: Robert Osowiecki <robert.osowiecki@gmail.com>
This commit is contained in:
patchback[bot] 2020-09-29 06:08:33 +02:00 committed by GitHub
parent 0d459e5662
commit d7c4849473
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "parted - fix creating partition when label is changed (https://github.com/ansible-collections/community.general/issues/522)."

View file

@ -634,11 +634,12 @@ def main():
if state == 'present': if state == 'present':
# Assign label if required # Assign label if required
if current_device['generic'].get('table', None) != label: mklabel_needed = current_device['generic'].get('table', None) != label
if mklabel_needed:
script += "mklabel %s " % label script += "mklabel %s " % label
# Create partition if required # Create partition if required
if part_type and not part_exists(current_parts, 'num', number): if part_type and (mklabel_needed or not part_exists(current_parts, 'num', number)):
script += "mkpart %s %s%s %s " % ( script += "mkpart %s %s%s %s " % (
part_type, part_type,
'%s ' % fs_type if fs_type is not None else '', '%s ' % fs_type if fs_type is not None else '',

View file

@ -262,6 +262,19 @@ class TestParted(ModuleTestCase):
with patch('ansible_collections.community.general.plugins.modules.system.parted.get_device_info', return_value=parted_dict2): with patch('ansible_collections.community.general.plugins.modules.system.parted.get_device_info', return_value=parted_dict2):
self.execute_module(changed=True, script='unit KiB mklabel gpt mkpart primary 0% 100% unit KiB name 1 \'"lvmpartition"\' set 1 lvm on') self.execute_module(changed=True, script='unit KiB mklabel gpt mkpart primary 0% 100% unit KiB name 1 \'"lvmpartition"\' set 1 lvm on')
def test_change_label_gpt(self):
# When partitions already exists and label is changed, mkpart should be called even when partition already exists,
# because new empty label will be created anyway
set_module_args({
'device': '/dev/sdb',
'number': 1,
'state': 'present',
'label': 'gpt',
'_ansible_check_mode': True,
})
with patch('ansible_collections.community.general.plugins.modules.system.parted.get_device_info', return_value=parted_dict1):
self.execute_module(changed=True, script='unit KiB mklabel gpt mkpart primary 0% 100%')
def test_check_mode_unchanged(self): def test_check_mode_unchanged(self):
# Test that get_device_info result is checked in check mode too # Test that get_device_info result is checked in check mode too
# No change on partition 1 # No change on partition 1