pull/86251/merge
Abhijeet Kasurde 16 hours ago committed by GitHub
commit 1ecbd0f58b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,3 @@
---
minor_changes:
- ansible-test - add a rule for os.system call (https://github.com/ansible/ansible/issues/86250).

@ -60,6 +60,7 @@ REJECTLIST_IMPORTS = {
} }
SUBPROCESS_REGEX = re.compile(r'subprocess\.Po.*') SUBPROCESS_REGEX = re.compile(r'subprocess\.Po.*')
OS_CALL_REGEX = re.compile(r'os\.call.*') OS_CALL_REGEX = re.compile(r'os\.call.*')
OS_SYSTEM_REGEX = re.compile(r'os\.system.*')
PLUGINS_WITH_RETURN_VALUES = ('module', ) PLUGINS_WITH_RETURN_VALUES = ('module', )

@ -93,6 +93,7 @@ from .constants import (
REJECTLIST_IMPORTS, REJECTLIST_IMPORTS,
SUBPROCESS_REGEX, SUBPROCESS_REGEX,
OS_CALL_REGEX, OS_CALL_REGEX,
OS_SYSTEM_REGEX,
PLUGINS_WITH_RETURN_VALUES, PLUGINS_WITH_RETURN_VALUES,
PLUGINS_WITH_EXAMPLES, PLUGINS_WITH_EXAMPLES,
PLUGINS_WITH_YAML_EXAMPLES, PLUGINS_WITH_YAML_EXAMPLES,
@ -483,6 +484,19 @@ class ModuleValidator(Validator):
column=(os_call_match.span()[0] + 1) column=(os_call_match.span()[0] + 1)
) )
def _check_for_os_system(self):
if 'os.system' in self.text:
for line_no, line in enumerate(self.text.splitlines()):
os_system_match = OS_SYSTEM_REGEX.search(line)
if os_system_match:
self.reporter.error(
path=self.object_path,
code='use-run-command-not-os-system',
msg=('os.system() call found. Should be module.run_command'),
line=(line_no + 1),
column=(os_system_match.span()[0] + 1)
)
def _find_rejectlist_imports(self): def _find_rejectlist_imports(self):
for child in self.ast.body: for child in self.ast.body:
names = [] names = []
@ -2448,6 +2462,7 @@ class ModuleValidator(Validator):
if self.plugin_type == 'module': if self.plugin_type == 'module':
self._check_for_subprocess() self._check_for_subprocess()
self._check_for_os_call() self._check_for_os_call()
self._check_for_os_system()
if self._powershell_module(): if self._powershell_module():
self._validate_ps_replacers() self._validate_ps_replacers()

Loading…
Cancel
Save