Skip to content

Commit b44494b

Browse files
authored
[release test] move command_env getter into AnyscaleJobRunner (#60272)
so that it is not going back and forth between the implementation and the abstract class, and not implemented as a property. Signed-off-by: Lonnie Liu <95255098+aslonnie@users.noreply.github.com>
1 parent 9c9a996 commit b44494b

File tree

2 files changed

+33
-46
lines changed

2 files changed

+33
-46
lines changed

release/ray_release/command_runner/anyscale_job_runner.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from ray_release.file_manager.job_file_manager import JobFileManager
3030
from ray_release.job_manager.anyscale_job_manager import AnyscaleJobManager
3131
from ray_release.logger import logger
32+
from ray_release.reporter.artifacts import DEFAULT_ARTIFACTS_DIR
3233
from ray_release.util import (
3334
AZURE_CLOUD_STORAGE,
3435
AZURE_STORAGE_CONTAINER,
@@ -63,6 +64,24 @@ def _get_env_str(env: Dict[str, str]) -> str:
6364

6465

6566
class AnyscaleJobRunner(CommandRunner):
67+
# the directory for runners to dump files to (on buildkite runner instances).
68+
# Write to this directory. run_release_tests.sh will ensure that the content
69+
# shows up under buildkite job's "Artifacts" UI tab.
70+
_DEFAULT_ARTIFACTS_DIR = DEFAULT_ARTIFACTS_DIR
71+
72+
# the artifact file name put under s3 bucket root.
73+
# AnyscalejobWrapper will upload user generated artifact to this path
74+
# and AnyscaleJobRunner will then download from there.
75+
_USER_GENERATED_ARTIFACT = "user_generated_artifact"
76+
77+
# the path where result json will be written to on both head node
78+
# as well as the relative path where result json will be uploaded to on s3.
79+
_RESULT_OUTPUT_JSON = "/tmp/release_test_out.json"
80+
81+
# the path where output json will be written to on both head node
82+
# as well as the relative path where metrics json will be uploaded to on s3.
83+
_METRICS_OUTPUT_JSON = "/tmp/metrics_test_out.json"
84+
6685
def __init__(
6786
self,
6887
cluster_manager: ClusterManager,
@@ -223,17 +242,22 @@ def _handle_command_output(
223242
f"with error:\n{error}\n"
224243
)
225244

226-
@property
227-
def command_env(self):
228-
env = super().command_env
229-
# Make sure we don't buffer stdout so we don't lose any logs.
230-
env["PYTHONUNBUFFERED"] = "1"
231-
return env
245+
def _get_full_command_env(self, env: Optional[Dict[str, str]] = None):
246+
full_env = {
247+
"TEST_OUTPUT_JSON": self._RESULT_OUTPUT_JSON,
248+
"METRICS_OUTPUT_JSON": self._METRICS_OUTPUT_JSON,
249+
"USER_GENERATED_ARTIFACT": self._USER_GENERATED_ARTIFACT,
250+
"BUILDKITE_BRANCH": os.environ.get("BUILDKITE_BRANCH", ""),
251+
"PYTHONUNBUFFERED": "1",
252+
}
253+
if env:
254+
full_env.update(env)
255+
return full_env
232256

233257
def run_command(
234258
self,
235259
command: str,
236-
env: Optional[Dict] = None,
260+
env: Optional[Dict[str, str]] = None,
237261
timeout: float = 3600.0,
238262
raise_on_timeout: bool = True,
239263
) -> float:
@@ -242,7 +266,7 @@ def run_command(
242266
# Convert the prepare commands, envs and timeouts into shell-compliant
243267
# strings that can be passed to the wrapper script
244268
for prepare_command, prepare_env, prepare_timeout in self.prepare_commands:
245-
prepare_env = self.get_full_command_env(prepare_env)
269+
prepare_env = self._get_full_command_env(prepare_env)
246270
env_str = _get_env_str(prepare_env)
247271
prepare_command_strs.append(f"{env_str} {prepare_command}")
248272
prepare_command_timeouts.append(prepare_timeout)
@@ -254,7 +278,7 @@ def run_command(
254278
shlex.quote(str(x)) for x in prepare_command_timeouts
255279
)
256280

257-
full_env = self.get_full_command_env(env)
281+
full_env = self._get_full_command_env(env)
258282

259283
no_raise_on_timeout_str = (
260284
" --test-no-raise-on-timeout" if not raise_on_timeout else ""

release/ray_release/command_runner/command_runner.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,16 @@
11
import abc
2-
import os
32
from typing import Any, Dict, Optional
43

54
from click.exceptions import ClickException
65

76
from ray_release.cluster_manager.cluster_manager import ClusterManager
87
from ray_release.logger import logger
9-
from ray_release.reporter.artifacts import DEFAULT_ARTIFACTS_DIR
108
from ray_release.util import exponential_backoff_retry
119

1210

1311
class CommandRunner(abc.ABC):
1412
"""This is run on Buildkite runners."""
1513

16-
# the directory for runners to dump files to (on buildkite runner instances).
17-
# Write to this directory. run_release_tests.sh will ensure that the content
18-
# shows up under buildkite job's "Artifacts" UI tab.
19-
_DEFAULT_ARTIFACTS_DIR = DEFAULT_ARTIFACTS_DIR
20-
21-
# the artifact file name put under s3 bucket root.
22-
# AnyscalejobWrapper will upload user generated artifact to this path
23-
# and AnyscaleJobRunner will then download from there.
24-
_USER_GENERATED_ARTIFACT = "user_generated_artifact"
25-
26-
# the path where result json will be written to on both head node
27-
# as well as the relative path where result json will be uploaded to on s3.
28-
_RESULT_OUTPUT_JSON = "/tmp/release_test_out.json"
29-
30-
# the path where output json will be written to on both head node
31-
# as well as the relative path where metrics json will be uploaded to on s3.
32-
_METRICS_OUTPUT_JSON = "/tmp/metrics_test_out.json"
33-
3414
def __init__(
3515
self,
3616
cluster_manager: ClusterManager,
@@ -40,23 +20,6 @@ def __init__(
4020
self.cluster_manager = cluster_manager
4121
self.working_dir = working_dir
4222

43-
@property
44-
def command_env(self):
45-
return {
46-
"TEST_OUTPUT_JSON": self._RESULT_OUTPUT_JSON,
47-
"METRICS_OUTPUT_JSON": self._METRICS_OUTPUT_JSON,
48-
"USER_GENERATED_ARTIFACT": self._USER_GENERATED_ARTIFACT,
49-
"BUILDKITE_BRANCH": os.environ.get("BUILDKITE_BRANCH", ""),
50-
}
51-
52-
def get_full_command_env(self, env: Optional[Dict] = None):
53-
full_env = self.command_env.copy()
54-
55-
if env:
56-
full_env.update(env)
57-
58-
return full_env
59-
6023
def prepare_remote_env(self):
6124
"""Prepare remote environment, e.g. upload files."""
6225
raise NotImplementedError

0 commit comments

Comments
 (0)