From bc7ff83cd9eb3ed2ce07f28650df438c4ec21ae4 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Wed, 23 May 2018 10:06:26 -0500 Subject: [PATCH] parted module not idempotent for esp flag and name (#40547) * parted module not idempotent for esp flag and name Fixes #40452 Currently the parted module doesn't take into account names with spaces in them which leads to non-idempotent transactions on the state of the system because the name comparison will never succeed. Also, when the esp flag is set, parted infers the boot flag and the parted module did not previously account for this. This lead to non-idempotent transactions as well. Signed-off-by: Adam Miller * fix unit tests, expected command changed in the patch Signed-off-by: Adam Miller --- lib/ansible/modules/system/parted.py | 10 +++++++++- test/units/modules/system/test_parted.py | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/system/parted.py b/lib/ansible/modules/system/parted.py index 46ecdcafdc8..5b43742718a 100644 --- a/lib/ansible/modules/system/parted.py +++ b/lib/ansible/modules/system/parted.py @@ -658,10 +658,18 @@ def main(): # Assign name to the partition if name is not None and partition.get('name', None) != name: - script += "name %s %s " % (number, name) + # Wrap double quotes in single quotes so the shell doesn't strip + # the double quotes as those need to be included in the arg + # passed to parted + script += 'name %s \'"%s"\' ' % (number, name) # Manage flags if flags: + # Parted infers boot with esp, if you assign esp, boot is set + # and if boot is unset, esp is also unset. + 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'])) diff --git a/test/units/modules/system/test_parted.py b/test/units/modules/system/test_parted.py index 95735aabd14..df141af7971 100644 --- a/test/units/modules/system/test_parted.py +++ b/test/units/modules/system/test_parted.py @@ -237,4 +237,4 @@ class TestParted(ModuleTestCase): '_ansible_check_mode': True, }) with patch('ansible.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')