Skip to content

Commit b30534d

Browse files
authored
[RAPTOR-15444] fix ADDRESS env var assignment from cli param (#1807)
1 parent ba297e3 commit b30534d

File tree

5 files changed

+171
-140
lines changed

5 files changed

+171
-140
lines changed

custom_model_runner/datarobot_drum/drum/entry_point.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
from datarobot_drum.drum.gunicorn.run_gunicorn import main_gunicorn
22
from datarobot_drum.drum.main import main
3-
import sys
43
from datarobot_drum import RuntimeParameters
4+
from datarobot_drum.drum.utils.setup import setup_options
55

6+
from datarobot_drum.drum.enum import ArgumentsOptions
67

7-
def run_drum_server():
8-
cmd_args = sys.argv
9-
is_server = False
10-
if len(cmd_args) > 1 and cmd_args[1] == "server":
11-
is_server = True
128

9+
def run_drum_server():
10+
options = setup_options()
1311
if (
14-
RuntimeParameters.has("DRUM_SERVER_TYPE")
12+
options.subparser_name == ArgumentsOptions.SERVER
13+
and RuntimeParameters.has("DRUM_SERVER_TYPE")
1514
and str(RuntimeParameters.get("DRUM_SERVER_TYPE")).lower() == "gunicorn"
16-
and is_server
1715
):
1816
main_gunicorn()
1917
else:

custom_model_runner/datarobot_drum/drum/gunicorn/gunicorn.conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
if temp_loglevel in {"debug", "info", "warning", "error", "critical"}:
6767
loglevel = temp_loglevel
6868

69-
bind = os.environ.get("ADDRESS", "0.0.0.0:8080")
69+
bind = os.environ["ADDRESS"]
7070
# loglevel = "info"
7171
accesslog = "-"
7272
access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'

custom_model_runner/datarobot_drum/drum/utils/setup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Released under the terms of DataRobot Tool and Utility Agreement.
66
"""
77

8+
import os
89
import sys
910

1011
from datarobot_drum import RuntimeParameters
@@ -31,7 +32,6 @@ def setup_options(args=None):
3132
Parsed command line options as an argparse.Namespace object.
3233
"""
3334
arg_parser = CMRunnerArgsRegistry.get_arg_parser()
34-
3535
try:
3636
import argcomplete
3737
except ImportError:
@@ -48,6 +48,11 @@ def setup_options(args=None):
4848

4949
options = arg_parser.parse_args(args)
5050

51+
# Override env var from CLI parameter.
52+
# Now only ADDRESS is supported.
53+
if getattr(options, "address", None):
54+
os.environ["ADDRESS"] = options.address
55+
5156
"""Set max workers from runtime parameters if available."""
5257
if RuntimeParameters.has("CUSTOM_MODEL_WORKERS"):
5358
options.max_workers = RuntimeParameters.get("CUSTOM_MODEL_WORKERS")

tests/functional/test_runtime_parameters.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ def _test_custom_model_with_runtime_params(
222222
if docker:
223223
cmd += " --docker {} --verbose ".format(docker)
224224

225-
_, stdout, _ = _exec_shell_cmd(cmd, err_msg=None, assert_if_fail=False, env=env)
226-
return stdout
225+
_, stdout, stderr = _exec_shell_cmd(cmd, err_msg=None, assert_if_fail=False, env=env)
226+
return stdout, stderr
227227

228228
@classmethod
229229
def _setup_runtime_parameters(
@@ -251,20 +251,20 @@ def _setup_runtime_parameters(
251251
def test_runtime_parameters_invalid_yaml(
252252
self, resources, tmp_path, runtime_param_values_stream, use_runtime_params_env_var
253253
):
254-
stdout = self._test_custom_model_with_runtime_params(
254+
stdout, stderr = self._test_custom_model_with_runtime_params(
255255
resources,
256256
tmp_path,
257257
runtime_param_values_stream,
258258
is_invalid_yaml=True,
259259
use_runtime_params_env_var=use_runtime_params_env_var,
260260
)
261-
assert "Invalid runtime parameter values YAML content!" in stdout
261+
assert "Invalid runtime parameter values YAML content!" in stdout + stderr
262262

263263
@pytest.mark.parametrize("use_runtime_params_env_var", [True, False])
264264
def test_runtime_parameters_missing_attr(
265265
self, resources, tmp_path, runtime_param_values_stream, use_runtime_params_env_var
266266
):
267-
stdout = self._test_custom_model_with_runtime_params(
267+
stdout, stderr = self._test_custom_model_with_runtime_params(
268268
resources,
269269
tmp_path,
270270
runtime_param_values_stream,
@@ -273,27 +273,27 @@ def test_runtime_parameters_missing_attr(
273273
)
274274
assert re.search(
275275
r".*Failed to load runtime parameter.*{\\'credentialType\\': DataError\(\\'is required\\'\)}.*",
276-
stdout,
276+
stdout + stderr,
277277
)
278278

279279
def test_runtime_parameters_boolean_invalid(
280280
self, resources, tmp_path, runtime_param_values_stream
281281
):
282-
stderr = self._test_custom_model_with_runtime_params(
282+
stdout, stderr = self._test_custom_model_with_runtime_params(
283283
resources, tmp_path, runtime_param_values_stream, bool_var_value="text"
284284
)
285285
assert re.search(
286286
r".*Failed to load runtime parameter.*value should be True or False.*",
287-
stderr,
287+
stdout + stderr,
288288
)
289289

290290
def test_runtime_parameters_numeric_invalid(
291291
self, resources, tmp_path, runtime_param_values_stream
292292
):
293-
stderr = self._test_custom_model_with_runtime_params(
293+
stdout, stderr = self._test_custom_model_with_runtime_params(
294294
resources, tmp_path, runtime_param_values_stream, numeric_var_value="text"
295295
)
296296
assert re.search(
297297
r".*Failed to load runtime parameter.*value can.*t be converted to float.*",
298-
stderr,
298+
stdout + stderr,
299299
)

0 commit comments

Comments
 (0)