Skip to content

Commit

Permalink
fix: [AAP-12264] output job url at run completion (ansible#604)
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Shimkus <[email protected]>
  • Loading branch information
jshimkus-rh authored Nov 29, 2023
1 parent f510d81 commit 68ea91c
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ansible_rulebook/action/run_job_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ async def _post_process(self) -> None:
if "error" in self.controller_job:
a_log["message"] = self.controller_job["error"]
a_log["reason"] = {"error": self.controller_job["error"]}
else:
logger.info(f"job results url: {a_log['url']}")

await self.helper.send_status(a_log)
set_facts = self.action_args.get("set_facts", False)
Expand Down
2 changes: 2 additions & 0 deletions ansible_rulebook/action/run_workflow_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ async def _post_process(self) -> None:
if "error" in self.controller_job:
a_log["message"] = self.controller_job["error"]
a_log["reason"] = {"error": self.controller_job["error"]}
else:
logger.info(f"job results url: {a_log['url']}")

await self.helper.send_status(a_log)
set_facts = self.action_args.get("set_facts", False)
Expand Down
55 changes: 55 additions & 0 deletions tests/unit/action/test_run_job_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def _validate(queue, success, reason=None):

x = set(action.keys()).difference(required_keys)
assert len(x) == 0
return action


JOB_TEMPLATE_ERRORS = [
Expand Down Expand Up @@ -161,6 +162,60 @@ async def test_run_job_template(drools_call, additional_args):
_validate(queue, True)


URL_PARAMETERS = [
(None,),
(10,),
]


@pytest.mark.parametrize("job_id", URL_PARAMETERS)
@pytest.mark.asyncio
async def test_run_job_template_url(job_id):
queue = asyncio.Queue()
metadata = Metadata(
rule="r1",
rule_set="rs1",
rule_uuid="u1",
rule_set_uuid="u2",
rule_run_at="abc",
)
control = Control(
queue=queue,
inventory="abc",
hosts=["all"],
variables={"a": 1},
project_data_file="",
)
action_args = {
"name": "fred",
"organization": "Default",
"retries": 0,
"retry": True,
"delay": 0,
}
controller_job = {
"status": "success",
"rc": 0,
"artifacts": dict(b=1),
"created": "abc",
}
if job_id is not None:
controller_job["id"] = job_id

with patch(
"ansible_rulebook.action.run_job_template."
"job_template_runner.run_job_template",
return_value=controller_job,
):
await RunJobTemplate(metadata, control, **action_args)()

action = _validate(queue, True)

assert ((not job_id) and (action["url"] == "")) or (
job_id and (action["url"] != "")
)


@pytest.mark.asyncio
async def test_run_job_template_retries():
queue = asyncio.Queue()
Expand Down
55 changes: 55 additions & 0 deletions tests/unit/action/test_run_workflow_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def _validate(queue, success, reason=None):

x = set(action.keys()).difference(required_keys)
assert len(x) == 0
return action


WORKFLOW_TEMPLATE_ERRORS = [
Expand Down Expand Up @@ -218,3 +219,57 @@ async def test_run_workflow_template_retries():
drools_mock.assert_called_once()

_validate(queue, True)


URL_PARAMETERS = [
(None,),
(10,),
]


@pytest.mark.parametrize("job_id", URL_PARAMETERS)
@pytest.mark.asyncio
async def test_run_workflow_template_url(job_id):
queue = asyncio.Queue()
metadata = Metadata(
rule="r1",
rule_set="rs1",
rule_uuid="u1",
rule_set_uuid="u2",
rule_run_at="abc",
)
control = Control(
queue=queue,
inventory="abc",
hosts=["all"],
variables={"a": 1},
project_data_file="",
)
action_args = {
"name": "fred",
"organization": "Default",
"retries": 0,
"retry": True,
"delay": 0,
}
controller_job = {
"status": "success",
"rc": 0,
"artifacts": dict(b=1),
"created": "abc",
}
if job_id is not None:
controller_job["id"] = job_id

with patch(
"ansible_rulebook.action.run_workflow_template."
"job_template_runner.run_workflow_job_template",
return_value=controller_job,
):
await RunWorkflowTemplate(metadata, control, **action_args)()

action = _validate(queue, True)

assert ((not job_id) and (action["url"] == "")) or (
job_id and (action["url"] != "")
)

0 comments on commit 68ea91c

Please sign in to comment.