From ad94d03ba1a2771e0b7e88e2083a4507a2767862 Mon Sep 17 00:00:00 2001 From: jhawkesworth Date: Thu, 5 Apr 2018 22:13:31 +0100 Subject: [PATCH] Tolerate win line endings on windows module_util load (#37291) * tolerate windows line endings when loading windows module utils. Helpful for old custom windows modules. * add test modules to demonstrate win line ending module load behaviour. * attempt to fix sanity check failures * pep8 fix * explict skip of test modules from shebang check (core modules must still have expected unix style line endings) * switch to rstrip() following core team meeting feedback --- lib/ansible/executor/module_common.py | 2 +- .../legacy_only_new_way_win_line_ending.ps1 | 6 ++++++ .../legacy_only_old_way_win_line_ending.ps1 | 4 ++++ .../targets/win_module_utils/tasks/main.yml | 16 ++++++++++++++++ test/sanity/code-smell/line-endings.py | 2 ++ test/sanity/code-smell/shebang.py | 2 ++ 6 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/integration/targets/win_module_utils/library/legacy_only_new_way_win_line_ending.ps1 create mode 100644 test/integration/targets/win_module_utils/library/legacy_only_old_way_win_line_ending.ps1 diff --git a/lib/ansible/executor/module_common.py b/lib/ansible/executor/module_common.py index 38a58ca2244..009eb06c483 100644 --- a/lib/ansible/executor/module_common.py +++ b/lib/ansible/executor/module_common.py @@ -826,7 +826,7 @@ def _find_module_utils(module_name, b_module_data, module_path, module_args, tas become_required = True for m in set(module_names): - m = to_text(m) + m = to_text(m).rstrip() # tolerate windows line endings mu_path = ps_module_utils_loader.find_plugin(m, ".psm1") if not mu_path: raise AnsibleError('Could not find imported module support code for \'%s\'.' % m) diff --git a/test/integration/targets/win_module_utils/library/legacy_only_new_way_win_line_ending.ps1 b/test/integration/targets/win_module_utils/library/legacy_only_new_way_win_line_ending.ps1 new file mode 100644 index 00000000000..d9c2e008258 --- /dev/null +++ b/test/integration/targets/win_module_utils/library/legacy_only_new_way_win_line_ending.ps1 @@ -0,0 +1,6 @@ +#!powershell + +#Requires -Module Ansible.ModuleUtils.Legacy + +Exit-Json @{ data="success" } + diff --git a/test/integration/targets/win_module_utils/library/legacy_only_old_way_win_line_ending.ps1 b/test/integration/targets/win_module_utils/library/legacy_only_old_way_win_line_ending.ps1 new file mode 100644 index 00000000000..d5d328a5d85 --- /dev/null +++ b/test/integration/targets/win_module_utils/library/legacy_only_old_way_win_line_ending.ps1 @@ -0,0 +1,4 @@ +#!powershell +# POWERSHELL_COMMON + +Exit-Json @{ data="success" } diff --git a/test/integration/targets/win_module_utils/tasks/main.yml b/test/integration/targets/win_module_utils/tasks/main.yml index 4b32cecfff6..8f4ba6f851f 100644 --- a/test/integration/targets/win_module_utils/tasks/main.yml +++ b/test/integration/targets/win_module_utils/tasks/main.yml @@ -14,6 +14,22 @@ that: - new_way.data == 'success' +- name: call old WANTS_JSON module with windows line endings + legacy_only_old_way_win_line_ending: + register: old_way_win + +- assert: + that: + - old_way_win.data == 'success' + +- name: call module with only legacy requires and windows line endings + legacy_only_new_way_win_line_ending: + register: new_way_win + +- assert: + that: + - new_way_win.data == 'success' + - name: call module with local module_utils uses_local_utils: register: local_utils diff --git a/test/sanity/code-smell/line-endings.py b/test/sanity/code-smell/line-endings.py index 1c2631889eb..85b8109e4a4 100755 --- a/test/sanity/code-smell/line-endings.py +++ b/test/sanity/code-smell/line-endings.py @@ -8,6 +8,8 @@ def main(): 'test/integration/targets/template/files/foo.dos.txt', 'test/integration/targets/win_regmerge/templates/win_line_ending.j2', 'test/integration/targets/win_template/files/foo.dos.txt', + 'test/integration/targets/win_module_utils/library/legacy_only_new_way_win_line_ending.ps1', + 'test/integration/targets/win_module_utils/library/legacy_only_old_way_win_line_ending.ps1', ]) for path in sys.argv[1:] or sys.stdin.read().splitlines(): diff --git a/test/sanity/code-smell/shebang.py b/test/sanity/code-smell/shebang.py index b61cd672b2f..bac373bc450 100755 --- a/test/sanity/code-smell/shebang.py +++ b/test/sanity/code-smell/shebang.py @@ -25,6 +25,8 @@ def main(): skip = set([ 'hacking/cherrypick.py', + 'test/integration/targets/win_module_utils/library/legacy_only_new_way_win_line_ending.ps1', + 'test/integration/targets/win_module_utils/library/legacy_only_old_way_win_line_ending.ps1', ]) for path in sys.argv[1:] or sys.stdin.read().splitlines():