diff --git a/ansible_rulebook/action/run_job_template.py b/ansible_rulebook/action/run_job_template.py index 3270743f..6b75d03b 100644 --- a/ansible_rulebook/action/run_job_template.py +++ b/ansible_rulebook/action/run_job_template.py @@ -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) diff --git a/ansible_rulebook/action/run_workflow_template.py b/ansible_rulebook/action/run_workflow_template.py index ada2f39d..289b2019 100644 --- a/ansible_rulebook/action/run_workflow_template.py +++ b/ansible_rulebook/action/run_workflow_template.py @@ -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) diff --git a/tests/unit/action/test_run_job_template.py b/tests/unit/action/test_run_job_template.py index 8646729e..19da3492 100644 --- a/tests/unit/action/test_run_job_template.py +++ b/tests/unit/action/test_run_job_template.py @@ -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 = [ @@ -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() diff --git a/tests/unit/action/test_run_workflow_template.py b/tests/unit/action/test_run_workflow_template.py index c780fe17..fcd14a33 100644 --- a/tests/unit/action/test_run_workflow_template.py +++ b/tests/unit/action/test_run_workflow_template.py @@ -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 = [ @@ -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"] != "") + )