Skip to content

Conversation

@winem
Copy link
Contributor

@winem winem commented Feb 22, 2020

Closes #4828

This PR contains a small fix and does the lookup on the correct key.

Previous implementation returned actions with the name of the provided tag name (value) and not those actions with the specified tag.

@pull-request-size pull-request-size bot added the size/XS PR that changes 0-9 lines. Quick fix/merge. label Feb 22, 2020
@winem
Copy link
Contributor Author

winem commented Feb 22, 2020

I saw that there are no tests for the tag filter.

I will have another look on the tests in the next few days and add them. Will provide the tests in a separate PR if this is merged earlier than that.

@arm4b arm4b added the bug label Feb 23, 2020
@arm4b
Copy link
Member

arm4b commented Feb 23, 2020

@cognifloyd Would be nice to have a second pair of 👀 on verifying this API PR bugfix end2end considering full story in #4828 and more background in #4219.

@winem
Copy link
Contributor Author

winem commented Feb 24, 2020

Here are 4 curls to show the effect of the fix.

  1. the action itself looks like this:
curl -H "X-Auth-Token: xxx" -k https://localhost/api/v1/actions?name=marvel_workflow_demo
[
    {
        "parameters": {
            "environment": {
                "required": true,
                "type": "string"
            },
            "component": {
                "required": true,
                "type": "string"
            },
            "docker_tag": {
                "required": true,
                "type": "string"
            }
        },
        "runner_type": "orquesta",
        "tags": [
            {
                "name": "marvel-project",
                "value": "self-service"
            }
        ],
        "description": "A basic workflow that applies the default workflow for docker image updates.",
        "enabled": true,
        "metadata_file": "actions/marvel_workflow_demo.meta.yaml",
        "entry_point": "workflows/marvel_workflow_demo.yaml",
        "notify": {},
        "output_schema": {},
        "uid": "action:cm_demo_pack:marvel_workflow_demo",
        "pack": "cm_demo_pack",
        "ref": "cm_demo_pack.marvel_workflow_demo",
        "id": "5e4c213b90f52c00e35343ea",
        "name": "marvel_workflow_demo"
    }
]

Without the fix a curl to the API with ?tags=marvel-project did not return any result:

curl -H "X-Auth-Token: xxx" -k https://localhost/api/v1/actions?tags=marvel-project
[]

While a curl with the tag provided tag matching the name of the action did return the action:

curl -H "X-Auth-Token: xxx" -k 'https://localhost/api/v1/actions?tags=marvel_workflow_demo'
[
    {
        "parameters": {
            "environment": {
                "required": true,
                "type": "string"
            },
            "component": {
                "required": true,
                "type": "string"
            },
            "docker_tag": {
                "required": true,
                "type": "string"
            }
        },
        "runner_type": "orquesta",
        "tags": [
            {
                "name": "marvel-project",
                "value": "self-service"
            }
        ],
        "description": "A basic workflow that applies the default workflow for docker image updates.",
        "enabled": true,
        "metadata_file": "actions/marvel_workflow_demo.meta.yaml",
        "entry_point": "workflows/marvel_workflow_demo.yaml",
        "notify": {},
        "output_schema": {},
        "uid": "action:cm_demo_pack:marvel_workflow_demo",
        "pack": "cm_demo_pack",
        "ref": "cm_demo_pack.marvel_workflow_demo",
        "id": "5e4c213b90f52c00e35343ea",
        "name": "marvel_workflow_demo"
    }
]

So, with the fix being applied the query with ?tags=marvel-project returns the expected action:

curl H "X-Auth-Token: fa589af220454453b245d7f80ee2bbaf" -k 'https://localhost/api/v1/actions?tags=marvel-project'
[
    {
        "parameters": {
            "environment": {
                "required": true,
                "type": "string"
            },
            "component": {
                "required": true,
                "type": "string"
            },
            "docker_tag": {
                "required": true,
                "type": "string"
            }
        },
        "runner_type": "orquesta",
        "tags": [
            {
                "name": "marvel-project",
                "value": "self-service"
            }
        ],
        "description": "A basic workflow that applies the default workflow for docker image updates.",
        "enabled": true,
        "metadata_file": "actions/marvel_workflow_demo.meta.yaml",
        "entry_point": "workflows/marvel_workflow_demo.yaml",
        "notify": {},
        "output_schema": {},
        "uid": "action:cm_demo_pack:marvel_workflow_demo",
        "pack": "cm_demo_pack",
        "ref": "cm_demo_pack.marvel_workflow_demo",
        "id": "5e4c213b90f52c00e35343ea",
        "name": "marvel_workflow_demo"
    }
]

@blag blag added this to the 3.2.0 milestone Feb 25, 2020
@blag blag added v3.1.1 and removed v3.1.1 labels Feb 26, 2020
@arm4b arm4b requested a review from nmaludy April 7, 2020 22:02
Copy link
Member

@nmaludy nmaludy left a comment

Choose a reason for hiding this comment

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

Here are my reproduction steps:

Create a new action:

$ cat << EOF > /opt/stackstorm/packs/default/actions/test_tags.yaml
---
description: Action that executes an arbitrary Linux command on the localhost.
enabled: true
entry_point: ''
name: test_tags
tags:
 - name: foo
   value: bar
 - name: blah
   value: junk
parameters:
  cmd:
    description: Arbitrary Linux command to be executed on the local host.
    required: true
    type: string
  sudo:
    immutable: true
runner_type: "local-shell-cmd"
EOF
$ st2 action create /opt/stackstorm/packs/default/actions/test_tags.yaml

Auth and test the API:

$ export ST2_AUTH_TOKEN=$(st2 auth st2admin -p Ch@ngeMe -t)
$ curl -H "X-Auth-Token: $ST2_AUTH_TOKEN" -k https://localhost/api/v1/actions?tags=foo
[]

Apply your fix and test again:

$ sed -i "s/'tags': 'name'/'tags': 'tags.name'/g" /opt/stackstorm/st2/lib/python3.6/site-packages/st2api/controllers/v1/actions.py
$ systemctl restart st2api
$ curl -H "X-Auth-Token: $ST2_AUTH_TOKEN" -k https://localhost/api/v1/actions?tags=foo
[
    {
        "tags": [
            {
                "name": "foo",
                "value": "bar"
            },
            {
                "name": "blah",
                "value": "junk"
            }
        ],
        "uid": "action:default:test_tags",
        "metadata_file": "",
        "name": "test_tags",
        "ref": "default.test_tags",
        "description": "Action that executes an arbitrary Linux command on the localhost.",
        "enabled": true,
        "entry_point": "",
        "pack": "default",
        "runner_type": "local-shell-cmd",
        "parameters": {
            "cmd": {
                "description": "Arbitrary Linux command to be executed on the local host.",
                "required": true,
                "type": "string"
            },
            "sudo": {
                "immutable": true
            }
        },
        "output_schema": {},
        "notify": {},
        "id": "5e8d20a45dfe26b0514e0646"
    }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug size/XS PR that changes 0-9 lines. Quick fix/merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tags filtering is not returning the expected result through the API

5 participants