Skip to content

Commit

Permalink
Handle a runner message without an event (#226)
Browse files Browse the repository at this point in the history
Handle a runner message without an event

Reviewed-by: https://github.com/apps/ansible-zuul
  • Loading branch information
cidrblock authored May 10, 2021
1 parent 4c369c0 commit ce13910
Showing 1 changed file with 54 additions and 49 deletions.
103 changes: 54 additions & 49 deletions ansible_navigator/actions/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,60 +553,65 @@ def _dequeue(self) -> None:

def _handle_message(self, message: dict) -> None:
# pylint: disable=too-many-branches
# pylint: disable=too-many-nested-blocks
"""Handle a runner message
:param message: The message from runner
:type message: dict
"""
event = message["event"]

if "stdout" in message and message["stdout"]:
self.stdout.extend(message["stdout"].splitlines())

if event in ["verbose", "error"]:
if "ERROR!" in message["stdout"]:
self._msg_from_plays = ("ERROR", 9)
elif "WARNING" in message["stdout"]:
self._msg_from_plays = ("WARNINGS", 13)

if event == "playbook_on_play_start":
play = message["event_data"]
play["__play_name"] = play["name"]
play["tasks"] = []
self._plays.value.append(play)

if event.startswith("runner_on_"):
runner_event = event.split("_")[2]
task = message["event_data"]
play_id = next(
idx for idx, p in enumerate(self._plays.value) if p["uuid"] == task["play_uuid"]
)
if runner_event in ["ok", "skipped", "unreachable", "failed"]:
if runner_event == "failed" and task["ignore_errors"]:
result = "ignored"
else:
result = runner_event
task["__result"] = result.upper()
task["__changed"] = task.get("res", {}).get("changed", False)
task["__duration"] = human_time(seconds=round(task["duration"], 2))
task_id = None
for idx, play_task in enumerate(self._plays.value[play_id]["tasks"]):
if task["task_uuid"] == play_task["task_uuid"]:
if task["host"] == play_task["host"]:
task_id = idx
break
if task_id is not None:
self._plays.value[play_id]["tasks"][task_id].update(task)

elif runner_event == "start":
task["__host"] = task["host"]
task["__result"] = "IN_PROGRESS"
task["__changed"] = "unknown"
task["__duration"] = None
task["__number"] = len(self._plays.value[play_id]["tasks"])
task["__task"] = task["task"]
task["__task_action"] = task["task_action"]
self._plays.value[play_id]["tasks"].append(task)
try:
event = message["event"]
except KeyError:
error = f"Unhandled message from runner queue, discarded: {message}"
self._logger.critical(error)
else:
if "stdout" in message and message["stdout"]:
self.stdout.extend(message["stdout"].splitlines())

if event in ["verbose", "error"]:
if "ERROR!" in message["stdout"]:
self._msg_from_plays = ("ERROR", 9)
elif "WARNING" in message["stdout"]:
self._msg_from_plays = ("WARNINGS", 13)

if event == "playbook_on_play_start":
play = message["event_data"]
play["__play_name"] = play["name"]
play["tasks"] = []
self._plays.value.append(play)

if event.startswith("runner_on_"):
runner_event = event.split("_")[2]
task = message["event_data"]
play_id = next(
idx for idx, p in enumerate(self._plays.value) if p["uuid"] == task["play_uuid"]
)
if runner_event in ["ok", "skipped", "unreachable", "failed"]:
if runner_event == "failed" and task["ignore_errors"]:
result = "ignored"
else:
result = runner_event
task["__result"] = result.upper()
task["__changed"] = task.get("res", {}).get("changed", False)
task["__duration"] = human_time(seconds=round(task["duration"], 2))
task_id = None
for idx, play_task in enumerate(self._plays.value[play_id]["tasks"]):
if task["task_uuid"] == play_task["task_uuid"]:
if task["host"] == play_task["host"]:
task_id = idx
break
if task_id is not None:
self._plays.value[play_id]["tasks"][task_id].update(task)

elif runner_event == "start":
task["__host"] = task["host"]
task["__result"] = "IN_PROGRESS"
task["__changed"] = "unknown"
task["__duration"] = None
task["__number"] = len(self._plays.value[play_id]["tasks"])
task["__task"] = task["task"]
task["__task_action"] = task["task_action"]
self._plays.value[play_id]["tasks"].append(task)

def _play_stats(self) -> None:
"""Calculate the play's stats based
Expand Down

0 comments on commit ce13910

Please sign in to comment.