Skip to content

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

@blag

Description

@blag
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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions