Skip to content

Commit 8deced3

Browse files
authored
Fix shebangs and file modes and update tests. (ansible#40563)
* Add execute bit sanity test and apply fixes. * Add shebang test for `lib` dirs and apply fixes. * Shebang and execute bit cleanup.
1 parent f84f3de commit 8deced3

39 files changed

+17
-11
lines changed

contrib/inventory/lxd.py

100644100755
File mode changed.

hacking/fix_test_syntax.py

100644100755
File mode changed.

lib/ansible/module_utils/aws/elb_utils.py

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

lib/ansible/module_utils/aws/elbv2.py

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

lib/ansible/module_utils/gitlab.py

100755100644
File mode changed.

lib/ansible/module_utils/manageiq.py

100755100644
File mode changed.

lib/ansible/modules/cloud/amazon/ec2_lc.py

100755100644
File mode changed.

lib/ansible/modules/cloud/azure/azure_rm_loadbalancer.py

100755100644
File mode changed.

lib/ansible/modules/cloud/docker/docker_service.py

100755100644
File mode changed.

lib/ansible/modules/cloud/vmware/vmware_datastore_facts.py

100755100644
File mode changed.

lib/ansible/modules/clustering/k8s/_kubernetes.py

100755100644
File mode changed.

lib/ansible/modules/clustering/znode.py

100755100644
File mode changed.

lib/ansible/modules/network/aci/aci_aep_to_domain.py

100755100644
File mode changed.

lib/ansible/modules/network/aci/aci_contract_subject.py

100755100644
File mode changed.

lib/ansible/modules/network/aci/aci_domain_to_vlan_pool.py

100755100644
File mode changed.

lib/ansible/modules/network/aci/aci_tenant_ep_retention_policy.py

100755100644
File mode changed.

lib/ansible/modules/network/aci/aci_tenant_span_src_group.py

100755100644
File mode changed.

lib/ansible/modules/network/aci/aci_tenant_span_src_group_to_dst_group.py

100755100644
File mode changed.

lib/ansible/modules/network/bigswitch/bcf_switch.py

100755100644
File mode changed.

lib/ansible/modules/network/bigswitch/bigmon_chain.py

100755100644
File mode changed.

lib/ansible/modules/network/panos/panos_sag.py

100755100644
File mode changed.

lib/ansible/modules/network/panos/panos_security_rule.py

100755100644
File mode changed.

lib/ansible/modules/notification/logentries_msg.py

100755100644
File mode changed.

lib/ansible/modules/notification/snow_record.py

100755100644
File mode changed.

lib/ansible/modules/remote_management/hpilo/hpilo_boot.py

100755100644
File mode changed.

lib/ansible/modules/remote_management/hpilo/hpilo_facts.py

100755100644
File mode changed.

lib/ansible/modules/remote_management/manageiq/manageiq_user.py

100755100644
File mode changed.

lib/ansible/modules/source_control/gitlab_deploy_key.py

100755100644
File mode changed.

lib/ansible/modules/source_control/gitlab_hooks.py

100755100644
File mode changed.

lib/ansible/modules/system/interfaces_file.py

100755100644
File mode changed.

lib/ansible/modules/system/service_facts.py

100755100644
File mode changed.

lib/ansible/modules/web_infrastructure/jenkins_job_facts.py

100755100644
File mode changed.

lib/ansible/plugins/inventory/foreman.py

100755100644
File mode changed.

test/runner/lib/cloud/foreman.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
"""Foreman plugin for integration tests."""
32

43
from __future__ import absolute_import, print_function

test/sanity/code-smell/shebang.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22

33
import os
4+
import stat
45
import sys
56

67

@@ -24,7 +25,6 @@ def main():
2425
}
2526

2627
skip = set([
27-
'hacking/cherrypick.py',
2828
'test/integration/targets/win_module_utils/library/legacy_only_new_way_win_line_ending.ps1',
2929
'test/integration/targets/win_module_utils/library/legacy_only_old_way_win_line_ending.ps1',
3030
])
@@ -35,17 +35,27 @@ def main():
3535

3636
with open(path, 'rb') as path_fd:
3737
shebang = path_fd.readline().strip()
38+
mode = os.stat(path).st_mode
39+
executable = (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) & mode
3840

39-
if not shebang:
40-
continue
41+
if not shebang or not shebang.startswith(b'#!'):
42+
if executable:
43+
print('%s:%d:%d: file without shebang should not be executable' % (path, 0, 0))
4144

42-
if not shebang.startswith(b'#!'):
4345
continue
4446

4547
is_module = False
4648

4749
if path.startswith('lib/ansible/modules/'):
4850
is_module = True
51+
elif path.startswith('lib/') or path.startswith('test/runner/lib/'):
52+
if executable:
53+
print('%s:%d:%d: should not be executable' % (path, 0, 0))
54+
55+
if shebang:
56+
print('%s:%d:%d: should not have a shebang' % (path, 0, 0))
57+
58+
continue
4959
elif path.startswith('test/integration/targets/'):
5060
dirname = os.path.dirname(path)
5161

@@ -57,6 +67,9 @@ def main():
5767
is_module = True
5868

5969
if is_module:
70+
if executable:
71+
print('%s:%d:%d: module should not be executable' % (path, 0, 0))
72+
6073
ext = os.path.splitext(path)[1]
6174
expected_shebang = module_shebangs.get(ext)
6275
expected_ext = ' or '.join(['"%s"' % k for k in module_shebangs])

test/sanity/validate-modules/test_validate_modules_regex.py

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

test/units/modules/network/nxos/test_nxos_config.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
#
31
# (c) 2016 Red Hat Inc.
42
#
53
# This file is part of Ansible

test/units/modules/source_control/test_gitlab_deploy_key.py

100755100644
File mode changed.

test/units/modules/source_control/test_gitlab_hooks.py

100755100644
File mode changed.

0 commit comments

Comments
 (0)