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 run --inherit-env does not work for actions run with python-script runner #4676

Closed
blag opened this issue May 13, 2019 · 1 comment · Fixed by #6030
Closed

st2 run --inherit-env does not work for actions run with python-script runner #4676

blag opened this issue May 13, 2019 · 1 comment · Fixed by #6030

Comments

@blag
Copy link
Contributor

blag commented May 13, 2019

SUMMARY

The --inherit-env option supposedly supports the python-script runner:

  -e, --inherit-env     Pass all the environment variables which are
                        accessible to the CLI as "env" parameter to the
                        action. Note: Only works with python, local and remote
                        runners.

But it doesn't actually pass the environment variables to the Python script. I suspect that this has been broken for some time.

The core.local and core.remote actions do pass their environment variables correctly.

ISSUE TYPE

Pick one below and delete the rest:

  • Bug Report
STACKSTORM VERSION

st2 3.1dev (95d7cc3), on Python 2.7.12

OS / ENVIRONMENT / INSTALL METHOD

Ubuntu 16.04, installed as part of setup_e2e_tests in st2ci pack.

STEPS TO REPRODUCE

actions/test_inherit_env_python_script_runner.yaml:

---
name: test_inherit_env_python_script_runner
description: Test the --inherit-env option to the st2 command for an action run with the python-script runner
enabled: true
runner_type: python-script
entry_point: test_inherit_env.py
parameters: {}

actions/test_inherit_env.py:

import os

from st2common.runners.base_action import Action


class InheritEnvTestAction(Action):
    def run(self, *args, **kwargs):
        return (True, os.environ)
EXPECTED RESULTS
env | grep SLACK_; st2 run --inherit-env tests.test_inherit_env_python_script_runner
SLACK_USER_API_TOKEN=xoxb-...
SLACK_CHANNEL=chatops_e2e_tests_u16
SLACK_BOT_USERNAME=chatops_test_bot_u16
SLACK_USER_USERNAME=chatops_test_user_u16
.
id: ...
status: succeeded
parameters: None
result:
  exit_code: 0
  result: '{
    ''SLACK_USER_API_TOKEN'': ''xoxb-...'',
    ''SLACK_CHANNEL'': ''chatops_e2e_tests_u16'',
    ''SLACK_BOT_USERNAME'': ''chatops_test_bot_u16'',
    ''SLACK_USER_USERNAME'': ''chatops_test_user_u16'',
    ''ST2_ACTION_EXECUTION_ID'': ''...',
    ''DAEMON_ARGS'': ''--config-file /etc/st2/st2.conf'',
    ''ST2_ACTION_API_URL'': ''http://127.0.0.1:9101/v1'',
    ''ST2_ACTION_AUTH_TOKEN'': ''...'',
    ''PYTHONPATH'': ''/opt/stackstorm/packs/tests/lib:/opt/stackstorm/st2/lib/python2.7/site-packages'',
    ''ST2_AUTH_TOKEN'': ''...'',
    ''SHELL'': ''/bin/sh'',
    ''LOGNAME'': ''root'',
    ''ST2_API_URL'': ''http://127.0.0.1:9101/v1'',
    ''WORKERID'': ''10'',
    ''PATH'': ''/opt/stackstorm/virtualenvs/tests/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'',
    ''HOME'': ''/root'',
    ''USER'': ''root''
  }'
  stderr: ''
  stdout: ''

Note how the SLACK_ environment variables show up in the output from st2.

ACTUAL RESULTS
env | grep SLACK_; st2 run --inherit-env tests.test_inherit_env_python_script_runner
SLACK_USER_API_TOKEN=xoxb-...
SLACK_CHANNEL=chatops_e2e_tests_u16
SLACK_BOT_USERNAME=chatops_test_bot_u16
SLACK_USER_USERNAME=chatops_test_user_u16
.
id: ...
status: succeeded
parameters: None
result:
  exit_code: 0
  result: '{
    ''ST2_ACTION_PACK_NAME'': ''tests'',
    ''ST2_ACTION_EXECUTION_ID'': ''...',
    ''DAEMON_ARGS'': ''--config-file /etc/st2/st2.conf'',
    ''ST2_ACTION_API_URL'': ''http://127.0.0.1:9101/v1'',
    ''ST2_ACTION_AUTH_TOKEN'': ''...'',
    ''PYTHONPATH'': ''/opt/stackstorm/packs/tests/lib:/opt/stackstorm/st2/lib/python2.7/site-packages'',
    ''ST2_AUTH_TOKEN'': ''...'',
    ''SHELL'': ''/bin/sh'',
    ''LOGNAME'': ''root'',
    ''ST2_API_URL'': ''http://127.0.0.1:9101/v1'',
    ''WORKERID'': ''10'',
    ''PATH'': ''/opt/stackstorm/virtualenvs/tests/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'',
    ''HOME'': ''/root'',
    ''USER'': ''root''
  }'
  stderr: ''
  stdout: ''

Note how the SLACK_ environment variables do not show up in the output from st2.

@winem
Copy link
Contributor

winem commented Sep 11, 2021

Reported for Ubuntu Xenial but still applies to later and currently supported OS.

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

Successfully merging a pull request may close this issue.

2 participants