From abcba9dbbec79374dc0cdb9978f0622e74a60e48 Mon Sep 17 00:00:00 2001 From: Roman Belyakovsky Date: Thu, 9 Mar 2023 21:09:13 +0200 Subject: [PATCH] Interfaces file spaces fix (#6131) * interfaces_file: added test case for #6120 * interfaces_file: reverted code to #fafabed * interfaces_file: added changelog fragment * interfaces_file: added missing licenses * interfaces_file: improved test coverage * interfaces_file: fixed retrieving option values * Update plugins/modules/interfaces_file.py Co-authored-by: Felix Fontein * Update plugins/modules/interfaces_file.py Co-authored-by: Felix Fontein * Update tests/unit/plugins/modules/interfaces_file/test_interfaces_file.py Co-authored-by: Felix Fontein * Update plugins/modules/interfaces_file.py Co-authored-by: Felix Fontein * Update plugins/modules/interfaces_file.py Co-authored-by: Felix Fontein * Update plugins/modules/interfaces_file.py Co-authored-by: Felix Fontein * Update plugins/modules/interfaces_file.py Co-authored-by: Felix Fontein * Update plugins/modules/interfaces_file.py Co-authored-by: Felix Fontein * Update plugins/modules/interfaces_file.py Co-authored-by: Felix Fontein * Update tests/unit/plugins/modules/interfaces_file/test_interfaces_file.py Co-authored-by: Felix Fontein * interfaces_file: spacing fix --------- Co-authored-by: Felix Fontein --- ...-interfaces_file-for-no-leading-spaces.yml | 2 + plugins/modules/interfaces_file.py | 154 ++++++++----- .../no_leading_spaces.test_no_changes | 8 + .../no_leading_spaces.test_no_changes.json | 21 ++ ...eading_spaces.test_no_changes.json.license | 3 + .../no_leading_spaces.test_no_changes.license | 3 + .../no_leading_spaces_add_aggi_up | 8 + ..._leading_spaces_add_aggi_up.exceptions.txt | 8 + ..._spaces_add_aggi_up.exceptions.txt.license | 3 + .../no_leading_spaces_add_aggi_up.json | 21 ++ ...no_leading_spaces_add_aggi_up.json.license | 3 + .../no_leading_spaces_add_aggi_up.license | 3 + .../no_leading_spaces_add_aggi_up_twice | 8 + ...ng_spaces_add_aggi_up_twice.exceptions.txt | 17 ++ ...s_add_aggi_up_twice.exceptions.txt.license | 3 + .../no_leading_spaces_add_aggi_up_twice.json | 21 ++ ...ding_spaces_add_aggi_up_twice.json.license | 3 + ...o_leading_spaces_add_aggi_up_twice.license | 3 + .../no_leading_spaces_add_and_delete_aggi_up | 8 + ...aces_add_and_delete_aggi_up.exceptions.txt | 17 ++ ..._and_delete_aggi_up.exceptions.txt.license | 3 + ...leading_spaces_add_and_delete_aggi_up.json | 21 ++ ...spaces_add_and_delete_aggi_up.json.license | 3 + ...ding_spaces_add_and_delete_aggi_up.license | 3 + .../no_leading_spaces_aggi_remove_dup | 8 + ...ding_spaces_aggi_remove_dup.exceptions.txt | 17 ++ ...ces_aggi_remove_dup.exceptions.txt.license | 3 + .../no_leading_spaces_aggi_remove_dup.json | 21 ++ ...eading_spaces_aggi_remove_dup.json.license | 3 + .../no_leading_spaces_aggi_remove_dup.license | 3 + .../no_leading_spaces_change_ipv4 | 8 + ..._leading_spaces_change_ipv4.exceptions.txt | 0 ..._spaces_change_ipv4.exceptions.txt.license | 3 + .../no_leading_spaces_change_ipv4.json | 21 ++ ...no_leading_spaces_change_ipv4.json.license | 3 + .../no_leading_spaces_change_ipv4.license | 3 + .../no_leading_spaces_change_ipv4_post_up | 9 + ..._spaces_change_ipv4_post_up.exceptions.txt | 0 ...change_ipv4_post_up.exceptions.txt.license | 3 + ...no_leading_spaces_change_ipv4_post_up.json | 21 ++ ...ng_spaces_change_ipv4_post_up.json.license | 3 + ...leading_spaces_change_ipv4_post_up.license | 3 + .../no_leading_spaces_change_ipv4_pre_up | 9 + ...g_spaces_change_ipv4_pre_up.exceptions.txt | 0 ..._change_ipv4_pre_up.exceptions.txt.license | 3 + .../no_leading_spaces_change_ipv4_pre_up.json | 21 ++ ...ing_spaces_change_ipv4_pre_up.json.license | 3 + ..._leading_spaces_change_ipv4_pre_up.license | 3 + .../no_leading_spaces_change_ipv6 | 8 + ..._leading_spaces_change_ipv6.exceptions.txt | 9 + ..._spaces_change_ipv6.exceptions.txt.license | 3 + .../no_leading_spaces_change_ipv6.json | 21 ++ ...no_leading_spaces_change_ipv6.json.license | 3 + .../no_leading_spaces_change_ipv6.license | 3 + .../no_leading_spaces_change_ipv6_post_up | 8 + ..._spaces_change_ipv6_post_up.exceptions.txt | 9 + ...change_ipv6_post_up.exceptions.txt.license | 3 + ...no_leading_spaces_change_ipv6_post_up.json | 21 ++ ...ng_spaces_change_ipv6_post_up.json.license | 3 + ...leading_spaces_change_ipv6_post_up.license | 3 + .../no_leading_spaces_change_ipv6_pre_up | 8 + ...g_spaces_change_ipv6_pre_up.exceptions.txt | 9 + ..._change_ipv6_pre_up.exceptions.txt.license | 3 + .../no_leading_spaces_change_ipv6_pre_up.json | 21 ++ ...ing_spaces_change_ipv6_pre_up.json.license | 3 + ..._leading_spaces_change_ipv6_pre_up.license | 3 + .../no_leading_spaces_change_method | 8 + ...eading_spaces_change_method.exceptions.txt | 8 + ...paces_change_method.exceptions.txt.license | 3 + .../no_leading_spaces_change_method.json | 21 ++ ..._leading_spaces_change_method.json.license | 3 + .../no_leading_spaces_change_method.license | 3 + .../golden_output/no_leading_spaces_revert | 7 + .../no_leading_spaces_revert.exceptions.txt | 0 ...ading_spaces_revert.exceptions.txt.license | 3 + .../no_leading_spaces_revert.json | 21 ++ .../no_leading_spaces_revert.json.license | 3 + .../no_leading_spaces_revert.license | 3 + .../no_leading_spaces_set_aggi_and_eth0_mtu | 8 + ...paces_set_aggi_and_eth0_mtu.exceptions.txt | 8 + ...t_aggi_and_eth0_mtu.exceptions.txt.license | 3 + ..._leading_spaces_set_aggi_and_eth0_mtu.json | 21 ++ ..._spaces_set_aggi_and_eth0_mtu.json.license | 3 + ...ading_spaces_set_aggi_and_eth0_mtu.license | 3 + .../no_leading_spaces_set_aggi_slaves | 8 + ...ding_spaces_set_aggi_slaves.exceptions.txt | 8 + ...ces_set_aggi_slaves.exceptions.txt.license | 3 + .../no_leading_spaces_set_aggi_slaves.json | 21 ++ ...eading_spaces_set_aggi_slaves.json.license | 3 + .../no_leading_spaces_set_aggi_slaves.license | 3 + .../input/no_leading_spaces | 8 + .../input/no_leading_spaces.license | 3 + .../interfaces_file/test_interfaces_file.py | 213 +++++++++++++++++- 93 files changed, 995 insertions(+), 63 deletions(-) create mode 100644 changelogs/fragments/6131-fix-interfaces_file-for-no-leading-spaces.yml create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces.test_no_changes create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces.test_no_changes.json create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces.test_no_changes.json.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces.test_no_changes.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_add_aggi_up create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_add_aggi_up.exceptions.txt create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_add_aggi_up.exceptions.txt.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_add_aggi_up.json create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_add_aggi_up.json.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_add_aggi_up.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_add_aggi_up_twice create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_add_aggi_up_twice.exceptions.txt create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_add_aggi_up_twice.exceptions.txt.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_add_aggi_up_twice.json create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_add_aggi_up_twice.json.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_add_aggi_up_twice.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_add_and_delete_aggi_up create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_add_and_delete_aggi_up.exceptions.txt create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_add_and_delete_aggi_up.exceptions.txt.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_add_and_delete_aggi_up.json create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_add_and_delete_aggi_up.json.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_add_and_delete_aggi_up.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_aggi_remove_dup create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_aggi_remove_dup.exceptions.txt create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_aggi_remove_dup.exceptions.txt.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_aggi_remove_dup.json create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_aggi_remove_dup.json.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_aggi_remove_dup.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv4 create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv4.exceptions.txt create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv4.exceptions.txt.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv4.json create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv4.json.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv4.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv4_post_up create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv4_post_up.exceptions.txt create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv4_post_up.exceptions.txt.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv4_post_up.json create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv4_post_up.json.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv4_post_up.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv4_pre_up create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv4_pre_up.exceptions.txt create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv4_pre_up.exceptions.txt.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv4_pre_up.json create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv4_pre_up.json.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv4_pre_up.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv6 create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv6.exceptions.txt create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv6.exceptions.txt.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv6.json create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv6.json.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv6.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv6_post_up create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv6_post_up.exceptions.txt create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv6_post_up.exceptions.txt.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv6_post_up.json create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv6_post_up.json.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv6_post_up.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv6_pre_up create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv6_pre_up.exceptions.txt create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv6_pre_up.exceptions.txt.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv6_pre_up.json create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv6_pre_up.json.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_ipv6_pre_up.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_method create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_method.exceptions.txt create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_method.exceptions.txt.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_method.json create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_method.json.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_change_method.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_revert create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_revert.exceptions.txt create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_revert.exceptions.txt.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_revert.json create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_revert.json.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_revert.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_set_aggi_and_eth0_mtu create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_set_aggi_and_eth0_mtu.exceptions.txt create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_set_aggi_and_eth0_mtu.exceptions.txt.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_set_aggi_and_eth0_mtu.json create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_set_aggi_and_eth0_mtu.json.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_set_aggi_and_eth0_mtu.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_set_aggi_slaves create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_set_aggi_slaves.exceptions.txt create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_set_aggi_slaves.exceptions.txt.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_set_aggi_slaves.json create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_set_aggi_slaves.json.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/golden_output/no_leading_spaces_set_aggi_slaves.license create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/input/no_leading_spaces create mode 100644 tests/unit/plugins/modules/interfaces_file/interfaces_file_fixtures/input/no_leading_spaces.license diff --git a/changelogs/fragments/6131-fix-interfaces_file-for-no-leading-spaces.yml b/changelogs/fragments/6131-fix-interfaces_file-for-no-leading-spaces.yml new file mode 100644 index 0000000000..c975d4e624 --- /dev/null +++ b/changelogs/fragments/6131-fix-interfaces_file-for-no-leading-spaces.yml @@ -0,0 +1,2 @@ +bugfixes: + - interfaces_file - fix reading options in lines not starting with a space (https://github.com/ansible-collections/community.general/issues/6120). diff --git a/plugins/modules/interfaces_file.py b/plugins/modules/interfaces_file.py index 8e643fb797..f19c019f4e 100644 --- a/plugins/modules/interfaces_file.py +++ b/plugins/modules/interfaces_file.py @@ -156,20 +156,22 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.common.text.converters import to_bytes -def line_dict(line): +def lineDict(line): return {'line': line, 'line_type': 'unknown'} -def make_option_dict(line, iface, option, value, address_family): +def optionDict(line, iface, option, value, address_family): return {'line': line, 'iface': iface, 'option': option, 'value': value, 'line_type': 'option', 'address_family': address_family} -def get_option_value(line): - patt = re.compile(r'^\s+(?P