Exemplo n.º 1
0
def test_put_get(shutdown_only, tmp_path, storage_type):
    with simulate_storage(storage_type) as storage_uri:
        ray.init(storage=storage_uri, num_gpus=1)
        client = storage.get_client("ns")
        client2 = storage.get_client("ns2")
        assert client.get("foo/bar") is None
        client.put("foo/bar", b"hello")
        client.put("baz", b"goodbye")
        client2.put("baz", b"goodbye!")
        assert client.get("foo/bar") == b"hello"
        assert client.get("baz") == b"goodbye"
        assert client2.get("baz") == b"goodbye!"

        # delete file
        assert client.delete("baz")
        assert client.get("baz") is None
        assert not client.delete("non_existing")

        # delete dir
        n_files = 3
        for i in range(n_files):
            assert client2.get(f"foo/bar{i}") is None
        for i in range(n_files):
            client2.put(f"foo/bar{i}", f"hello{i}".encode())
        for i in range(n_files):
            assert client2.get(f"foo/bar{i}") == f"hello{i}".encode()
        assert client2.delete_dir("foo")
        for i in range(n_files):
            assert client2.get(f"foo/bar{i}") is None
        assert not client2.delete_dir("non_existing")
Exemplo n.º 2
0
def test_directory_traversal_attack(shutdown_only, storage_type):
    with simulate_storage(storage_type) as storage_uri:
        ray.init(storage=storage_uri, num_gpus=1)
        client = storage.get_client("foo")
        client.put("data", b"hello")
        client2 = storage.get_client("foo/bar")
        # Should not be able to access '../data'.
        with pytest.raises(ValueError):
            client2.get("../data")
Exemplo n.º 3
0
def test_directory_traversal_attack(shutdown_only, tmp_path):
    path = str(tmp_path)
    ray.init(storage=path, num_gpus=1)
    client = storage.get_client("foo")
    client.put("data", b"hello")
    client2 = storage.get_client("foo/bar")
    # Should not be able to access '../data'.
    with pytest.raises(ValueError):
        client2.get("../data")
Exemplo n.º 4
0
def test_put_get(shutdown_only, tmp_path):
    path = str(tmp_path)
    ray.init(storage=path, num_gpus=1)
    client = storage.get_client("ns")
    client2 = storage.get_client("ns2")
    client.put("foo/bar", b"hello")
    client.put("baz", b"goodbye")
    client2.put("baz", b"goodbye!")
    assert client.get("foo/bar") == b"hello"
    assert client.get("baz") == b"goodbye"
    assert client2.get("baz") == b"goodbye!"

    client.delete("baz")
    assert client.get("baz") is None
Exemplo n.º 5
0
    def __init__(self, workflow_id: str):
        from ray.workflow.api import _ensure_workflow_initialized

        _ensure_workflow_initialized()

        self._storage = storage.get_client(
            os.path.join(WORKFLOW_ROOT, workflow_id))
        self._workflow_id = workflow_id
Exemplo n.º 6
0
def test_get_info_basic(shutdown_only, storage_type):
    with simulate_storage(storage_type) as storage_uri:
        ray.init(storage=storage_uri, num_gpus=1)
        client = storage.get_client("ns")
        client.put("foo/bar1", b"hello")
        assert client.get_info("foo/bar1").base_name == "bar1"
        assert client.get_info("foo/bar2") is None
        assert client.get_info("foo").base_name == "foo"
        assert client.get_info("").base_name == "ns"
Exemplo n.º 7
0
def test_get_info_basic(shutdown_only, tmp_path):
    path = str(tmp_path)
    ray.init(storage=path, num_gpus=1)
    client = storage.get_client("ns")
    client.put("foo/bar1", b"hello")
    assert client.get_info("foo/bar1").base_name == "bar1"
    assert client.get_info("foo/bar2") is None
    assert client.get_info("foo").base_name == "foo"
    assert client.get_info("").base_name == "ns"
Exemplo n.º 8
0
def test_list_basic(shutdown_only, storage_type):
    with simulate_storage(storage_type) as storage_uri:
        ray.init(storage=storage_uri, num_gpus=1)
        client = storage.get_client("ns")
        client.put("foo/bar1", b"hello")
        client.put("foo/bar2", b"hello")
        client.put("baz/baz1", b"goodbye!")
        d1 = client.list("")
        assert sorted([f.base_name for f in d1]) == ["baz", "foo"], d1
        d2 = client.list("foo")
        assert sorted([f.base_name for f in d2]) == ["bar1", "bar2"], d2
        with pytest.raises(FileNotFoundError):
            client.list("invalid")
        with pytest.raises(NotADirectoryError):
            client.list("foo/bar1")
Exemplo n.º 9
0
 def __init__(self):
     self._storage = storage.get_client(WORKFLOW_ROOT)