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

@ -262,6 +262,19 @@ class TestParted(ModuleTestCase):
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')
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):
# Test that get_device_info result is checked in check mode too
# No change on partition 1