From d36571328b6c273b2ca3b2961467a7da29a35c71 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Sat, 2 Nov 2024 14:51:57 -0500 Subject: [PATCH 01/10] expose oslo_config env var support --- st2common/st2common/config.py | 11 +++++++++++ .../tests/integration/test_garbage_collector.py | 5 +++++ st2tests/st2tests/config.py | 4 +++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/st2common/st2common/config.py b/st2common/st2common/config.py index bbf73752b3..e3a802a15b 100644 --- a/st2common/st2common/config.py +++ b/st2common/st2common/config.py @@ -19,6 +19,7 @@ import sys from oslo_config import cfg +from oslo_config.sources._environment import EnvironmentConfigurationSource from st2common.constants.system import VERSION_STRING from st2common.constants.system import DEFAULT_CONFIG_FILE_PATH @@ -900,10 +901,20 @@ def register_opts(ignore_errors=False): ) +class St2EnvironmentConfigurationSource(EnvironmentConfigurationSource): + @staticmethod + def get_name(group_name, option_name): + group_name = group_name or "DEFAULT" + return "ST2_{}__{}".format(group_name.upper(), option_name.upper()) + + def parse_args(args=None, ignore_errors=False): + # Override oslo_config's 'OS_' env var prefix with 'ST2_'. + cfg.CONF._env_driver = St2EnvironmentConfigurationSource() register_opts(ignore_errors=ignore_errors) cfg.CONF( args=args, version=VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], + use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2reactor/tests/integration/test_garbage_collector.py b/st2reactor/tests/integration/test_garbage_collector.py index 649d09e534..938a3c15da 100644 --- a/st2reactor/tests/integration/test_garbage_collector.py +++ b/st2reactor/tests/integration/test_garbage_collector.py @@ -20,6 +20,8 @@ import signal import datetime +from oslo_config import cfg + from st2common.util import concurrency from st2common.constants import action as action_constants from st2common.util import date as date_utils @@ -274,12 +276,15 @@ def _create_inquiry(self, ttl, timestamp): def _start_garbage_collector(self): subprocess = concurrency.get_subprocess_module() + env=os.environ.copy() + env["ST2_DATABASE__DB_NAME"] = cfg.CONF.database.db_name process = subprocess.Popen( CMD_INQUIRY, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, preexec_fn=os.setsid, + env=env, ) self.add_process(process=process) return process diff --git a/st2tests/st2tests/config.py b/st2tests/st2tests/config.py index 40c82151e9..575d6addd4 100644 --- a/st2tests/st2tests/config.py +++ b/st2tests/st2tests/config.py @@ -39,9 +39,11 @@ def reset(): def parse_args(args=None, coordinator_noop=True): + # Override oslo_config's 'OS_' env var prefix with 'ST2_'. + cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource() _setup_config_opts(coordinator_noop=coordinator_noop) - kwargs = {} + kwargs = {"use_env": True} if USE_DEFAULT_CONFIG_FILES: kwargs["default_config_files"] = [DEFAULT_CONFIG_FILE_PATH] From a27b4df71dcf861dc2b5adddf650a91f63cacd7e Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Sat, 2 Nov 2024 16:38:01 -0500 Subject: [PATCH 02/10] expose oslo_config env var support --- st2actions/st2actions/notifier/config.py | 3 +++ st2actions/st2actions/scheduler/config.py | 3 +++ st2actions/st2actions/workflows/config.py | 3 +++ st2api/st2api/config.py | 3 +++ st2auth/st2auth/config.py | 3 +++ st2reactor/st2reactor/garbage_collector/config.py | 3 +++ st2reactor/st2reactor/rules/config.py | 3 +++ st2reactor/st2reactor/sensor/config.py | 3 +++ st2reactor/st2reactor/timer/config.py | 3 +++ st2stream/st2stream/config.py | 3 +++ 10 files changed, 30 insertions(+) diff --git a/st2actions/st2actions/notifier/config.py b/st2actions/st2actions/notifier/config.py index d5bb4b44ab..b18bb0417f 100644 --- a/st2actions/st2actions/notifier/config.py +++ b/st2actions/st2actions/notifier/config.py @@ -25,10 +25,13 @@ def parse_args(args=None): + # Override oslo_config's 'OS_' env var prefix with 'ST2_'. + cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource() cfg.CONF( args=args, version=VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], + use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2actions/st2actions/scheduler/config.py b/st2actions/st2actions/scheduler/config.py index 035c030a93..422e52997b 100644 --- a/st2actions/st2actions/scheduler/config.py +++ b/st2actions/st2actions/scheduler/config.py @@ -27,10 +27,13 @@ def parse_args(args=None): + # Override oslo_config's 'OS_' env var prefix with 'ST2_'. + cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource() cfg.CONF( args=args, version=sys_constants.VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], + use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2actions/st2actions/workflows/config.py b/st2actions/st2actions/workflows/config.py index bbfa5b22a1..6983a074b0 100644 --- a/st2actions/st2actions/workflows/config.py +++ b/st2actions/st2actions/workflows/config.py @@ -23,10 +23,13 @@ def parse_args(args=None): + # Override oslo_config's 'OS_' env var prefix with 'ST2_'. + cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource() cfg.CONF( args=args, version=sys_constants.VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], + use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2api/st2api/config.py b/st2api/st2api/config.py index 5009763cdf..6d5fe36b8a 100644 --- a/st2api/st2api/config.py +++ b/st2api/st2api/config.py @@ -32,10 +32,13 @@ def parse_args(args=None): + # Override oslo_config's 'OS_' env var prefix with 'ST2_'. + cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource() cfg.CONF( args=args, version=VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], + use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2auth/st2auth/config.py b/st2auth/st2auth/config.py index aa85ae4584..1a346c8464 100644 --- a/st2auth/st2auth/config.py +++ b/st2auth/st2auth/config.py @@ -28,10 +28,13 @@ def parse_args(args=None): + # Override oslo_config's 'OS_' env var prefix with 'ST2_'. + cfg.CONF._env_driver = st2cfg.St2EnvironmentConfigurationSource() cfg.CONF( args=args, version=VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], + use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2reactor/st2reactor/garbage_collector/config.py b/st2reactor/st2reactor/garbage_collector/config.py index e5d2600de4..febce172d7 100644 --- a/st2reactor/st2reactor/garbage_collector/config.py +++ b/st2reactor/st2reactor/garbage_collector/config.py @@ -27,10 +27,13 @@ def parse_args(args=None): + # Override oslo_config's 'OS_' env var prefix with 'ST2_'. + cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource() cfg.CONF( args=args, version=VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], + use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2reactor/st2reactor/rules/config.py b/st2reactor/st2reactor/rules/config.py index 20bc720ec9..98895fb7cd 100644 --- a/st2reactor/st2reactor/rules/config.py +++ b/st2reactor/st2reactor/rules/config.py @@ -25,10 +25,13 @@ def parse_args(args=None): + # Override oslo_config's 'OS_' env var prefix with 'ST2_'. + cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource() cfg.CONF( args=args, version=VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], + use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2reactor/st2reactor/sensor/config.py b/st2reactor/st2reactor/sensor/config.py index 8126bdbc9f..653d30a276 100644 --- a/st2reactor/st2reactor/sensor/config.py +++ b/st2reactor/st2reactor/sensor/config.py @@ -26,10 +26,13 @@ def parse_args(args=None): + # Override oslo_config's 'OS_' env var prefix with 'ST2_'. + cfg.CONF._env_driver = st2cfg.St2EnvironmentConfigurationSource() cfg.CONF( args=args, version=VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], + use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2reactor/st2reactor/timer/config.py b/st2reactor/st2reactor/timer/config.py index 0301ca4a7f..9561de75e7 100644 --- a/st2reactor/st2reactor/timer/config.py +++ b/st2reactor/st2reactor/timer/config.py @@ -25,10 +25,13 @@ def parse_args(args=None): + # Override oslo_config's 'OS_' env var prefix with 'ST2_'. + cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource() cfg.CONF( args=args, version=VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], + use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2stream/st2stream/config.py b/st2stream/st2stream/config.py index eef5c55830..cbc83c055e 100644 --- a/st2stream/st2stream/config.py +++ b/st2stream/st2stream/config.py @@ -32,10 +32,13 @@ def parse_args(args=None): + # Override oslo_config's 'OS_' env var prefix with 'ST2_'. + cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource() cfg.CONF( args=args, version=VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], + use_env=True, # Make our env var support explicit (default is True) ) From b840b453fa84cc248c02719087fecbe05e26f4f1 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Sat, 2 Nov 2024 19:20:19 -0500 Subject: [PATCH 03/10] expose oslo_config env var support --- st2reactor/tests/integration/test_garbage_collector.py | 2 +- st2reactor/tests/integration/test_sensor_container.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/st2reactor/tests/integration/test_garbage_collector.py b/st2reactor/tests/integration/test_garbage_collector.py index 938a3c15da..80e3a39b4d 100644 --- a/st2reactor/tests/integration/test_garbage_collector.py +++ b/st2reactor/tests/integration/test_garbage_collector.py @@ -276,7 +276,7 @@ def _create_inquiry(self, ttl, timestamp): def _start_garbage_collector(self): subprocess = concurrency.get_subprocess_module() - env=os.environ.copy() + env = os.environ.copy() env["ST2_DATABASE__DB_NAME"] = cfg.CONF.database.db_name process = subprocess.Popen( CMD_INQUIRY, diff --git a/st2reactor/tests/integration/test_sensor_container.py b/st2reactor/tests/integration/test_sensor_container.py index e2e13a3474..16fb0e554f 100644 --- a/st2reactor/tests/integration/test_sensor_container.py +++ b/st2reactor/tests/integration/test_sensor_container.py @@ -244,6 +244,8 @@ def test_single_sensor_mode(self): def _start_sensor_container(self, cmd=DEFAULT_CMD): subprocess = concurrency.get_subprocess_module() + env = os.environ.copy() + env["ST2_DATABASE__DB_NAME"] = cfg.CONF.database.db_name print("Using command: %s" % (" ".join(cmd))) process = subprocess.Popen( cmd, @@ -251,6 +253,7 @@ def _start_sensor_container(self, cmd=DEFAULT_CMD): stderr=subprocess.PIPE, shell=False, preexec_fn=os.setsid, + env=env, ) self.add_process(process=process) return process From 610b3d6419995809c1e2d2137eae29235c79551f Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Wed, 6 Nov 2024 17:10:52 -0600 Subject: [PATCH 04/10] add ST2_ env var handling to actionrunner and reactor --- st2actions/st2actions/config.py | 3 +++ st2reactor/st2reactor/cmd/trigger_re_fire.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/st2actions/st2actions/config.py b/st2actions/st2actions/config.py index 3ed43c3c6e..7a98134278 100644 --- a/st2actions/st2actions/config.py +++ b/st2actions/st2actions/config.py @@ -28,10 +28,13 @@ def parse_args(args=None): + # Override oslo_config's 'OS_' env var prefix with 'ST2_'. + CONF._env_driver = common_config.St2EnvironmentConfigurationSource() CONF( args=args, version=VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], + use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2reactor/st2reactor/cmd/trigger_re_fire.py b/st2reactor/st2reactor/cmd/trigger_re_fire.py index 8282a5decf..acee891da6 100644 --- a/st2reactor/st2reactor/cmd/trigger_re_fire.py +++ b/st2reactor/st2reactor/cmd/trigger_re_fire.py @@ -48,6 +48,8 @@ def _parse_config(): CONF.register_cli_opts(cli_opts) st2cfg.register_opts(ignore_errors=False) + # Override oslo_config's 'OS_' env var prefix with 'ST2_'. + CONF._env_driver = st2cfg.St2EnvironmentConfigurationSource() CONF(args=sys.argv[1:]) From 15e9cac0a90650f8c5b814cf7a95c47f50cbee44 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Fri, 8 Nov 2024 19:18:20 -0600 Subject: [PATCH 05/10] Simplify oslo_config setup to use ST2_* env vars --- st2actions/st2actions/config.py | 4 +--- st2actions/st2actions/notifier/config.py | 6 +----- st2actions/st2actions/scheduler/config.py | 4 +--- st2actions/st2actions/workflows/config.py | 4 +--- st2api/st2api/config.py | 4 +--- st2auth/st2auth/config.py | 4 +--- st2common/st2common/config.py | 9 ++++++--- st2reactor/st2reactor/cmd/trigger_re_fire.py | 3 +-- st2reactor/st2reactor/garbage_collector/config.py | 4 +--- st2reactor/st2reactor/rules/config.py | 4 +--- st2reactor/st2reactor/sensor/config.py | 4 +--- st2reactor/st2reactor/timer/config.py | 4 +--- st2stream/st2stream/config.py | 4 +--- st2tests/st2tests/config.py | 5 ++--- 14 files changed, 20 insertions(+), 43 deletions(-) diff --git a/st2actions/st2actions/config.py b/st2actions/st2actions/config.py index 7a98134278..504c7e5eb3 100644 --- a/st2actions/st2actions/config.py +++ b/st2actions/st2actions/config.py @@ -28,13 +28,11 @@ def parse_args(args=None): - # Override oslo_config's 'OS_' env var prefix with 'ST2_'. - CONF._env_driver = common_config.St2EnvironmentConfigurationSource() + common_config.use_st2_env_vars(CONF) CONF( args=args, version=VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], - use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2actions/st2actions/notifier/config.py b/st2actions/st2actions/notifier/config.py index b18bb0417f..474d5447e5 100644 --- a/st2actions/st2actions/notifier/config.py +++ b/st2actions/st2actions/notifier/config.py @@ -21,17 +21,13 @@ from st2common.constants.system import VERSION_STRING from st2common.constants.system import DEFAULT_CONFIG_FILE_PATH -CONF = cfg.CONF - def parse_args(args=None): - # Override oslo_config's 'OS_' env var prefix with 'ST2_'. - cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource() + common_config.use_st2_env_vars(cfg.CONF) cfg.CONF( args=args, version=VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], - use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2actions/st2actions/scheduler/config.py b/st2actions/st2actions/scheduler/config.py index 422e52997b..614702f3f6 100644 --- a/st2actions/st2actions/scheduler/config.py +++ b/st2actions/st2actions/scheduler/config.py @@ -27,13 +27,11 @@ def parse_args(args=None): - # Override oslo_config's 'OS_' env var prefix with 'ST2_'. - cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource() + common_config.use_st2_env_vars(cfg.CONF) cfg.CONF( args=args, version=sys_constants.VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], - use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2actions/st2actions/workflows/config.py b/st2actions/st2actions/workflows/config.py index 6983a074b0..4e54aef02c 100644 --- a/st2actions/st2actions/workflows/config.py +++ b/st2actions/st2actions/workflows/config.py @@ -23,13 +23,11 @@ def parse_args(args=None): - # Override oslo_config's 'OS_' env var prefix with 'ST2_'. - cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource() + common_config.use_st2_env_vars(cfg.CONF) cfg.CONF( args=args, version=sys_constants.VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], - use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2api/st2api/config.py b/st2api/st2api/config.py index 6d5fe36b8a..e73c5c3936 100644 --- a/st2api/st2api/config.py +++ b/st2api/st2api/config.py @@ -32,13 +32,11 @@ def parse_args(args=None): - # Override oslo_config's 'OS_' env var prefix with 'ST2_'. - cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource() + common_config.use_st2_env_vars(cfg.CONF) cfg.CONF( args=args, version=VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], - use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2auth/st2auth/config.py b/st2auth/st2auth/config.py index 1a346c8464..061075db7b 100644 --- a/st2auth/st2auth/config.py +++ b/st2auth/st2auth/config.py @@ -28,13 +28,11 @@ def parse_args(args=None): - # Override oslo_config's 'OS_' env var prefix with 'ST2_'. - cfg.CONF._env_driver = st2cfg.St2EnvironmentConfigurationSource() + st2cfg.use_st2_env_vars(cfg.CONF) cfg.CONF( args=args, version=VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], - use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2common/st2common/config.py b/st2common/st2common/config.py index e3a802a15b..15a4d5b32a 100644 --- a/st2common/st2common/config.py +++ b/st2common/st2common/config.py @@ -908,13 +908,16 @@ def get_name(group_name, option_name): return "ST2_{}__{}".format(group_name.upper(), option_name.upper()) -def parse_args(args=None, ignore_errors=False): +def use_st2_env_vars(conf: cfg.ConfigOpts) -> None: # Override oslo_config's 'OS_' env var prefix with 'ST2_'. - cfg.CONF._env_driver = St2EnvironmentConfigurationSource() + conf._env_driver = St2EnvironmentConfigurationSource() + + +def parse_args(args=None, ignore_errors=False): + use_st2_env_vars(cfg.CONF) register_opts(ignore_errors=ignore_errors) cfg.CONF( args=args, version=VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], - use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2reactor/st2reactor/cmd/trigger_re_fire.py b/st2reactor/st2reactor/cmd/trigger_re_fire.py index acee891da6..d278aab835 100644 --- a/st2reactor/st2reactor/cmd/trigger_re_fire.py +++ b/st2reactor/st2reactor/cmd/trigger_re_fire.py @@ -48,8 +48,7 @@ def _parse_config(): CONF.register_cli_opts(cli_opts) st2cfg.register_opts(ignore_errors=False) - # Override oslo_config's 'OS_' env var prefix with 'ST2_'. - CONF._env_driver = st2cfg.St2EnvironmentConfigurationSource() + st2cfg.use_st2_env_vars(CONF) CONF(args=sys.argv[1:]) diff --git a/st2reactor/st2reactor/garbage_collector/config.py b/st2reactor/st2reactor/garbage_collector/config.py index febce172d7..66bf88bb5c 100644 --- a/st2reactor/st2reactor/garbage_collector/config.py +++ b/st2reactor/st2reactor/garbage_collector/config.py @@ -27,13 +27,11 @@ def parse_args(args=None): - # Override oslo_config's 'OS_' env var prefix with 'ST2_'. - cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource() + common_config.use_st2_env_vars(cfg.CONF) cfg.CONF( args=args, version=VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], - use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2reactor/st2reactor/rules/config.py b/st2reactor/st2reactor/rules/config.py index 98895fb7cd..d05ce44d1e 100644 --- a/st2reactor/st2reactor/rules/config.py +++ b/st2reactor/st2reactor/rules/config.py @@ -25,13 +25,11 @@ def parse_args(args=None): - # Override oslo_config's 'OS_' env var prefix with 'ST2_'. - cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource() + common_config.use_st2_env_vars(cfg.CONF) cfg.CONF( args=args, version=VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], - use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2reactor/st2reactor/sensor/config.py b/st2reactor/st2reactor/sensor/config.py index 653d30a276..f54a602167 100644 --- a/st2reactor/st2reactor/sensor/config.py +++ b/st2reactor/st2reactor/sensor/config.py @@ -26,13 +26,11 @@ def parse_args(args=None): - # Override oslo_config's 'OS_' env var prefix with 'ST2_'. - cfg.CONF._env_driver = st2cfg.St2EnvironmentConfigurationSource() + st2cfg.use_st2_env_vars(cfg.CONF) cfg.CONF( args=args, version=VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], - use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2reactor/st2reactor/timer/config.py b/st2reactor/st2reactor/timer/config.py index 9561de75e7..02c868cb8c 100644 --- a/st2reactor/st2reactor/timer/config.py +++ b/st2reactor/st2reactor/timer/config.py @@ -25,13 +25,11 @@ def parse_args(args=None): - # Override oslo_config's 'OS_' env var prefix with 'ST2_'. - cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource() + common_config.use_st2_env_vars(cfg.CONF) cfg.CONF( args=args, version=VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], - use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2stream/st2stream/config.py b/st2stream/st2stream/config.py index cbc83c055e..e820c249df 100644 --- a/st2stream/st2stream/config.py +++ b/st2stream/st2stream/config.py @@ -32,13 +32,11 @@ def parse_args(args=None): - # Override oslo_config's 'OS_' env var prefix with 'ST2_'. - cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource() + common_config.use_st2_env_vars(cfg.CONF) cfg.CONF( args=args, version=VERSION_STRING, default_config_files=[DEFAULT_CONFIG_FILE_PATH], - use_env=True, # Make our env var support explicit (default is True) ) diff --git a/st2tests/st2tests/config.py b/st2tests/st2tests/config.py index 575d6addd4..95bf49314f 100644 --- a/st2tests/st2tests/config.py +++ b/st2tests/st2tests/config.py @@ -39,11 +39,10 @@ def reset(): def parse_args(args=None, coordinator_noop=True): - # Override oslo_config's 'OS_' env var prefix with 'ST2_'. - cfg.CONF._env_driver = common_config.St2EnvironmentConfigurationSource() + common_config.use_st2_env_vars(cfg.CONF) _setup_config_opts(coordinator_noop=coordinator_noop) - kwargs = {"use_env": True} + kwargs = {} if USE_DEFAULT_CONFIG_FILES: kwargs["default_config_files"] = [DEFAULT_CONFIG_FILE_PATH] From d7bb43e9eab8a51dbe67dd1b034398ee11a0749e Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Fri, 8 Nov 2024 19:41:18 -0600 Subject: [PATCH 06/10] Add st2tests.config.db_opts_as_env_vars for itests Integration tests need to start subprocesses that use the same database as the test. This matters when running under pantsbuild, because pants runs several instances of pytest in parallel. We configured pants to pass an env var to disambiguate parallel test runs: ST2TESTS_PARALLEL_SLOT. Then, the db name gets suffixed with this slot number at runtime. But, when an integration test runs production code in a subprocess, the production code does not use-- and should not use--any ST2TESTS_* vars, meaning the subprocess ends up using what is configured in the conf file instead of the parallel-safe test db. Thanks to a new-ish oslo_config feature, we can now update config via env variables. So, make use of that in integration tests to override the conf-file provided values with test-provided values. --- .../integration/test_gunicorn_configs.py | 3 ++ .../test_register_content_script.py | 29 ++++++++++++------- .../test_service_setup_log_level_filtering.py | 8 +++-- .../integration/test_garbage_collector.py | 5 ++-- .../integration/test_sensor_container.py | 2 +- st2tests/st2tests/config.py | 15 ++++++++++ 6 files changed, 45 insertions(+), 17 deletions(-) diff --git a/st2api/tests/integration/test_gunicorn_configs.py b/st2api/tests/integration/test_gunicorn_configs.py index c4c05bb155..84fda239f5 100644 --- a/st2api/tests/integration/test_gunicorn_configs.py +++ b/st2api/tests/integration/test_gunicorn_configs.py @@ -22,6 +22,7 @@ import eventlet from eventlet.green import subprocess +import st2tests.config from st2common.models.utils import profiling from st2common.util.shell import kill_process from st2tests.base import IntegrationTestCase @@ -41,6 +42,7 @@ def test_st2api_wsgi_entry_point(self): ) env = os.environ.copy() env["ST2_CONFIG_PATH"] = ST2_CONFIG_PATH + env.update(st2tests.config.db_opts_as_env_vars()) process = subprocess.Popen(cmd, env=env, shell=True, preexec_fn=os.setsid) try: self.add_process(process=process) @@ -60,6 +62,7 @@ def test_st2auth(self): ) env = os.environ.copy() env["ST2_CONFIG_PATH"] = ST2_CONFIG_PATH + env.update(st2tests.config.db_opts_as_env_vars()) process = subprocess.Popen(cmd, env=env, shell=True, preexec_fn=os.setsid) try: self.add_process(process=process) diff --git a/st2common/tests/integration/test_register_content_script.py b/st2common/tests/integration/test_register_content_script.py index b0288a910e..14abf12e45 100644 --- a/st2common/tests/integration/test_register_content_script.py +++ b/st2common/tests/integration/test_register_content_script.py @@ -19,6 +19,7 @@ import sys import glob +import st2tests.config from st2tests.base import IntegrationTestCase from st2common.util.shell import run_command from st2tests import config as test_config @@ -56,7 +57,7 @@ def test_register_from_pack_success(self): "--register-runner-dir=%s" % (runner_dirs), ] cmd = BASE_REGISTER_ACTIONS_CMD_ARGS + opts - exit_code, _, stderr = run_command(cmd=cmd) + exit_code, _, stderr = self._run_command(cmd=cmd) self.assertIn("Registered 3 actions.", stderr) self.assertEqual(exit_code, 0) @@ -71,7 +72,7 @@ def test_register_from_pack_fail_on_failure_pack_dir_doesnt_exist(self): "--register-no-fail-on-failure", ] cmd = BASE_REGISTER_ACTIONS_CMD_ARGS + opts - exit_code, _, _ = run_command(cmd=cmd) + exit_code, _, _ = self._run_command(cmd=cmd) self.assertEqual(exit_code, 0) # Fail on failure, should fail @@ -81,7 +82,7 @@ def test_register_from_pack_fail_on_failure_pack_dir_doesnt_exist(self): "--register-fail-on-failure", ] cmd = BASE_REGISTER_ACTIONS_CMD_ARGS + opts - exit_code, _, stderr = run_command(cmd=cmd) + exit_code, _, stderr = self._run_command(cmd=cmd) self.assertIn('Directory "doesntexistblah" doesn\'t exist', stderr) self.assertEqual(exit_code, 1) @@ -97,7 +98,7 @@ def test_register_from_pack_action_metadata_fails_validation(self): ] cmd = BASE_REGISTER_ACTIONS_CMD_ARGS + opts - exit_code, _, stderr = run_command(cmd=cmd) + exit_code, _, stderr = self._run_command(cmd=cmd) self.assertIn("Registered 0 actions.", stderr) self.assertEqual(exit_code, 0) @@ -109,7 +110,7 @@ def test_register_from_pack_action_metadata_fails_validation(self): "--register-runner-dir=%s" % (runner_dirs), ] cmd = BASE_REGISTER_ACTIONS_CMD_ARGS + opts - exit_code, _, stderr = run_command(cmd=cmd) + exit_code, _, stderr = self._run_command(cmd=cmd) self.assertIn("object has no attribute 'get'", stderr) self.assertEqual(exit_code, 1) @@ -127,7 +128,7 @@ def test_register_from_packs_doesnt_throw_on_missing_pack_resource_folder(self): "-v", "--register-sensors", ] - exit_code, _, stderr = run_command(cmd=cmd) + exit_code, _, stderr = self._run_command(cmd=cmd) self.assertIn("Registered 0 sensors.", stderr, "Actual stderr: %s" % (stderr)) self.assertEqual(exit_code, 0) @@ -139,7 +140,7 @@ def test_register_from_packs_doesnt_throw_on_missing_pack_resource_folder(self): "--register-all", "--register-no-fail-on-failure", ] - exit_code, _, stderr = run_command(cmd=cmd) + exit_code, _, stderr = self._run_command(cmd=cmd) self.assertIn("Registered 0 actions.", stderr) self.assertIn("Registered 0 sensors.", stderr) self.assertIn("Registered 0 rules.", stderr) @@ -155,7 +156,7 @@ def test_register_all_and_register_setup_virtualenvs(self): "--register-setup-virtualenvs", "--register-no-fail-on-failure", ] - exit_code, stdout, stderr = run_command(cmd=cmd) + exit_code, stdout, stderr = self._run_command(cmd=cmd) self.assertIn("Registering actions", stderr, "Actual stderr: %s" % (stderr)) self.assertIn("Registering rules", stderr) self.assertIn("Setup virtualenv for %s pack(s)" % ("1"), stderr) @@ -170,7 +171,7 @@ def test_register_setup_virtualenvs(self): "--register-setup-virtualenvs", "--register-no-fail-on-failure", ] - exit_code, stdout, stderr = run_command(cmd=cmd) + exit_code, stdout, stderr = self._run_command(cmd=cmd) self.assertIn('Setting up virtualenv for pack "dummy_pack_1"', stderr) self.assertIn("Setup virtualenv for 1 pack(s)", stderr) @@ -186,7 +187,7 @@ def test_register_recreate_virtualenvs(self): "--register-setup-virtualenvs", "--register-no-fail-on-failure", ] - exit_code, stdout, stderr = run_command(cmd=cmd) + exit_code, stdout, stderr = self._run_command(cmd=cmd) self.assertIn('Setting up virtualenv for pack "dummy_pack_1"', stderr) self.assertIn("Setup virtualenv for 1 pack(s)", stderr) @@ -200,9 +201,15 @@ def test_register_recreate_virtualenvs(self): "--register-recreate-virtualenvs", "--register-no-fail-on-failure", ] - exit_code, stdout, stderr = run_command(cmd=cmd) + exit_code, stdout, stderr = self._run_command(cmd=cmd) self.assertIn('Setting up virtualenv for pack "dummy_pack_1"', stderr) self.assertIn("Virtualenv successfully removed.", stderr) self.assertIn("Setup virtualenv for 1 pack(s)", stderr) self.assertEqual(exit_code, 0) + + @staticmethod + def _run_command(cmd): + env = os.environ.copy() + env.update(st2tests.config.db_opts_as_env_vars()) + return run_command(cmd=cmd, env=env) diff --git a/st2common/tests/integration/test_service_setup_log_level_filtering.py b/st2common/tests/integration/test_service_setup_log_level_filtering.py index 36c891896c..a4f3cc90a5 100644 --- a/st2common/tests/integration/test_service_setup_log_level_filtering.py +++ b/st2common/tests/integration/test_service_setup_log_level_filtering.py @@ -21,6 +21,7 @@ import eventlet from eventlet.green import subprocess +import st2tests.config from st2tests.base import IntegrationTestCase from st2tests.fixtures.conf.fixture import FIXTURE_PATH as CONF_FIXTURES_PATH @@ -223,13 +224,16 @@ def test_kombu_heartbeat_tick_log_messages_are_excluded(self): stdout = "\n".join(process.stdout.read().decode("utf-8").split("\n")) self.assertNotIn("heartbeat_tick", stdout) - def _start_process(self, config_path, env=None): + @staticmethod + def _start_process(config_path, env=None): cmd = CMD + [config_path] cwd = os.path.abspath(os.path.join(BASE_DIR, "../../../")) cwd = os.path.abspath(cwd) + env = env or os.environ.copy() + env.update(st2tests.config.db_opts_as_env_vars()) process = subprocess.Popen( cmd, - env=env or os.environ.copy(), + env=env, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, diff --git a/st2reactor/tests/integration/test_garbage_collector.py b/st2reactor/tests/integration/test_garbage_collector.py index 80e3a39b4d..630dad86de 100644 --- a/st2reactor/tests/integration/test_garbage_collector.py +++ b/st2reactor/tests/integration/test_garbage_collector.py @@ -20,8 +20,7 @@ import signal import datetime -from oslo_config import cfg - +import st2tests.config from st2common.util import concurrency from st2common.constants import action as action_constants from st2common.util import date as date_utils @@ -277,7 +276,7 @@ def _create_inquiry(self, ttl, timestamp): def _start_garbage_collector(self): subprocess = concurrency.get_subprocess_module() env = os.environ.copy() - env["ST2_DATABASE__DB_NAME"] = cfg.CONF.database.db_name + env.update(st2tests.config.db_opts_as_env_vars()) process = subprocess.Popen( CMD_INQUIRY, stdout=subprocess.PIPE, diff --git a/st2reactor/tests/integration/test_sensor_container.py b/st2reactor/tests/integration/test_sensor_container.py index 16fb0e554f..0ebae08604 100644 --- a/st2reactor/tests/integration/test_sensor_container.py +++ b/st2reactor/tests/integration/test_sensor_container.py @@ -245,7 +245,7 @@ def test_single_sensor_mode(self): def _start_sensor_container(self, cmd=DEFAULT_CMD): subprocess = concurrency.get_subprocess_module() env = os.environ.copy() - env["ST2_DATABASE__DB_NAME"] = cfg.CONF.database.db_name + env.update(st2tests.config.db_opts_as_env_vars()) print("Using command: %s" % (" ".join(cmd))) process = subprocess.Popen( cmd, diff --git a/st2tests/st2tests/config.py b/st2tests/st2tests/config.py index 95bf49314f..22c5d62f09 100644 --- a/st2tests/st2tests/config.py +++ b/st2tests/st2tests/config.py @@ -16,6 +16,7 @@ from __future__ import absolute_import import os +from typing import Dict from oslo_config import cfg, types @@ -92,6 +93,20 @@ def _override_db_opts(): CONF.set_override(name="host", override="127.0.0.1", group="database") +def db_opts_as_env_vars() -> Dict[str, str]: + env = { + "ST2_DATABASE__HOST": CONF.database.host, + "ST2_DATABASE__PORT": str(CONF.database.port), + "ST2_DATABASE__DB_NAME": CONF.database.db_name, + "ST2_DATABASE__CONNECTION_TIMEOUT": str(CONF.database.connection_timeout), + } + if CONF.database.username is not None: + env["ST2_DATABASE__USERNAME"] = CONF.database.username + if CONF.database.password is not None: + env["ST2_DATABASE__PASSWORD"] = CONF.database.password + return env + + def _override_common_opts(): packs_base_path = get_fixtures_packs_base_path() CONF.set_override(name="base_path", override=packs_base_path, group="system") From 1bbd29acde7de37c08fc9154311531aa41cfba71 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Fri, 8 Nov 2024 19:59:20 -0600 Subject: [PATCH 07/10] Add st2tests.config.coord_opts_as_env_vars for itests Integration tests need to start subprocesses that use the same redis as the test. This matters when running under pantsbuild, because pants runs several instances of pytest in parallel. This PR prepares to add support, to disambiguate test runs--similar to the database logic--using the env var: ST2TESTS_PARALLEL_SLOT. In any case, when an integration test runs production code in a subprocess, the production code does not use-- and should not use--any ST2TESTS_* vars, meaning the subprocess ends up using what is configured in the conf file instead of the (planned) parallel-safe coordinator. Thanks to a new-ish oslo_config feature, we can now update config via env variables. So, make use of that in integration tests to override the conf-file provided values with test-provided values. --- st2api/tests/integration/test_gunicorn_configs.py | 2 ++ .../tests/integration/test_register_content_script.py | 1 + .../integration/test_service_setup_log_level_filtering.py | 1 + st2reactor/tests/integration/test_garbage_collector.py | 1 + st2reactor/tests/integration/test_sensor_container.py | 1 + st2tests/st2tests/config.py | 7 +++++++ 6 files changed, 13 insertions(+) diff --git a/st2api/tests/integration/test_gunicorn_configs.py b/st2api/tests/integration/test_gunicorn_configs.py index 84fda239f5..c663aa83a7 100644 --- a/st2api/tests/integration/test_gunicorn_configs.py +++ b/st2api/tests/integration/test_gunicorn_configs.py @@ -43,6 +43,7 @@ def test_st2api_wsgi_entry_point(self): env = os.environ.copy() env["ST2_CONFIG_PATH"] = ST2_CONFIG_PATH env.update(st2tests.config.db_opts_as_env_vars()) + env.update(st2tests.config.coord_opts_as_env_vars()) process = subprocess.Popen(cmd, env=env, shell=True, preexec_fn=os.setsid) try: self.add_process(process=process) @@ -63,6 +64,7 @@ def test_st2auth(self): env = os.environ.copy() env["ST2_CONFIG_PATH"] = ST2_CONFIG_PATH env.update(st2tests.config.db_opts_as_env_vars()) + env.update(st2tests.config.coord_opts_as_env_vars()) process = subprocess.Popen(cmd, env=env, shell=True, preexec_fn=os.setsid) try: self.add_process(process=process) diff --git a/st2common/tests/integration/test_register_content_script.py b/st2common/tests/integration/test_register_content_script.py index 14abf12e45..c19d91c2a1 100644 --- a/st2common/tests/integration/test_register_content_script.py +++ b/st2common/tests/integration/test_register_content_script.py @@ -212,4 +212,5 @@ def test_register_recreate_virtualenvs(self): def _run_command(cmd): env = os.environ.copy() env.update(st2tests.config.db_opts_as_env_vars()) + env.update(st2tests.config.coord_opts_as_env_vars()) return run_command(cmd=cmd, env=env) diff --git a/st2common/tests/integration/test_service_setup_log_level_filtering.py b/st2common/tests/integration/test_service_setup_log_level_filtering.py index a4f3cc90a5..03cfa1b6e5 100644 --- a/st2common/tests/integration/test_service_setup_log_level_filtering.py +++ b/st2common/tests/integration/test_service_setup_log_level_filtering.py @@ -231,6 +231,7 @@ def _start_process(config_path, env=None): cwd = os.path.abspath(cwd) env = env or os.environ.copy() env.update(st2tests.config.db_opts_as_env_vars()) + env.update(st2tests.config.coord_opts_as_env_vars()) process = subprocess.Popen( cmd, env=env, diff --git a/st2reactor/tests/integration/test_garbage_collector.py b/st2reactor/tests/integration/test_garbage_collector.py index 630dad86de..7b8ff0dd10 100644 --- a/st2reactor/tests/integration/test_garbage_collector.py +++ b/st2reactor/tests/integration/test_garbage_collector.py @@ -277,6 +277,7 @@ def _start_garbage_collector(self): subprocess = concurrency.get_subprocess_module() env = os.environ.copy() env.update(st2tests.config.db_opts_as_env_vars()) + env.update(st2tests.config.coord_opts_as_env_vars()) process = subprocess.Popen( CMD_INQUIRY, stdout=subprocess.PIPE, diff --git a/st2reactor/tests/integration/test_sensor_container.py b/st2reactor/tests/integration/test_sensor_container.py index 0ebae08604..e7d38eda99 100644 --- a/st2reactor/tests/integration/test_sensor_container.py +++ b/st2reactor/tests/integration/test_sensor_container.py @@ -246,6 +246,7 @@ def _start_sensor_container(self, cmd=DEFAULT_CMD): subprocess = concurrency.get_subprocess_module() env = os.environ.copy() env.update(st2tests.config.db_opts_as_env_vars()) + env.update(st2tests.config.coord_opts_as_env_vars()) print("Using command: %s" % (" ".join(cmd))) process = subprocess.Popen( cmd, diff --git a/st2tests/st2tests/config.py b/st2tests/st2tests/config.py index 22c5d62f09..9a2042be4a 100644 --- a/st2tests/st2tests/config.py +++ b/st2tests/st2tests/config.py @@ -165,6 +165,13 @@ def _override_coordinator_opts(noop=False): CONF.set_override(name="lock_timeout", override=1, group="coordination") +def coord_opts_as_env_vars() -> Dict[str, str]: + env = {} + if CONF.coordination.url is not None: + env["ST2_COORDINATION__URL"] = CONF.coordination.url + return env + + def _override_workflow_engine_opts(): cfg.CONF.set_override("retry_stop_max_msec", 200, group="workflow_engine") cfg.CONF.set_override("retry_wait_fixed_msec", 100, group="workflow_engine") From ed072bdd3c0434342580faf18e023b9854ef50bd Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Fri, 8 Nov 2024 20:31:09 -0600 Subject: [PATCH 08/10] Run parse_args() in IntegrationTestCase.setUpClass() This is needed so that vars are initialized before using them to configure the itest subprocesses via env vars. --- st2tests/st2tests/base.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/st2tests/st2tests/base.py b/st2tests/st2tests/base.py index 7847a93dc8..b452f79983 100644 --- a/st2tests/st2tests/base.py +++ b/st2tests/st2tests/base.py @@ -565,6 +565,11 @@ class IntegrationTestCase(TestCase): processes = {} + @classmethod + def setUpClass(cls): + # this prepares the vars for use in configuring the subprocesses via env var + tests_config.parse_args() + def setUp(self): super(IntegrationTestCase, self).setUp() self._stop_running_processes() From d31d05afd71838b6e7a7c871c72d20d36d765871 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Fri, 8 Nov 2024 22:10:56 -0600 Subject: [PATCH 09/10] Add st2tests.config.mq_opts_as_env_vars for itests Integration tests need to start subprocesses that use the same exchanges as the test. This matters when running under pantsbuild, because pants runs several instances of pytest in parallel. This PR prepares to add support, to disambiguate test runs--similar to the database logic--using the env var: ST2TESTS_PARALLEL_SLOT. In any case, when an integration test runs production code in a subprocess, the production code does not use-- and should not use--any ST2TESTS_* vars, meaning the subprocess ends up using what is configured in the conf file instead of the (planned) parallel-safe coordinator. Thanks to a new-ish oslo_config feature, we can now update config via env variables. So, make use of that in integration tests to override the conf-file provided values with test-provided values. --- st2api/tests/integration/test_gunicorn_configs.py | 2 ++ st2common/tests/integration/test_register_content_script.py | 1 + .../integration/test_service_setup_log_level_filtering.py | 1 + st2reactor/tests/integration/test_garbage_collector.py | 1 + st2reactor/tests/integration/test_sensor_container.py | 1 + st2tests/st2tests/config.py | 4 ++++ 6 files changed, 10 insertions(+) diff --git a/st2api/tests/integration/test_gunicorn_configs.py b/st2api/tests/integration/test_gunicorn_configs.py index c663aa83a7..8362a0e7f9 100644 --- a/st2api/tests/integration/test_gunicorn_configs.py +++ b/st2api/tests/integration/test_gunicorn_configs.py @@ -43,6 +43,7 @@ def test_st2api_wsgi_entry_point(self): env = os.environ.copy() env["ST2_CONFIG_PATH"] = ST2_CONFIG_PATH env.update(st2tests.config.db_opts_as_env_vars()) + env.update(st2tests.config.mq_opts_as_env_vars()) env.update(st2tests.config.coord_opts_as_env_vars()) process = subprocess.Popen(cmd, env=env, shell=True, preexec_fn=os.setsid) try: @@ -64,6 +65,7 @@ def test_st2auth(self): env = os.environ.copy() env["ST2_CONFIG_PATH"] = ST2_CONFIG_PATH env.update(st2tests.config.db_opts_as_env_vars()) + env.update(st2tests.config.mq_opts_as_env_vars()) env.update(st2tests.config.coord_opts_as_env_vars()) process = subprocess.Popen(cmd, env=env, shell=True, preexec_fn=os.setsid) try: diff --git a/st2common/tests/integration/test_register_content_script.py b/st2common/tests/integration/test_register_content_script.py index c19d91c2a1..9f3c73e467 100644 --- a/st2common/tests/integration/test_register_content_script.py +++ b/st2common/tests/integration/test_register_content_script.py @@ -212,5 +212,6 @@ def test_register_recreate_virtualenvs(self): def _run_command(cmd): env = os.environ.copy() env.update(st2tests.config.db_opts_as_env_vars()) + env.update(st2tests.config.mq_opts_as_env_vars()) env.update(st2tests.config.coord_opts_as_env_vars()) return run_command(cmd=cmd, env=env) diff --git a/st2common/tests/integration/test_service_setup_log_level_filtering.py b/st2common/tests/integration/test_service_setup_log_level_filtering.py index 03cfa1b6e5..869a26260c 100644 --- a/st2common/tests/integration/test_service_setup_log_level_filtering.py +++ b/st2common/tests/integration/test_service_setup_log_level_filtering.py @@ -231,6 +231,7 @@ def _start_process(config_path, env=None): cwd = os.path.abspath(cwd) env = env or os.environ.copy() env.update(st2tests.config.db_opts_as_env_vars()) + env.update(st2tests.config.mq_opts_as_env_vars()) env.update(st2tests.config.coord_opts_as_env_vars()) process = subprocess.Popen( cmd, diff --git a/st2reactor/tests/integration/test_garbage_collector.py b/st2reactor/tests/integration/test_garbage_collector.py index 7b8ff0dd10..4ce3d90afc 100644 --- a/st2reactor/tests/integration/test_garbage_collector.py +++ b/st2reactor/tests/integration/test_garbage_collector.py @@ -277,6 +277,7 @@ def _start_garbage_collector(self): subprocess = concurrency.get_subprocess_module() env = os.environ.copy() env.update(st2tests.config.db_opts_as_env_vars()) + env.update(st2tests.config.mq_opts_as_env_vars()) env.update(st2tests.config.coord_opts_as_env_vars()) process = subprocess.Popen( CMD_INQUIRY, diff --git a/st2reactor/tests/integration/test_sensor_container.py b/st2reactor/tests/integration/test_sensor_container.py index e7d38eda99..7c2a8d2767 100644 --- a/st2reactor/tests/integration/test_sensor_container.py +++ b/st2reactor/tests/integration/test_sensor_container.py @@ -246,6 +246,7 @@ def _start_sensor_container(self, cmd=DEFAULT_CMD): subprocess = concurrency.get_subprocess_module() env = os.environ.copy() env.update(st2tests.config.db_opts_as_env_vars()) + env.update(st2tests.config.mq_opts_as_env_vars()) env.update(st2tests.config.coord_opts_as_env_vars()) print("Using command: %s" % (" ".join(cmd))) process = subprocess.Popen( diff --git a/st2tests/st2tests/config.py b/st2tests/st2tests/config.py index 9a2042be4a..6a2e13ea89 100644 --- a/st2tests/st2tests/config.py +++ b/st2tests/st2tests/config.py @@ -107,6 +107,10 @@ def db_opts_as_env_vars() -> Dict[str, str]: return env +def mq_opts_as_env_vars() -> Dict[str, str]: + return {"ST2_MESSAGING__URL": CONF.messaging.url} + + def _override_common_opts(): packs_base_path = get_fixtures_packs_base_path() CONF.set_override(name="base_path", override=packs_base_path, group="system") From 4e8794c99a97fd92dda85f74ae0989e56dc715e4 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Tue, 12 Nov 2024 19:27:11 -0600 Subject: [PATCH 10/10] add changelog entry --- CHANGELOG.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index abd62f9cc8..aff3a80642 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -86,6 +86,13 @@ Added following to set system user to the current user: `export ST2TESTS_SYSTEM_USER=$(id -un)` #6242 Contributed by @cognifloyd +* Added experimental support for setting conf vars via environment variables. All settings in `st2.conf` can be + overriden via enviornment vars in the format: `ST2___