Change /tmp to platform-specific temporary directory (#7529)

This commit is contained in:
mehrdadn
2020-03-16 18:10:14 -07:00
committed by GitHub
parent 797e6cfc2a
commit a0700e2f86
27 changed files with 289 additions and 80 deletions
+66 -27
View File
@@ -4,6 +4,7 @@ import time
import pytest
import ray
import ray.ray_constants as ray_constants
import subprocess
from ray.cluster_utils import Cluster
@@ -12,7 +13,8 @@ def test_conn_cluster():
with pytest.raises(Exception) as exc_info:
ray.init(
address="127.0.0.1:6379",
plasma_store_socket_name="/tmp/this_should_fail")
plasma_store_socket_name=os.path.join(
ray.utils.get_user_temp_dir(), "this_should_fail"))
assert exc_info.value.args[0] == (
"When connecting to an existing cluster, "
"plasma_store_socket_name must not be provided.")
@@ -21,74 +23,111 @@ def test_conn_cluster():
with pytest.raises(Exception) as exc_info:
ray.init(
address="127.0.0.1:6379",
raylet_socket_name="/tmp/this_should_fail")
raylet_socket_name=os.path.join(ray.utils.get_user_temp_dir(),
"this_should_fail"))
assert exc_info.value.args[0] == (
"When connecting to an existing cluster, "
"raylet_socket_name must not be provided.")
# temp_dir
with pytest.raises(Exception) as exc_info:
ray.init(address="127.0.0.1:6379", temp_dir="/tmp/this_should_fail")
ray.init(
address="127.0.0.1:6379",
temp_dir=os.path.join(ray.utils.get_user_temp_dir(),
"this_should_fail"))
assert exc_info.value.args[0] == (
"When connecting to an existing cluster, "
"temp_dir must not be provided.")
def test_tempdir(shutdown_only):
shutil.rmtree("/tmp/ray", ignore_errors=True)
ray.init(temp_dir="/tmp/i_am_a_temp_dir")
shutil.rmtree(ray.utils.get_ray_temp_dir(), ignore_errors=True)
ray.init(
temp_dir=os.path.join(ray.utils.get_user_temp_dir(),
"i_am_a_temp_dir"))
assert os.path.exists(
"/tmp/i_am_a_temp_dir"), "Specified temp dir not found."
assert not os.path.exists("/tmp/ray"), "Default temp dir should not exist."
shutil.rmtree("/tmp/i_am_a_temp_dir", ignore_errors=True)
os.path.join(ray.utils.get_user_temp_dir(),
"i_am_a_temp_dir")), "Specified temp dir not found."
assert not os.path.exists(
ray.utils.get_ray_temp_dir()), ("Default temp dir should not exist.")
shutil.rmtree(
os.path.join(ray.utils.get_user_temp_dir(), "i_am_a_temp_dir"),
ignore_errors=True)
def test_tempdir_commandline():
shutil.rmtree("/tmp/ray", ignore_errors=True)
os.system("ray start --head --temp-dir=/tmp/i_am_a_temp_dir2")
shutil.rmtree(ray.utils.get_ray_temp_dir(), ignore_errors=True)
subprocess.check_call([
"ray", "start", "--head", "--temp-dir=" + os.path.join(
ray.utils.get_user_temp_dir(), "i_am_a_temp_dir2")
])
assert os.path.exists(
"/tmp/i_am_a_temp_dir2"), "Specified temp dir not found."
assert not os.path.exists("/tmp/ray"), "Default temp dir should not exist."
os.system("ray stop")
shutil.rmtree("/tmp/i_am_a_temp_dir2", ignore_errors=True)
os.path.join(ray.utils.get_user_temp_dir(),
"i_am_a_temp_dir2")), "Specified temp dir not found."
assert not os.path.exists(
ray.utils.get_ray_temp_dir()), "Default temp dir should not exist."
subprocess.check_call(["ray", "stop"])
shutil.rmtree(
os.path.join(ray.utils.get_user_temp_dir(), "i_am_a_temp_dir2"),
ignore_errors=True)
def test_raylet_socket_name(shutdown_only):
ray.init(raylet_socket_name="/tmp/i_am_a_temp_socket")
ray.init(
raylet_socket_name=os.path.join(ray.utils.get_user_temp_dir(),
"i_am_a_temp_socket"))
assert os.path.exists(
"/tmp/i_am_a_temp_socket"), "Specified socket path not found."
os.path.join(ray.utils.get_user_temp_dir(),
"i_am_a_temp_socket")), "Specified socket path not found."
ray.shutdown()
try:
os.remove("/tmp/i_am_a_temp_socket")
os.remove(
os.path.join(ray.utils.get_user_temp_dir(), "i_am_a_temp_socket"))
except OSError:
pass # It could have been removed by Ray.
cluster = Cluster(True)
cluster.add_node(raylet_socket_name="/tmp/i_am_a_temp_socket_2")
cluster.add_node(
raylet_socket_name=os.path.join(ray.utils.get_user_temp_dir(),
"i_am_a_temp_socket_2"))
assert os.path.exists(
"/tmp/i_am_a_temp_socket_2"), "Specified socket path not found."
os.path.join(
ray.utils.get_user_temp_dir(),
"i_am_a_temp_socket_2")), "Specified socket path not found."
cluster.shutdown()
try:
os.remove("/tmp/i_am_a_temp_socket_2")
os.remove(
os.path.join(ray.utils.get_user_temp_dir(),
"i_am_a_temp_socket_2"))
except OSError:
pass # It could have been removed by Ray.
def test_temp_plasma_store_socket(shutdown_only):
ray.init(plasma_store_socket_name="/tmp/i_am_a_temp_socket")
ray.init(
plasma_store_socket_name=os.path.join(ray.utils.get_user_temp_dir(),
"i_am_a_temp_socket"))
assert os.path.exists(
"/tmp/i_am_a_temp_socket"), "Specified socket path not found."
os.path.join(ray.utils.get_user_temp_dir(),
"i_am_a_temp_socket")), "Specified socket path not found."
ray.shutdown()
try:
os.remove("/tmp/i_am_a_temp_socket")
os.remove(
os.path.join(ray.utils.get_user_temp_dir(), "i_am_a_temp_socket"))
except OSError:
pass # It could have been removed by Ray.
cluster = Cluster(True)
cluster.add_node(plasma_store_socket_name="/tmp/i_am_a_temp_socket_2")
cluster.add_node(
plasma_store_socket_name=os.path.join(ray.utils.get_user_temp_dir(),
"i_am_a_temp_socket_2"))
assert os.path.exists(
"/tmp/i_am_a_temp_socket_2"), "Specified socket path not found."
os.path.join(
ray.utils.get_user_temp_dir(),
"i_am_a_temp_socket_2")), "Specified socket path not found."
cluster.shutdown()
try:
os.remove("/tmp/i_am_a_temp_socket_2")
os.remove(
os.path.join(ray.utils.get_user_temp_dir(),
"i_am_a_temp_socket_2"))
except OSError:
pass # It could have been removed by Ray.
@@ -135,7 +174,7 @@ def test_raylet_tempfiles(shutdown_only):
def test_tempdir_privilege(shutdown_only):
os.chmod("/tmp/ray", 0o000)
os.chmod(ray.utils.get_ray_temp_dir(), 0o000)
ray.init(num_cpus=1)
session_dir = ray.worker._global_node.get_session_dir_path()
assert os.path.exists(session_dir), "Specified socket path not found."