Fix shebangs and file modes and update tests. (#40563)

* Add execute bit sanity test and apply fixes.
* Add shebang test for `lib` dirs and apply fixes.
* Shebang and execute bit cleanup.
pull/40571/head
Matt Clay 6 years ago committed by GitHub
parent f84f3de7c2
commit 8deced3e04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,4 +1,3 @@
#!/usr/bin/env python
# Copyright (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

@ -1,4 +1,3 @@
#!/usr/bin/env python
# Copyright (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

@ -1,4 +1,3 @@
#!/usr/bin/env python
"""Foreman plugin for integration tests."""
from __future__ import absolute_import, print_function

@ -1,6 +1,7 @@
#!/usr/bin/env python
import os
import stat
import sys
@ -24,7 +25,6 @@ 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',
])
@ -35,17 +35,27 @@ def main():
with open(path, 'rb') as path_fd:
shebang = path_fd.readline().strip()
mode = os.stat(path).st_mode
executable = (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) & mode
if not shebang:
continue
if not shebang or not shebang.startswith(b'#!'):
if executable:
print('%s:%d:%d: file without shebang should not be executable' % (path, 0, 0))
if not shebang.startswith(b'#!'):
continue
is_module = False
if path.startswith('lib/ansible/modules/'):
is_module = True
elif path.startswith('lib/') or path.startswith('test/runner/lib/'):
if executable:
print('%s:%d:%d: should not be executable' % (path, 0, 0))
if shebang:
print('%s:%d:%d: should not have a shebang' % (path, 0, 0))
continue
elif path.startswith('test/integration/targets/'):
dirname = os.path.dirname(path)
@ -57,6 +67,9 @@ def main():
is_module = True
if is_module:
if executable:
print('%s:%d:%d: module should not be executable' % (path, 0, 0))
ext = os.path.splitext(path)[1]
expected_shebang = module_shebangs.get(ext)
expected_ext = ' or '.join(['"%s"' % k for k in module_shebangs])

@ -1,5 +1,3 @@
#!/usr/bin/env python
# This is a standalone test for the regex inside validate-modules
# It is not suitable to add to the make tests target because the
# file under test is outside the test's sys.path AND has a hyphen

@ -1,5 +1,3 @@
#!/usr/bin/env python
#
# (c) 2016 Red Hat Inc.
#
# This file is part of Ansible

Loading…
Cancel
Save