From 3af5728969d547647c60e3b5e665479f0ddcfc1e Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Tue, 10 Jan 2023 06:29:15 +0100 Subject: [PATCH 1/2] Ignore shebangs in files/ and templates/ in collection roles and integration test targets. --- changelogs/fragments/79700-test-shebang.yml | 2 ++ .../ansible_collections/ns/col/roles/foo/files/test.py | 7 +++++++ .../ansible_collections/ns/col/roles/foo/files/test.sh | 7 +++++++ .../ns/col/tests/integration/targets/valid/files/test.py | 7 +++++++ .../ns/col/tests/integration/targets/valid/files/test.sh | 7 +++++++ .../targets/ansible-test-sanity-shebang/files/test.py | 7 +++++++ .../targets/ansible-test-sanity-shebang/files/test.sh | 7 +++++++ .../_util/controller/sanity/code-smell/shebang.py | 7 +++++++ test/sanity/ignore.txt | 9 +++++++++ 9 files changed, 60 insertions(+) create mode 100644 changelogs/fragments/79700-test-shebang.yml create mode 100644 test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/roles/foo/files/test.py create mode 100644 test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/roles/foo/files/test.sh create mode 100644 test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/tests/integration/targets/valid/files/test.py create mode 100644 test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/tests/integration/targets/valid/files/test.sh create mode 100644 test/integration/targets/ansible-test-sanity-shebang/files/test.py create mode 100644 test/integration/targets/ansible-test-sanity-shebang/files/test.sh diff --git a/changelogs/fragments/79700-test-shebang.yml b/changelogs/fragments/79700-test-shebang.yml new file mode 100644 index 00000000000..1ede53e5d65 --- /dev/null +++ b/changelogs/fragments/79700-test-shebang.yml @@ -0,0 +1,2 @@ +minor_changes: + - "ansible-test shebang sanity test - ignore files in ``files/`` and ``templates/`` in collection roles and integration test targets (https://github.com/ansible/ansible/pull/79700)." diff --git a/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/roles/foo/files/test.py b/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/roles/foo/files/test.py new file mode 100644 index 00000000000..5f43ddf2368 --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/roles/foo/files/test.py @@ -0,0 +1,7 @@ +#!/pyth + +# Python file with non-standard shebang. + +# Since it appears in a files/ or templates/ directory inside an integration test, +# the 'shebang' sanity test should ignore it. This "test" is successful when no +# ignore.txt entry is needed for this file. diff --git a/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/roles/foo/files/test.sh b/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/roles/foo/files/test.sh new file mode 100644 index 00000000000..ff302fe9bdd --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/roles/foo/files/test.sh @@ -0,0 +1,7 @@ +#!/bin/foo + +# Shell script with non-standard shebang. + +# Since it appears in a files/ or templates/ directory inside an integration test, +# the 'shebang' sanity test should ignore it. This "test" is successful when no +# ignore.txt entry is needed for this file (inside the collection). diff --git a/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/tests/integration/targets/valid/files/test.py b/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/tests/integration/targets/valid/files/test.py new file mode 100644 index 00000000000..5f43ddf2368 --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/tests/integration/targets/valid/files/test.py @@ -0,0 +1,7 @@ +#!/pyth + +# Python file with non-standard shebang. + +# Since it appears in a files/ or templates/ directory inside an integration test, +# the 'shebang' sanity test should ignore it. This "test" is successful when no +# ignore.txt entry is needed for this file. diff --git a/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/tests/integration/targets/valid/files/test.sh b/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/tests/integration/targets/valid/files/test.sh new file mode 100644 index 00000000000..ff302fe9bdd --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/tests/integration/targets/valid/files/test.sh @@ -0,0 +1,7 @@ +#!/bin/foo + +# Shell script with non-standard shebang. + +# Since it appears in a files/ or templates/ directory inside an integration test, +# the 'shebang' sanity test should ignore it. This "test" is successful when no +# ignore.txt entry is needed for this file (inside the collection). diff --git a/test/integration/targets/ansible-test-sanity-shebang/files/test.py b/test/integration/targets/ansible-test-sanity-shebang/files/test.py new file mode 100644 index 00000000000..5f43ddf2368 --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-shebang/files/test.py @@ -0,0 +1,7 @@ +#!/pyth + +# Python file with non-standard shebang. + +# Since it appears in a files/ or templates/ directory inside an integration test, +# the 'shebang' sanity test should ignore it. This "test" is successful when no +# ignore.txt entry is needed for this file. diff --git a/test/integration/targets/ansible-test-sanity-shebang/files/test.sh b/test/integration/targets/ansible-test-sanity-shebang/files/test.sh new file mode 100644 index 00000000000..98bc38d64df --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-shebang/files/test.sh @@ -0,0 +1,7 @@ +#!/bin/foo + +# Shell script with non-standard shebang. + +# Since it appears in a files/ or templates/ directory inside an integration test, +# the 'shebang' sanity test should ignore it. This "test" is successful when no +# ignore.txt entry is needed for this file. diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/shebang.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/shebang.py index b0b13197839..cf8dc960829 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/shebang.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/shebang.py @@ -60,6 +60,7 @@ def main(): is_module = False is_integration = False + is_role_file = False dirname = os.path.dirname(path) @@ -83,6 +84,10 @@ def main(): print('%s:%d:%d: should not have a shebang' % (path, 0, 0)) continue + elif re.search('^roles/[^/]+/(?:files|templates)/', path): + is_role_file = True + elif re.search('^tests?/integration/targets/[^/]+/(?:files|templates)/', path): + is_role_file = True elif path.startswith('test/integration/targets/') or path.startswith('tests/integration/targets/'): is_integration = True @@ -110,6 +115,8 @@ def main(): print('%s:%d:%d: expected module shebang "%s" but found: %s' % (path, 1, 1, expected_shebang, shebang)) else: print('%s:%d:%d: expected module extension %s but found: %s' % (path, 0, 0, expected_ext, ext)) + elif is_role_file: + continue else: if is_integration: allowed = integration_shebangs diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt index cab676db420..554f2c56c7d 100644 --- a/test/sanity/ignore.txt +++ b/test/sanity/ignore.txt @@ -96,6 +96,15 @@ test/integration/targets/ansible-test-docker/ansible_collections/ns/col/plugins/ test/integration/targets/ansible-test-docker/ansible_collections/ns/col/tests/unit/plugins/modules/test_hello.py pylint:relative-beyond-top-level test/integration/targets/ansible-test-docker/ansible_collections/ns/col/tests/unit/plugins/module_utils/test_my_util.py pylint:relative-beyond-top-level test/integration/targets/ansible-test-no-tty/ansible_collections/ns/col/vendored_pty.py pep8!skip # vendored code +test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/roles/foo/files/test.py shebang +test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/roles/foo/files/test.sh shebang +test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/roles/foo/files/test.sh shellcheck:SC1008 +test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/tests/integration/targets/valid/files/test.py shebang +test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/tests/integration/targets/valid/files/test.sh shebang +test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/tests/integration/targets/valid/files/test.sh shellcheck:SC1008 +test/integration/targets/ansible-test-sanity-shebang/files/test.py shebang +test/integration/targets/ansible-test-sanity-shebang/files/test.sh shebang +test/integration/targets/ansible-test-sanity-shebang/files/test.sh shellcheck:SC1008 test/integration/targets/collections_relative_imports/collection_root/ansible_collections/my_ns/my_col/plugins/modules/my_module.py pylint:relative-beyond-top-level test/integration/targets/collections_relative_imports/collection_root/ansible_collections/my_ns/my_col/plugins/module_utils/my_util2.py pylint:relative-beyond-top-level test/integration/targets/config/lookup_plugins/casting.py pylint:unidiomatic-typecheck From 32bd431b8cd3c91c5d2dd8285777d25c36712cb6 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 13 Feb 2023 21:39:55 +0100 Subject: [PATCH 2/2] Affect only collections, not core. Co-authored-by: Matt Clay --- .../ansible_test/_util/controller/sanity/code-smell/shebang.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/shebang.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/shebang.py index cf8dc960829..75e7acfb26a 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/shebang.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/shebang.py @@ -86,7 +86,7 @@ def main(): continue elif re.search('^roles/[^/]+/(?:files|templates)/', path): is_role_file = True - elif re.search('^tests?/integration/targets/[^/]+/(?:files|templates)/', path): + elif re.search('^tests/integration/targets/[^/]+/(?:files|templates)/', path): is_role_file = True elif path.startswith('test/integration/targets/') or path.startswith('tests/integration/targets/'): is_integration = True