1919import sys
2020import glob
2121
22+ import st2tests .config
2223from st2tests .base import IntegrationTestCase
2324from st2common .util .shell import run_command
2425from st2tests import config as test_config
@@ -56,7 +57,7 @@ def test_register_from_pack_success(self):
5657 "--register-runner-dir=%s" % (runner_dirs ),
5758 ]
5859 cmd = BASE_REGISTER_ACTIONS_CMD_ARGS + opts
59- exit_code , _ , stderr = run_command (cmd = cmd )
60+ exit_code , _ , stderr = self . _run_command (cmd = cmd )
6061 self .assertIn ("Registered 3 actions." , stderr )
6162 self .assertEqual (exit_code , 0 )
6263
@@ -71,7 +72,7 @@ def test_register_from_pack_fail_on_failure_pack_dir_doesnt_exist(self):
7172 "--register-no-fail-on-failure" ,
7273 ]
7374 cmd = BASE_REGISTER_ACTIONS_CMD_ARGS + opts
74- exit_code , _ , _ = run_command (cmd = cmd )
75+ exit_code , _ , _ = self . _run_command (cmd = cmd )
7576 self .assertEqual (exit_code , 0 )
7677
7778 # Fail on failure, should fail
@@ -81,7 +82,7 @@ def test_register_from_pack_fail_on_failure_pack_dir_doesnt_exist(self):
8182 "--register-fail-on-failure" ,
8283 ]
8384 cmd = BASE_REGISTER_ACTIONS_CMD_ARGS + opts
84- exit_code , _ , stderr = run_command (cmd = cmd )
85+ exit_code , _ , stderr = self . _run_command (cmd = cmd )
8586 self .assertIn ('Directory "doesntexistblah" doesn\' t exist' , stderr )
8687 self .assertEqual (exit_code , 1 )
8788
@@ -97,7 +98,7 @@ def test_register_from_pack_action_metadata_fails_validation(self):
9798 ]
9899
99100 cmd = BASE_REGISTER_ACTIONS_CMD_ARGS + opts
100- exit_code , _ , stderr = run_command (cmd = cmd )
101+ exit_code , _ , stderr = self . _run_command (cmd = cmd )
101102 self .assertIn ("Registered 0 actions." , stderr )
102103 self .assertEqual (exit_code , 0 )
103104
@@ -109,7 +110,7 @@ def test_register_from_pack_action_metadata_fails_validation(self):
109110 "--register-runner-dir=%s" % (runner_dirs ),
110111 ]
111112 cmd = BASE_REGISTER_ACTIONS_CMD_ARGS + opts
112- exit_code , _ , stderr = run_command (cmd = cmd )
113+ exit_code , _ , stderr = self . _run_command (cmd = cmd )
113114 self .assertIn ("object has no attribute 'get'" , stderr )
114115 self .assertEqual (exit_code , 1 )
115116
@@ -127,7 +128,7 @@ def test_register_from_packs_doesnt_throw_on_missing_pack_resource_folder(self):
127128 "-v" ,
128129 "--register-sensors" ,
129130 ]
130- exit_code , _ , stderr = run_command (cmd = cmd )
131+ exit_code , _ , stderr = self . _run_command (cmd = cmd )
131132 self .assertIn ("Registered 0 sensors." , stderr , "Actual stderr: %s" % (stderr ))
132133 self .assertEqual (exit_code , 0 )
133134
@@ -139,7 +140,7 @@ def test_register_from_packs_doesnt_throw_on_missing_pack_resource_folder(self):
139140 "--register-all" ,
140141 "--register-no-fail-on-failure" ,
141142 ]
142- exit_code , _ , stderr = run_command (cmd = cmd )
143+ exit_code , _ , stderr = self . _run_command (cmd = cmd )
143144 self .assertIn ("Registered 0 actions." , stderr )
144145 self .assertIn ("Registered 0 sensors." , stderr )
145146 self .assertIn ("Registered 0 rules." , stderr )
@@ -155,7 +156,7 @@ def test_register_all_and_register_setup_virtualenvs(self):
155156 "--register-setup-virtualenvs" ,
156157 "--register-no-fail-on-failure" ,
157158 ]
158- exit_code , stdout , stderr = run_command (cmd = cmd )
159+ exit_code , stdout , stderr = self . _run_command (cmd = cmd )
159160 self .assertIn ("Registering actions" , stderr , "Actual stderr: %s" % (stderr ))
160161 self .assertIn ("Registering rules" , stderr )
161162 self .assertIn ("Setup virtualenv for %s pack(s)" % ("1" ), stderr )
@@ -170,7 +171,7 @@ def test_register_setup_virtualenvs(self):
170171 "--register-setup-virtualenvs" ,
171172 "--register-no-fail-on-failure" ,
172173 ]
173- exit_code , stdout , stderr = run_command (cmd = cmd )
174+ exit_code , stdout , stderr = self . _run_command (cmd = cmd )
174175
175176 self .assertIn ('Setting up virtualenv for pack "dummy_pack_1"' , stderr )
176177 self .assertIn ("Setup virtualenv for 1 pack(s)" , stderr )
@@ -186,7 +187,7 @@ def test_register_recreate_virtualenvs(self):
186187 "--register-setup-virtualenvs" ,
187188 "--register-no-fail-on-failure" ,
188189 ]
189- exit_code , stdout , stderr = run_command (cmd = cmd )
190+ exit_code , stdout , stderr = self . _run_command (cmd = cmd )
190191
191192 self .assertIn ('Setting up virtualenv for pack "dummy_pack_1"' , stderr )
192193 self .assertIn ("Setup virtualenv for 1 pack(s)" , stderr )
@@ -200,9 +201,17 @@ def test_register_recreate_virtualenvs(self):
200201 "--register-recreate-virtualenvs" ,
201202 "--register-no-fail-on-failure" ,
202203 ]
203- exit_code , stdout , stderr = run_command (cmd = cmd )
204+ exit_code , stdout , stderr = self . _run_command (cmd = cmd )
204205
205206 self .assertIn ('Setting up virtualenv for pack "dummy_pack_1"' , stderr )
206207 self .assertIn ("Virtualenv successfully removed." , stderr )
207208 self .assertIn ("Setup virtualenv for 1 pack(s)" , stderr )
208209 self .assertEqual (exit_code , 0 )
210+
211+ @staticmethod
212+ def _run_command (cmd ):
213+ env = os .environ .copy ()
214+ env .update (st2tests .config .db_opts_as_env_vars ())
215+ env .update (st2tests .config .mq_opts_as_env_vars ())
216+ env .update (st2tests .config .coord_opts_as_env_vars ())
217+ return run_command (cmd = cmd , env = env )
0 commit comments