Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions st2api/st2api/controllers/v1/execution_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
# tab of st2web.
SUPPORTED_FILTERS = {
"action": "action.ref",
"pack": "action.pack",
"status": "status",
"liveaction": "liveaction.id",
"parent": "parent",
Expand Down
18 changes: 18 additions & 0 deletions st2api/tests/unit/controllers/v1/test_executions_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,24 @@ def test_query(self):
ids = [item["id"] for item in response.json]
self.assertListEqual(sorted(ids), sorted(refs))

def test_query_by_pack(self):
# All test fixtures use the "executions" pack, so filtering by it should
# return all executions (both chain and local types).
all_refs = list(self.refs.keys())
response = self.app.get("/v1/executions?pack=executions&limit=-1")
self.assertEqual(response.status_int, 200)
self.assertIsInstance(response.json, list)
self.assertGreater(len(response.json), 0)
self.assertEqual(response.headers["X-Total-Count"], str(len(all_refs)))

def test_query_by_pack_no_match(self):
# Filtering by a pack that has no executions should return an empty list.
response = self.app.get("/v1/executions?pack=nonexistent_pack")
self.assertEqual(response.status_int, 200)
self.assertIsInstance(response.json, list)
self.assertEqual(len(response.json), 0)
self.assertEqual(response.headers["X-Total-Count"], "0")

def test_filters(self):
excludes = [
"parent",
Expand Down
6 changes: 6 additions & 0 deletions st2client/st2client/commands/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,10 @@ def __init__(self, resource, *args, **kwargs):

# Filter options
self.group.add_argument("--action", help="Action reference to filter the list.")
self.group.add_argument(
"--pack",
help="Only return executions from the provided pack.",
)
self.group.add_argument(
"--status",
help=(
Expand Down Expand Up @@ -1523,6 +1527,8 @@ def run(self, args, **kwargs):
# Filtering options
if args.action:
kwargs["action"] = args.action
if args.pack:
kwargs["pack"] = args.pack
if args.status:
kwargs["status"] = args.status
if args.user:
Expand Down
1 change: 1 addition & 0 deletions st2common/st2common/models/db/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class ActionExecutionDB(stormbase.StormFoundationDB):
"indexes": [
{"fields": ["rule.ref"]},
{"fields": ["action.ref"]},
{"fields": ["action.pack"]},
{"fields": ["liveaction.id"]},
{"fields": ["start_timestamp"]},
{"fields": ["end_timestamp"]},
Expand Down
4 changes: 4 additions & 0 deletions st2common/st2common/openapi.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,10 @@ paths:
in: query
description: Action ref filter
type: string
- name: pack
in: query
description: Pack name filter
type: string
- name: runner
in: query
description: Runner filter
Expand Down
2 changes: 2 additions & 0 deletions st2tests/st2tests/fixtures/history_views/filters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ default:
- executions.chain
# null is not a valid value for action
- null
pack:
- executions
rule:
- st2.person.joe
# null is a valid value for rule
Expand Down