summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjhawkesworth <jhawkesworth@users.noreply.github.com>2018-04-05 22:13:31 +0100
committerJordan Borean <jborean93@gmail.com>2018-04-06 07:13:31 +1000
commitad94d03ba1a2771e0b7e88e2083a4507a2767862 (patch)
tree930e899725ed5ea092bdf1ad64464591c7b9f377
parent4e38036bbd3e905c877abbf5b2361a0de1c146a8 (diff)
downloadansible-ad94d03ba1a2771e0b7e88e2083a4507a2767862.tar.gz
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
-rw-r--r--lib/ansible/executor/module_common.py2
-rw-r--r--test/integration/targets/win_module_utils/library/legacy_only_new_way_win_line_ending.ps16
-rw-r--r--test/integration/targets/win_module_utils/library/legacy_only_old_way_win_line_ending.ps14
-rw-r--r--test/integration/targets/win_module_utils/tasks/main.yml16
-rwxr-xr-xtest/sanity/code-smell/line-endings.py2
-rwxr-xr-xtest/sanity/code-smell/shebang.py2
6 files changed, 31 insertions, 1 deletions
diff --git a/lib/ansible/executor/module_common.py b/lib/ansible/executor/module_common.py
index 38a58ca224..009eb06c48 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 0000000000..d9c2e00825
--- /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 0000000000..d5d328a5d8
--- /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 4b32cecfff..8f4ba6f851 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 1c2631889e..85b8109e4a 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 b61cd672b2..bac373bc45 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():