You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/test/integration/targets/callback-dispatch/callback_plugins/v1_only_methods.py

36 lines
1.2 KiB
Python

from __future__ import annotations
import functools
from ansible.plugins.callback import CallbackBase
class CallbackModule(CallbackBase):
"""Test callback that implements exclusively deprecated v1 callback methods."""
CALLBACK_NEEDS_ENABLED = True
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.called_v1_method_names: set[str] = set()
def callback_impl(self, *args, name: str, **kwargs) -> None:
print(f"hi from callback {name!r} with {args=!r} {kwargs=!r}")
self.called_v1_method_names.add(name)
for v1_method in CallbackBase._v2_v1_method_map.values():
if not v1_method:
continue
locals()[v1_method.__name__] = functools.partialmethod(callback_impl, name=v1_method.__name__)
def playbook_on_stats(self, stats, *args, **kwargs):
if missed_v1_method_calls := (
{'on_any',
'runner_on_ok',
'playbook_on_task_start',
'runner_on_async_ok',
} - self.called_v1_method_names):
assert False, f"The following v1 callback methods were not invoked as expected: {', '.join(missed_v1_method_calls)}"
print("v1 callback test PASS")