mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-22 05:09:12 +00:00
Remove redundant callback hooks
v2_runner_on_starts gets called by ansible right after the strategy has called on_task_start or on_handler_start. So there is no need to keep this code as the minimum ansible-core version is guaranteed to have this function. on_cleanup (removed around ansible-core 2.0) and on_no_hosts (removed around ansible-core 2.5) never get called.
This commit is contained in:
parent
855beecd82
commit
81873ea059
2 changed files with 12 additions and 43 deletions
|
|
@ -185,7 +185,7 @@ class TaskData:
|
|||
# concatenate task include output from multiple items
|
||||
host.result = f"{self.host_data[host.uuid].result}\n{host.result}"
|
||||
else:
|
||||
self.host_data[host.uuid].update(host)
|
||||
self.host_data[host.uuid].update(host.status, host.result)
|
||||
return
|
||||
|
||||
self.host_data[host.uuid] = host
|
||||
|
|
@ -196,20 +196,18 @@ class HostData:
|
|||
Data about an individual host.
|
||||
"""
|
||||
|
||||
def __init__(self, uuid, name, status, result, start=None):
|
||||
def __init__(self, uuid, name, status, result):
|
||||
self.uuid = uuid
|
||||
self.name = name
|
||||
self.status = status
|
||||
self.result = result
|
||||
self.finish = time_ns()
|
||||
self.start = start
|
||||
self.finish = None
|
||||
self.start = time_ns()
|
||||
|
||||
def update(self, host):
|
||||
self.status = host.status
|
||||
self.result = host.result
|
||||
self.finish = host.finish
|
||||
if host.start is not None:
|
||||
self.start = host.start
|
||||
def update(self, status, result):
|
||||
self.status = status
|
||||
self.result = result
|
||||
self.finish = time_ns()
|
||||
|
||||
|
||||
class OpenTelemetrySource:
|
||||
|
|
@ -230,17 +228,14 @@ class OpenTelemetrySource:
|
|||
carrier["traceparent"] = traceparent
|
||||
return TraceContextTextMapPropagator().extract(carrier=carrier)
|
||||
|
||||
def start_task(self, tasks_data, hide_task_arguments, play_name, task, host=None):
|
||||
def start_task(self, tasks_data, hide_task_arguments, play_name, task, host):
|
||||
"""record the start of a task for one or more hosts"""
|
||||
|
||||
uuid = task._uuid
|
||||
|
||||
if uuid in tasks_data:
|
||||
if host:
|
||||
tasks_data[uuid].add_host(HostData(host._uuid, host.name, "started", None, time_ns()))
|
||||
return
|
||||
else:
|
||||
return
|
||||
tasks_data[uuid].add_host(HostData(host._uuid, host.name, "started", None))
|
||||
return
|
||||
|
||||
name = task.get_name().strip()
|
||||
path = task.get_path()
|
||||
|
|
@ -251,8 +246,7 @@ class OpenTelemetrySource:
|
|||
args = task.args
|
||||
|
||||
tasks_data[uuid] = TaskData(uuid, name, path, play_name, action, args)
|
||||
if host:
|
||||
tasks_data[uuid].add_host(HostData(host._uuid, host.name, "started", None, time_ns()))
|
||||
tasks_data[uuid].add_host(HostData(host._uuid, host.name, "started", None))
|
||||
|
||||
def finish_task(self, tasks_data, status, result, dump):
|
||||
"""record the results of a task for a single host"""
|
||||
|
|
@ -575,21 +569,9 @@ class CallbackModule(CallbackBase):
|
|||
def v2_playbook_on_play_start(self, play):
|
||||
self.play_name = play.get_name()
|
||||
|
||||
def v2_runner_on_no_hosts(self, task):
|
||||
self.opentelemetry.start_task(self.tasks_data, self.hide_task_arguments, self.play_name, task)
|
||||
|
||||
def v2_playbook_on_task_start(self, task, is_conditional):
|
||||
self.opentelemetry.start_task(self.tasks_data, self.hide_task_arguments, self.play_name, task)
|
||||
|
||||
def v2_runner_on_start(self, host, task):
|
||||
self.opentelemetry.start_task(self.tasks_data, self.hide_task_arguments, self.play_name, task, host)
|
||||
|
||||
def v2_playbook_on_cleanup_task_start(self, task):
|
||||
self.opentelemetry.start_task(self.tasks_data, self.hide_task_arguments, self.play_name, task)
|
||||
|
||||
def v2_playbook_on_handler_task_start(self, task):
|
||||
self.opentelemetry.start_task(self.tasks_data, self.hide_task_arguments, self.play_name, task)
|
||||
|
||||
def v2_runner_on_failed(self, result, ignore_errors=False):
|
||||
if ignore_errors:
|
||||
status = "ignored"
|
||||
|
|
|
|||
|
|
@ -37,19 +37,6 @@ class TestOpentelemetry(unittest.TestCase):
|
|||
host=self.mock_host, task=self.mock_task, return_data={}, task_fields=self.task_fields
|
||||
)
|
||||
|
||||
def test_start_task(self):
|
||||
tasks_data = OrderedDict()
|
||||
|
||||
self.opentelemetry.start_task(tasks_data, False, "myplay", self.mock_task)
|
||||
|
||||
task_data = tasks_data["myuuid"]
|
||||
self.assertEqual(task_data.uuid, "myuuid")
|
||||
self.assertEqual(task_data.name, "mytask")
|
||||
self.assertEqual(task_data.path, "/mypath")
|
||||
self.assertEqual(task_data.play, "myplay")
|
||||
self.assertEqual(task_data.action, "myaction")
|
||||
self.assertEqual(task_data.args, {})
|
||||
|
||||
def test_run_task_with_host(self):
|
||||
tasks_data = OrderedDict()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue