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

ST2 3.0 Pack Install Fails if pack.yaml specifies only python3 #4654

Closed
punkrokk opened this issue Apr 30, 2019 · 15 comments · Fixed by #4662
Closed

ST2 3.0 Pack Install Fails if pack.yaml specifies only python3 #4654

punkrokk opened this issue Apr 30, 2019 · 15 comments · Fixed by #4662
Assignees
Milestone

Comments

@punkrokk
Copy link
Member

punkrokk commented Apr 30, 2019

SUMMARY

ST2 3.0 Pack Install Fails if pack.yaml specifies only python3

My assessment it that logic is missing to allow just --python3 to be declared in pack.yaml
In addition - it appears I could successfully install a pack into a py2 venv, but the code actually requires py3.

ISSUE TYPE
  • Bug Report
STACKSTORM VERSION

st2 3.0.0, on Python 2.7.5

OS / ENVIRONMENT / INSTALL METHOD

vagrant, st2 3.0 EWC, Centos 7.6 w/python3.6

STEPS TO REPRODUCE
  • install ST2, and optionally EWC
  • try and install a pack where the pack.yaml specifies only python3
---
name: somepack
ref: stillsomepack
description: Some Pack Description
version: 0.1.2
author : Some author
email : email@somedomain.com
python_versions:
  - "3"
  • Run st2 --debug pack install file:///$PWD --python3 or st2 --debug pack install file:///$PWD` or an appropriate st2 pack install command with the above yaml file
EXPECTED RESULTS

A successful pack install for python3 actions

ACTUAL RESULTS
 st2 --debug pack install file:///$PWD --python3
2019-04-30 18:04:21,305  DEBUG - Using cached token from file "/home/vagrant/.st2/token-st2admin"
# -------- begin 140386129926288 request ----------
curl -X POST -H  'Connection: keep-alive' -H  'Accept-Encoding: gzip, deflate' -H  'Accept: */*' -H  'User-Agent: python-requests/2.14.2' -H  'content-type: application/json' -H  'X-Auth-Token: fee4a8dba3ba4167a5e4367338dba390' -H  'Content-Length: 92' --data-binary '{"force": false, "python3": true, "packs": ["file:////opt/stackstorm/pack_dev/sentinelone"]}' http://127.0.0.1:9101/v1/packs/install
# -------- begin 140386129926288 response ----------
{
    "execution_id": "5cc88e25a08f81188b2ded97"
}
# -------- end 140386129926288 response ------------


        [  failed   ] download pack

# -------- begin 140386129926032 request ----------
curl -X GET -H  'Connection: keep-alive' -H  'Accept-Encoding: gzip, deflate' -H  'Accept: */*' -H  'User-Agent: python-requests/2.14.2' -H  'X-Auth-Token: fee4a8dba3ba4167a5e4367338dba390' 'http://127.0.0.1:9101/v1/executions/5cc88e25a08f81188b2ded97/children/?depth=1'
# -------- begin 140386129926032 response ----------
[
    {
        "status": "failed",
        "start_timestamp": "2019-04-30T18:04:21.615205Z",
        "log": [
            {
                "status": "requested",
                "timestamp": "2019-04-30T18:04:21.000000Z"
            },
            {
                "status": "scheduled",
                "timestamp": "2019-04-30T18:04:21.000000Z"
            },
            {
                "status": "running",
                "timestamp": "2019-04-30T18:04:21.000000Z"
            },
            {
                "status": "failed",
                "timestamp": "2019-04-30T18:04:23.000000Z"
            }
        ],
        "parameters": {
            "force": false,
            "packs": [
                "file:////opt/stackstorm/pack_dev/sentinelone"
            ]
        },
        "runner": {
            "runner_module": "python_runner",
            "uid": "runner_type:python-script",
            "runner_package": "python_runner",
            "description": "A runner for launching python actions.",
            "enabled": true,
            "output_key": "result",
            "output_schema": {
                "result": {
                    "anyOf": [
                        {
                            "type": "object"
                        },
                        {
                            "type": "string"
                        },
                        {
                            "type": "integer"
                        },
                        {
                            "type": "number"
                        },
                        {
                            "type": "boolean"
                        },
                        {
                            "type": "array"
                        },
                        {
                            "type": "null"
                        }
                    ]
                },
                "exit_code": {
                    "required": true,
                    "type": "integer"
                },
                "stderr": {
                    "required": true,
                    "type": "string"
                },
                "stdout": {
                    "required": true,
                    "type": "string"
                }
            },
            "runner_parameters": {
                "debug": {
                    "default": false,
                    "required": false,
                    "type": "boolean",
                    "description": "Enable runner debug mode."
                },
                "content_version": {
                    "required": false,
                    "type": "string",
                    "description": "Git revision of the pack content to use for this action execution (git commit sha / tag / branch). Only applies to packs which are git repositories."
                },
                "log_level": {
                    "default": "DEBUG",
                    "enum": [
                        "AUDIT",
                        "CRITICAL",
                        "ERROR",
                        "WARNING",
                        "INFO",
                        "DEBUG"
                    ],
                    "type": "string",
                    "description": "Default log level for Python runner actions."
                },
                "timeout": {
                    "default": 600,
                    "type": "integer",
                    "description": "Action timeout in seconds. Action will get killed if it doesn't finish in timeout seconds."
                },
                "env": {
                    "type": "object",
                    "description": "Environment variables which will be available to the script."
                }
            },
            "id": "5cc867c9a08f814ec62cf986",
            "name": "python-script"
        },
        "elapsed_seconds": 1.674699,
        "web_url": "https://st2vagrant/#/history/5cc88e25a08f8116378b5959/general",
        "parent": "5cc88e25a08f81188b2ded97",
        "result": {
            "result": "None",
            "exit_code": 1,
            "stderr": "Traceback (most recent call last):\n  File \"/opt/stackstorm/st2/lib/python2.7/site-packages/python_runner/python_action_wrapper.py\", line 334, in <module>\n    obj.run()\n  File \"/opt/stackstorm/st2/lib/python2.7/site-packages/python_runner/python_action_wrapper.py\", line 193, in run\n    output = action.run(**self._parameters)\n  File \"/opt/stackstorm/packs/packs/actions/pack_mgmt/download.py\", line 74, in run\n    logger=self.logger)\n  File \"/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/util/pack_management.py\", line 129, in download_pack\n    verify_pack_version(pack_dir=abs_local_path)\n  File \"/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/util/pack_management.py\", line 403, in verify_pack_version\n    raise ValueError(msg)\nValueError: Pack \"sentinelone\" requires Python 3.x, but current Python version is \"2.7.5\". You can override this restriction by providing the \"force\" flag, but the pack is not guaranteed to work.\n",
            "stdout": ""
        },
        "context": {
            "parent": {
                "user": "st2admin",
                "execution_id": "5cc88e25a08f81188b2ded97",
                "pack": "packs"
            },
            "user": "st2admin",
            "chain": {
                "name": "download pack",
                "parameters": {
                    "force": "{{force}}",
                    "packs": "{{packs}}"
                },
                "publish": null,
                "params": null,
                "notify": null,
                "on_failure": null,
                "ref": "packs.download",
                "on_success": "make a prerun"
            },
            "pack": "packs"
        },
        "action": {
            "description": "Downloads packs and places it in the local content repository.",
            "runner_type": "python-script",
            "tags": [],
            "enabled": true,
            "metadata_file": "actions/download.yaml",
            "pack": "packs",
            "entry_point": "pack_mgmt/download.py",
            "notify": {},
            "output_schema": {},
            "uid": "action:packs:download",
            "parameters": {
                "force": {
                    "default": false,
                    "required": false,
                    "type": "boolean",
                    "description": "Set to True to force install the pack and skip StackStorm version compatibility check"
                },
                "abs_repo_base": {
                    "default": "/opt/stackstorm/packs/",
                    "type": "string",
                    "immutable": true
                },
                "verifyssl": {
                    "default": true,
                    "type": "boolean"
                },
                "packs": {
                    "items": {
                        "type": "string"
                    },
                    "required": true,
                    "type": "array"
                }
            },
            "ref": "packs.download",
            "id": "5cc867cfa08f814ed6b05f3c",
            "name": "download"
        },
        "liveaction": {
            "runner_info": {
                "hostname": "st2vagrant",
                "pid": 5660
            },
            "parameters": {
                "force": false,
                "packs": [
                    "file:////opt/stackstorm/pack_dev/sentinelone"
                ]
            },
            "action_is_workflow": false,
            "callback": {},
            "action": "packs.download",
            "id": "5cc88e25a08f8116378b5958"
        },
        "id": "5cc88e25a08f8116378b5959",
        "end_timestamp": "2019-04-30T18:04:23.289904Z"
    }
]
# -------- end 140386129926032 response ------------

id: 5cc88e25a08f81188b2ded97
action.ref: packs.install
parameters: 
  packs:
  - file:////opt/stackstorm/pack_dev/sentinelone
  python3: true
status: failed
result_task: download pack
result: 
  exit_code: 1
  result: None
  stderr: "Traceback (most recent call last):
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/python_runner/python_action_wrapper.py", line 334, in <module>
    obj.run()
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/python_runner/python_action_wrapper.py", line 193, in run
    output = action.run(**self._parameters)
  File "/opt/stackstorm/packs/packs/actions/pack_mgmt/download.py", line 74, in run
    logger=self.logger)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/util/pack_management.py", line 129, in download_pack
    verify_pack_version(pack_dir=abs_local_path)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/util/pack_management.py", line 403, in verify_pack_version
    raise ValueError(msg)
ValueError: Pack "sentinelone" requires Python 3.x, but current Python version is "2.7.5". You can override this restriction by providing the "force" flag, but the pack is not guaranteed to work.
"
  stdout: ''
error: Traceback (most recent call last):
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/python_runner/python_action_wrapper.py", line 334, in <module>
    obj.run()
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/python_runner/python_action_wrapper.py", line 193, in run
    output = action.run(**self._parameters)
  File "/opt/stackstorm/packs/packs/actions/pack_mgmt/download.py", line 74, in run
    logger=self.logger)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/util/pack_management.py", line 129, in download_pack
    verify_pack_version(pack_dir=abs_local_path)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/util/pack_management.py", line 403, in verify_pack_version
    raise ValueError(msg)
ValueError: Pack "sentinelone" requires Python 3.x, but current Python version is "2.7.5". You can override this restriction by providing the "force" flag, but the pack is not guaranteed to work.

traceback: None
failed_on: download pack
start_timestamp: Tue, 30 Apr 2019 18:04:21 UTC
end_timestamp: Tue, 30 Apr 2019 18:04:23 UTC
+--------------------------+---------------------+---------------+----------------+-------------------------------+
| id                       | status              | task          | action         | start_timestamp               |
+--------------------------+---------------------+---------------+----------------+-------------------------------+
| 5cc88e25a08f8116378b5959 | failed (2s elapsed) | download pack | packs.download | Tue, 30 Apr 2019 18:04:21 UTC |
+--------------------------+---------------------+---------------+----------------+-------------------------------+
@Kami Kami self-assigned this Apr 30, 2019
@Kami
Copy link
Member

Kami commented Apr 30, 2019

Thanks for bringing this up.

Quickly from top of my head - --python3 flag was really just a temporary workaround until we produce official packages which run all StackStorm components / services under Python 3 (this is now already the case for Ubuntu Bionic packages) so --python3 flag functionality is not intended to work with new python_versions pack.yaml attribute.

In fact, it's planned to be removed in the near future because there are too many edge cases when mixing Python versions - StackStorm running under Python 2 and (some) packs running under Python 3.

It also causes unnecessary confusion when things fail when mixing Python versions (some packs work in a mixed environment, but a lot don't and produce "cryptic" errors which cause confusion).

@punkrokk
Copy link
Member Author

punkrokk commented Apr 30, 2019 via email

@Kami
Copy link
Member

Kami commented Apr 30, 2019

It should work if your StackStorm components are running under Python 3 - that's what the python_versions attribute in pack.yaml does.

It tells StackStorm under which Python versions pack works (and is tested with) and if you try to install it on an unsupported version it will throw an error.

@Kami
Copy link
Member

Kami commented Apr 30, 2019

And to add to my point above - yes, our documentation is not currently clear about that and we plan to fix that in time for v3.1.0 when Ubuntu Bionic packages which run StackStorm components under Python 3 go GA.

And sorry if the lack of documentation caused confusion.

@punkrokk
Copy link
Member Author

Wait - so are you saying - that - if I have python3 installed - and my understanding is that a pack that is ready for python3 simply runs the pack in python3, not all of ST2 in python3 - should work if in my pack.yaml I have only python3 defined and run st2 pack install somepack. Because that is not what I'm experiencing.

@Kami
Copy link
Member

Kami commented Apr 30, 2019

Having Python 3 installed is not enough - you need to have all the StackStorm components running under Python 3 and at the moment that's only the case with beta Ubuntu Bionic packages. This means packs which mark that they only work under Python 3 will only work on Ubuntu Bionic if you are using official packages (in theory you could also run StackStorm components under Python 3 on other distros, but that's not something we officially support).

In the past, the idea behind --python3 flag was that you could have StackStorm components running under Python 2 and Python 3 installed on the system and also some packs using Python 3 for pack virtual environment.

It turned out though there are too many edge cases when supporting such mixed environments so we don't plan support that in the future anymore.

And it would also be very hard and expensive (maintenance wise) to also run continuous integration system which tests all the packs in a mixed environment (in addition to testing packs under standalone Python 2 and standalone Python 3 StackStorm installation).

@Kami
Copy link
Member

Kami commented Apr 30, 2019

One option would be for us to leave the flag there and make it work in combination with python_versions attribute as per your use-case in v3.1.0, but that would be experimental and not officially supported feature since a lot of packs don't work in such mixed Python environments.

@punkrokk
Copy link
Member Author

punkrokk commented Apr 30, 2019 via email

@punkrokk
Copy link
Member Author

punkrokk commented Apr 30, 2019 via email

@Kami
Copy link
Member

Kami commented Apr 30, 2019

If you need a temporary solution for your scenario you can try using --force flag, this will make pack install command skip Python version check.

But again, there is no guarantees it will work - if it does though, great :)

@punkrokk
Copy link
Member Author

punkrokk commented May 1, 2019

One option would be for us to leave the flag there and make it work in combination with python_versions attribute as per your use-case in v3.1.0, but that would be experimental and not officially supported feature since a lot of packs don't work in such mixed Python environments.

Regarding this - If I'm building out net new packs, then I'm fine with experimental since I own them. I like this idea.

Really what I care most about is - in the event I wish to use the pack.yaml syntax for python3 support, I don't wish to be required to also put --python2 in my pack.yaml, because I'm specifically not building net new packs that are py2/py3 compatible. I accept that it's experimental, and what it get me is I won't have to go and update pack.yaml files in X months because it's now required, where it isn't today.

@Kami
Copy link
Member

Kami commented May 1, 2019

Yeah, after some more discussion with others, we will go with that approach in v3.1.

We will make --python3 flag work in combination with python_versions pack.yaml attribute and we will also document that mixed environments have edge cases and that some packs won't work (primarily that's the case with packs which depend on 3rd party Python packages which are not pure Python and depend on C extensions).

Thanks again for bringing this up.

@punkrokk
Copy link
Member Author

punkrokk commented May 2, 2019

@Kami Thanks for the feedback. I like what you proposed and it will solve a challenge for me, which in my case we do not have any 3rd party Py packages that have C extension dependencies. Thank you for being so responsive.

@Kami
Copy link
Member

Kami commented May 6, 2019

@punkrokk #4662 should fix this.

As noted above, there are still edge cases when mixing Python versions and this will be solved (documented, etc.) separately.

Thanks again for reporting this issue.

@punkrokk
Copy link
Member Author

punkrokk commented May 6, 2019

yup no problem, thanks for the tweaks

@Kami Kami closed this as completed in #4662 May 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants