Skip to content

Accept yum clean as a valid command #1747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/ansiblelint/rules/CommandsInsteadOfModulesRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class CommandsInsteadOfModulesRule(AnsibleLintRule):
_executable_options = {
'git': ['branch', 'log'],
'systemctl': ['set-default', 'show-environment', 'status'],
'yum': ['clean'],
}

def matchtask(
Expand Down Expand Up @@ -100,7 +101,7 @@ def matchtask(
return False


if "pytest" in sys.modules:
if "pytest" in sys.modules: # noqa: C901
import pytest

from ansiblelint.testing import RunFromText # pylint: disable=ungrouped-imports
Expand Down Expand Up @@ -154,6 +155,20 @@ def matchtask(
command: systemctl set-default multi-user.target
'''

YUM_UPDATE = '''
- hosts: all
tasks:
- name: run yum update
command: yum update
'''

YUM_CLEAN = '''
- hosts: all
tasks:
- name: clear yum cache
command: yum clean all
'''

@pytest.mark.parametrize(
'rule_runner', (CommandsInsteadOfModulesRule,), indirect=['rule_runner']
)
Expand Down Expand Up @@ -209,3 +224,19 @@ def test_systemd_runlevel(rule_runner: RunFromText) -> None:
"""Set-default is not supported by the systemd module."""
results = rule_runner.run_playbook(SYSTEMD_RUNLEVEL)
assert len(results) == 0

@pytest.mark.parametrize(
'rule_runner', (CommandsInsteadOfModulesRule,), indirect=['rule_runner']
)
def test_yum_update(rule_runner: RunFromText) -> None:
"""Using yum update should fail."""
results = rule_runner.run_playbook(YUM_UPDATE)
assert len(results) == 1

@pytest.mark.parametrize(
'rule_runner', (CommandsInsteadOfModulesRule,), indirect=['rule_runner']
)
def test_yum_clean(rule_runner: RunFromText) -> None:
"""The yum module does not support clearing yum cache."""
results = rule_runner.run_playbook(YUM_CLEAN)
assert len(results) == 0