Skip to content
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

Revert notify related checks, errors, transforms for listen and tests #4205

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Revert notify related checks, errors, transforms for listen and tests
  • Loading branch information
audgirka authored and ssbarnea committed Jun 4, 2024
commit 8d94ca495d7229ff07c8542a5027c6801d27afb4
2 changes: 1 addition & 1 deletion examples/playbooks/become.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
become: true
become_user: nobody
notify:
- Restart apache2
- restart apache2
34 changes: 0 additions & 34 deletions examples/playbooks/name_case_notify_fail.yml

This file was deleted.

54 changes: 10 additions & 44 deletions src/ansiblelint/rules/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,6 @@ def matchtask(
),
)

notify = task.get("notify")
if notify:
if isinstance(notify, str):
notify = [notify]

results.extend(
[
self.create_matcherror(
message=f"Task notify '{handler}' should start with an uppercase letter.",
lineno=task[LINE_NUMBER_KEY],
tag="name[casing]",
filename=file,
)
for handler in notify
if check_handler_case(handler)
],
)
return results

def _prefix_check(
Expand Down Expand Up @@ -268,27 +251,10 @@ def update_task_name(task_name: str) -> str:
if orig_task_name == task["notify"][idx]:
task["notify"][idx] = updated_task_name

if isinstance(item, dict) and "handlers" in item:
for task in item["handlers"]:
listener_task_name = task.get("listen", None)
if (
listener_task_name
and listener_task_name == orig_task_name
):
task["listen"] = updated_task_name

target_task["name"] = updated_task_name
match.fixed = True


def check_handler_case(handler: str) -> bool:
"""Check the casing of a handler."""
# Handlers may be prefixed with "role_name : " to indicate a handler from a specific role
# Strip this before checking
handler = handler.split(" : ", 1)[-1]
return handler[0].isalpha() and handler[0].islower() and not handler[0].isupper()


if "pytest" in sys.modules:
from ansiblelint.rules import RulesCollection
from ansiblelint.runner import Runner
Expand Down Expand Up @@ -381,16 +347,16 @@ def test_rule_name_lowercase() -> None:
assert errs[0].tag == "name[casing]"
assert errs[0].rule.id == "name"

def test_rule_notify_lowercase() -> None:
"""Negative test for a task notify that starts with lowercase."""
collection = RulesCollection()
collection.register(NameRule())
failure = "examples/playbooks/name_case_notify_fail.yml"
bad_runner = Runner(failure, rules=collection)
errs = bad_runner.run()
assert len(errs) == 5
assert all(err.tag == "name[casing]" for err in errs)
assert all(err.rule.id == "name" for err in errs)
# def test_rule_notify_lowercase() -> None:
# """Negative test for a task notify that starts with lowercase."""
# collection = RulesCollection()
# collection.register(NameRule())
# failure = "examples/playbooks/name_case_notify_fail.yml"
# bad_runner = Runner(failure, rules=collection)
# errs = bad_runner.run()
# assert len(errs) == 5
# assert all(err.tag == "name[casing]" for err in errs)
# assert all(err.rule.id == "name" for err in errs)

def test_name_play() -> None:
"""Positive test for name[play]."""
Expand Down
2 changes: 1 addition & 1 deletion test/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def fixture_runner_result(
id="strings",
),
pytest.param("examples/playbooks/vars/empty.yml", 1, False, True, id="empty"),
pytest.param("examples/playbooks/name-case.yml", 6, True, True, id="name_case"),
# pytest.param("examples/playbooks/name-case.yml", 6, True, True, id="name_case"),
pytest.param("examples/playbooks/fqcn.yml", 3, True, True, id="fqcn"),
pytest.param(
"examples/playbooks/multi_yaml_doc.yml",
Expand Down