Skip to content

Commit

Permalink
[core][autoscaler] Fix env variable overwrite not able to be used if …
Browse files Browse the repository at this point in the history
…command itself uses the env (#37675) (#37676)

---------

Signed-off-by: rickyyx <rickyx@anyscale.com>
Co-authored-by: scv119 <scv119@gmail.com>
  • Loading branch information
rickyyx and scv119 committed Jul 22, 2023
1 parent 62b4a0a commit cdbee21
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions python/ray/autoscaler/_private/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,15 @@ def with_envs(cmds: List[str], kv: Dict[str, str]) -> str:
Example:
with_envs(["echo $FOO"], {"FOO": "BAR"})
-> ["FOO=BAR echo $FOO"]
-> ["export FOO=BAR; echo $FOO"]
"""
out_cmds = []
for cmd in cmds:
kv_str = ""
for k, v in kv.items():
kv_str += f"{k}={v} "
# We will need to do export here so that it works correctly with
# shell if the cmd args uses the argument.
kv_str += f"export {k}={v}; "

out_cmds.append(f"{kv_str}{cmd}")
return out_cmds
Expand Down
10 changes: 5 additions & 5 deletions python/ray/tests/test_autoscaler_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ def test_with_envs():
assert with_envs(
["echo $RAY_HEAD_IP", "ray start"], {"RAY_HEAD_IP": "127.0.0.0"}
) == [
"RAY_HEAD_IP=127.0.0.0 echo $RAY_HEAD_IP",
"RAY_HEAD_IP=127.0.0.0 ray start",
"export RAY_HEAD_IP=127.0.0.0; echo $RAY_HEAD_IP",
"export RAY_HEAD_IP=127.0.0.0; ray start",
]

assert with_head_node_ip(["echo $RAY_HEAD_IP"], "127.0.0.0") == [
"RAY_HEAD_IP=127.0.0.0 echo $RAY_HEAD_IP"
"export RAY_HEAD_IP=127.0.0.0; echo $RAY_HEAD_IP"
]

assert (
"RAY_HEAD_IP=456"
"export RAY_HEAD_IP=456"
in with_envs(
["echo $RAY_CLOUD_ID"], {"RAY_CLOUD_ID": "123", "RAY_HEAD_IP": "456"}
)[0]
)
assert (
"RAY_CLOUD_ID=123"
"export RAY_CLOUD_ID=123"
in with_envs(
["echo $RAY_CLOUD_ID"], {"RAY_CLOUD_ID": "123", "RAY_HEAD_IP": "456"}
)[0]
Expand Down

0 comments on commit cdbee21

Please sign in to comment.