Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add output schemas for runners that just have a generic response #6102

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ in development
Fixed
~~~~~

Added
~~~~~
* add a schema to shell and winrm runners to allow validations to be executed againt their payloads. This means that shell or winrm jobs
that return a json object will be parsed into a dict to allow for field validations to be performed. Non json string resonses are still
handled as normal #6102

3.8.1 - December 13, 2023
-------------------------
Fixed
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ black: requirements .black-check
echo "==========================================================="; \
echo "Running black on" $$component; \
echo "==========================================================="; \
. $(VIRTUALENV_DIR)/bin/activate ; black --check --config pyproject.toml $$component/ || exit 1; \
. $(VIRTUALENV_DIR)/bin/activate ; black --diff --check --config pyproject.toml $$component/ || exit 1; \
if [ -d "$$component/bin" ]; then \
. $(VIRTUALENV_DIR)/bin/activate ; black $$(grep -rl '^#!/.*python' $$component/bin) || exit 1; \
fi \
Expand All @@ -387,7 +387,7 @@ black: requirements .black-check
echo "==========================================================="; \
echo "Running black on" $$component; \
echo "==========================================================="; \
. $(VIRTUALENV_DIR)/bin/activate ; black --check --config pyproject.toml $$component/ || exit 1; \
. $(VIRTUALENV_DIR)/bin/activate ; black --diff --check --config pyproject.toml $$component/ || exit 1; \
if [ -d "$$component/bin" ]; then \
. $(VIRTUALENV_DIR)/bin/activate ; black $$(grep -rl '^#!/.*python' $$component/bin) || exit 1; \
fi \
Expand Down
36 changes: 36 additions & 0 deletions contrib/runners/local_runner/local_runner/runner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@
description: Action timeout in seconds. Action will get killed if it doesn't
finish in timeout seconds.
type: integer
output_key: stdout
output_schema:
type: object
properties:
succeeded:
type: boolean
failed:
type: boolean
stdout:
anyOf:
- type: "object"
- type: "string"
- type: "array"
- type: "number"
Comment on lines +44 to +49
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be any of the simple json types? Why these 4?
https://github.com/StackStorm/st2/blob/master/st2common/st2common/util/schema/action_params.json#L19

I guess we need to look at how stdout is converted from json to see if there are any restrictions.

stderr:
type: string
return_code:
type: integer
- description: A runner to execute local actions as a fixed user.
enabled: true
name: local-shell-script
Expand Down Expand Up @@ -74,3 +92,21 @@
description: Action timeout in seconds. Action will get killed if it doesn't
finish in timeout seconds.
type: integer
output_key: stdout
output_schema:
type: object
properties:
succeeded:
type: boolean
failed:
type: boolean
stdout:
anyOf:
- type: "object"
- type: "string"
- type: "array"
- type: "number"
stderr:
type: string
return_code:
type: integer
2 changes: 1 addition & 1 deletion contrib/runners/orquesta_runner/tests/unit/test_rerun.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
)
RUNNER_RESULT_SUCCEEDED = (
action_constants.LIVEACTION_STATUS_SUCCEEDED,
{"stdout": "foobar"},
{"stdout": "foobar", "succeeded": True, "failed": False, "stderr": ""},
{},
)

Expand Down
4 changes: 2 additions & 2 deletions contrib/runners/orquesta_runner/tests/unit/test_with_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@

RUNNER_RESULT_RUNNING = (
action_constants.LIVEACTION_STATUS_RUNNING,
{"stdout": "..."},
{"stdout": "...", "stderr": ""},
{},
)

RUNNER_RESULT_SUCCEEDED = (
action_constants.LIVEACTION_STATUS_SUCCEEDED,
{"stdout": "..."},
{"stdout": "...", "stderr": "", "succeeded": True, "failed": False},
{},
)

Expand Down
36 changes: 36 additions & 0 deletions contrib/runners/remote_runner/remote_runner/runner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@
config is used.
required: false
type: string
output_key: stdout
output_schema:
type: object
properties:
succeeded:
type: boolean
failed:
type: boolean
stdout:
anyOf:
- type: "object"
- type: "string"
- type: "array"
- type: "number"
stderr:
type: string
return_code:
type: integer
- description: A remote execution runner that executes actions as a fixed system user.
enabled: true
name: remote-shell-script
Expand Down Expand Up @@ -162,3 +180,21 @@
config is used.
required: false
type: string
output_key: stdout
output_schema:
type: object
properties:
succeeded:
type: boolean
failed:
type: boolean
stdout:
anyOf:
- type: "object"
- type: "string"
- type: "array"
- type: "number"
stderr:
type: string
return_code:
type: integer
54 changes: 54 additions & 0 deletions contrib/runners/winrm_runner/winrm_runner/runner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@
CA bundle which comes from Mozilla. Verification using a custom CA bundle
is not yet supported. Set to False to skip verification.
type: boolean
output_key: stdout
output_schema:
type: object
properties:
succeeded:
type: boolean
failed:
type: boolean
stdout:
anyOf:
- type: "object"
- type: "string"
- type: "array"
- type: "number"
stderr:
type: string
return_code:
type: integer
- description: A remote execution runner that executes PowerShell commands via WinRM on a remote host
enabled: true
name: winrm-ps-cmd
Expand Down Expand Up @@ -134,6 +152,24 @@
CA bundle which comes from Mozilla. Verification using a custom CA bundle
is not yet supported. Set to False to skip verification.
type: boolean
output_key: stdout
output_schema:
type: object
properties:
succeeded:
type: boolean
failed:
type: boolean
stdout:
anyOf:
- type: "object"
- type: "string"
- type: "array"
- type: "number"
stderr:
type: string
return_code:
type: integer
- description: A remote execution runner that executes PowerShell script via WinRM on a set of remote hosts
enabled: true
name: winrm-ps-script
Expand Down Expand Up @@ -199,3 +235,21 @@
CA bundle which comes from Mozilla. Verification using a custom CA bundle
is not yet supported. Set to False to skip verification.
type: boolean
output_key: stdout
output_schema:
type: object
properties:
succeeded:
type: boolean
failed:
type: boolean
stdout:
anyOf:
- type: "object"
- type: "string"
- type: "array"
- type: "number"
stderr:
type: string
return_code:
type: integer
37 changes: 37 additions & 0 deletions st2actions/tests/unit/test_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,43 @@ def test_apply(self):
FakeConcurrencyApplicator.apply_after.assert_called_once_with(liveaction)
RaiseExceptionApplicator.apply_after.assert_called_once_with(liveaction)

@mock.patch.object(
FakeConcurrencyApplicator,
"apply_before",
mock.MagicMock(
side_effect=FakeConcurrencyApplicator(None, None, threshold=3).apply_before
),
)
@mock.patch.object(
RaiseExceptionApplicator,
"apply_before",
mock.MagicMock(side_effect=RaiseExceptionApplicator(None, None).apply_before),
)
@mock.patch.object(
FakeConcurrencyApplicator,
"apply_after",
mock.MagicMock(
side_effect=FakeConcurrencyApplicator(None, None, threshold=3).apply_after
),
)
@mock.patch.object(
RaiseExceptionApplicator,
"apply_after",
mock.MagicMock(side_effect=RaiseExceptionApplicator(None, None).apply_after),
)
def test_apply_with_dict(self):
liveaction = LiveActionDB(
action="wolfpack.action-1", parameters={"actionstr": "dict_resp"}
)
liveaction, _ = action_service.request(liveaction)
liveaction = self._wait_on_status(
liveaction, action_constants.LIVEACTION_STATUS_SUCCEEDED
)
FakeConcurrencyApplicator.apply_before.assert_called_once_with(liveaction)
RaiseExceptionApplicator.apply_before.assert_called_once_with(liveaction)
FakeConcurrencyApplicator.apply_after.assert_called_once_with(liveaction)
RaiseExceptionApplicator.apply_after.assert_called_once_with(liveaction)

@mock.patch.object(
FakeConcurrencyApplicator, "get_threshold", mock.MagicMock(return_value=0)
)
Expand Down
Loading
Loading