From 09a2a6a14161293964cd2a574c5ef55d3247ed2f Mon Sep 17 00:00:00 2001 From: Ruiyang Wang Date: Wed, 14 Jun 2023 14:32:45 -0700 Subject: [PATCH 1/6] Check that temp_dir must be absolute path. Signed-off-by: Ruiyang Wang --- python/ray/_private/parameter.py | 5 ++++- python/ray/_private/worker.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/python/ray/_private/parameter.py b/python/ray/_private/parameter.py index ec61cff7702d0..a05230f11bf7d 100644 --- a/python/ray/_private/parameter.py +++ b/python/ray/_private/parameter.py @@ -96,7 +96,7 @@ class RayParams: raylet_socket_name: If provided, it will specify the socket path used by the raylet process. temp_dir: If provided, it will specify the root temporary - directory for the Ray process. + directory for the Ray process. Must be an absolute path. storage: Specify a URI for persistent cluster-wide storage. This storage path must be accessible by all nodes of the cluster, otherwise an error will be raised. @@ -428,6 +428,9 @@ def build_error(resource, alternative): "serialization. Upgrade numpy if using with ray." ) + if self.temp_dir is not None and not os.path.isabs(self.temp_dir): + raise ValueError("temp_dir must be absolute path or None.") + def _format_ports(self, pre_selected_ports): """Format the pre-selected ports information to be more human-readable.""" ports = pre_selected_ports.copy() diff --git a/python/ray/_private/worker.py b/python/ray/_private/worker.py index 9f5570a88b9da..e531437101331 100644 --- a/python/ray/_private/worker.py +++ b/python/ray/_private/worker.py @@ -1240,8 +1240,8 @@ def init( _redis_password: Prevents external clients without the password from connecting to Redis if provided. _temp_dir: If provided, specifies the root temporary - directory for the Ray process. Defaults to an OS-specific - conventional location, e.g., "/tmp/ray". + directory for the Ray process. Must be an absolute path. Defaults to an + OS-specific conventional location, e.g., "/tmp/ray". _metrics_export_port: Port number Ray exposes system metrics through a Prometheus endpoint. It is currently under active development, and the API is subject to change. From 5d4d0544b95119196b6e4ff49674677941269372 Mon Sep 17 00:00:00 2001 From: Ruiyang Wang Date: Wed, 14 Jun 2023 15:54:49 -0700 Subject: [PATCH 2/6] add test. Signed-off-by: Ruiyang Wang --- python/ray/tests/test_basic.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/python/ray/tests/test_basic.py b/python/ray/tests/test_basic.py index d7a9a7919e855..4e12e632a45fb 100644 --- a/python/ray/tests/test_basic.py +++ b/python/ray/tests/test_basic.py @@ -1114,6 +1114,12 @@ def test_import_ray_does_not_import_grpc(): import grpc # noqa: F401 +# https://github.com/ray-project/ray/issues/36431 +def test_temp_dir_must_be_absolute(): + # This test fails with the flag set to false. + with pytest.Raises(ValueError): + ray.init(_temp_dir='relative_path') + if __name__ == "__main__": if os.environ.get("PARALLEL_CI"): sys.exit(pytest.main(["-n", "auto", "--boxed", "-vs", __file__])) From c4b4ae8bda3198d629eb0667edf53ace3896cffe Mon Sep 17 00:00:00 2001 From: Ruiyang Wang Date: Wed, 14 Jun 2023 16:24:41 -0700 Subject: [PATCH 3/6] fix test typo Signed-off-by: Ruiyang Wang --- python/ray/tests/test_basic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/ray/tests/test_basic.py b/python/ray/tests/test_basic.py index 4e12e632a45fb..a4acb9573bbb0 100644 --- a/python/ray/tests/test_basic.py +++ b/python/ray/tests/test_basic.py @@ -1115,9 +1115,9 @@ def test_import_ray_does_not_import_grpc(): # https://github.com/ray-project/ray/issues/36431 -def test_temp_dir_must_be_absolute(): +def test_temp_dir_must_be_absolute(shutdown_only): # This test fails with the flag set to false. - with pytest.Raises(ValueError): + with pytest.raises(ValueError): ray.init(_temp_dir='relative_path') if __name__ == "__main__": From 7edf05c0e2c05a2327581299d81d9e51f7a601e6 Mon Sep 17 00:00:00 2001 From: Ruiyang Wang Date: Thu, 15 Jun 2023 12:44:33 -0700 Subject: [PATCH 4/6] update test comment. Signed-off-by: Ruiyang Wang --- python/ray/tests/test_basic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/ray/tests/test_basic.py b/python/ray/tests/test_basic.py index a4acb9573bbb0..5335009d19d01 100644 --- a/python/ray/tests/test_basic.py +++ b/python/ray/tests/test_basic.py @@ -1116,7 +1116,7 @@ def test_import_ray_does_not_import_grpc(): # https://github.com/ray-project/ray/issues/36431 def test_temp_dir_must_be_absolute(shutdown_only): - # This test fails with the flag set to false. + # This test fails with a relative path _temp_dir. with pytest.raises(ValueError): ray.init(_temp_dir='relative_path') From dee1b0ca8fa2c6bc5c82d131cb8eb5940a2c77ca Mon Sep 17 00:00:00 2001 From: Ruiyang Wang Date: Thu, 15 Jun 2023 14:30:40 -0700 Subject: [PATCH 5/6] move test to test_ray_init_2.py Signed-off-by: Ruiyang Wang --- python/ray/tests/test_basic.py | 6 ------ python/ray/tests/test_ray_init_2.py | 9 ++++++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/python/ray/tests/test_basic.py b/python/ray/tests/test_basic.py index 5335009d19d01..d7a9a7919e855 100644 --- a/python/ray/tests/test_basic.py +++ b/python/ray/tests/test_basic.py @@ -1114,12 +1114,6 @@ def test_import_ray_does_not_import_grpc(): import grpc # noqa: F401 -# https://github.com/ray-project/ray/issues/36431 -def test_temp_dir_must_be_absolute(shutdown_only): - # This test fails with a relative path _temp_dir. - with pytest.raises(ValueError): - ray.init(_temp_dir='relative_path') - if __name__ == "__main__": if os.environ.get("PARALLEL_CI"): sys.exit(pytest.main(["-n", "auto", "--boxed", "-vs", __file__])) diff --git a/python/ray/tests/test_ray_init_2.py b/python/ray/tests/test_ray_init_2.py index 3f37dd7013083..7375c64b48c32 100644 --- a/python/ray/tests/test_ray_init_2.py +++ b/python/ray/tests/test_ray_init_2.py @@ -124,7 +124,7 @@ def test_hosted_external_dashboard_url(override_url, shutdown_only, monkeypatch) expected_dashboard_url = "127.0.0.1:8265" elif "://" in override_url: # External dashboard url with https protocol included - expected_dashboard_url = override_url[override_url.index("://") + 3 :] + expected_dashboard_url = override_url[override_url.index("://") + 3:] else: # External dashboard url with no protocol expected_dashboard_url = override_url @@ -325,6 +325,13 @@ def test_get_ray_address_from_environment(monkeypatch): ) +# https://github.com/ray-project/ray/issues/36431 +def test_temp_dir_must_be_absolute(shutdown_only): + # This test fails with a relative path _temp_dir. + with pytest.raises(ValueError): + ray.init(_temp_dir='relative_path') + + if __name__ == "__main__": import sys From 2533f943c1c18f5b63ee1354e4b1b1eca1262270 Mon Sep 17 00:00:00 2001 From: Ruiyang Wang Date: Thu, 15 Jun 2023 15:02:38 -0700 Subject: [PATCH 6/6] fix lint Signed-off-by: Ruiyang Wang --- python/ray/tests/test_ray_init_2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/ray/tests/test_ray_init_2.py b/python/ray/tests/test_ray_init_2.py index 7375c64b48c32..cd3e3f95f69c2 100644 --- a/python/ray/tests/test_ray_init_2.py +++ b/python/ray/tests/test_ray_init_2.py @@ -124,7 +124,7 @@ def test_hosted_external_dashboard_url(override_url, shutdown_only, monkeypatch) expected_dashboard_url = "127.0.0.1:8265" elif "://" in override_url: # External dashboard url with https protocol included - expected_dashboard_url = override_url[override_url.index("://") + 3:] + expected_dashboard_url = override_url[override_url.index("://") + 3 :] else: # External dashboard url with no protocol expected_dashboard_url = override_url @@ -329,7 +329,7 @@ def test_get_ray_address_from_environment(monkeypatch): def test_temp_dir_must_be_absolute(shutdown_only): # This test fails with a relative path _temp_dir. with pytest.raises(ValueError): - ray.init(_temp_dir='relative_path') + ray.init(_temp_dir="relative_path") if __name__ == "__main__":