Skip to content

Commit

Permalink
RHOAIENG-5344 - E2E test for Ray local interactive (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiripetrlik authored May 22, 2024
1 parent b4c55e4 commit 54e90f5
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 0 deletions.
85 changes: 85 additions & 0 deletions tests/e2e/local_interactive_sdk_kind_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from codeflare_sdk import (
Cluster,
ClusterConfiguration,
TokenAuthentication,
generate_cert,
)

import pytest
import ray
import math

from support import *


@pytest.mark.kind
class TestRayLocalInteractiveOauth:
def setup_method(self):
initialize_kubernetes_client(self)

def teardown_method(self):
delete_namespace(self)

def test_local_interactives(self):
self.setup_method()
create_namespace(self)
create_kueue_resources(self)
self.run_local_interactives()
self.teardown_method()

def run_local_interactives(self):
ray_image = get_ray_image()

cluster_name = "test-ray-cluster-li"

cluster = Cluster(
ClusterConfiguration(
name=cluster_name,
namespace=self.namespace,
num_workers=1,
head_cpus="500m",
head_memory=2,
min_cpus="500m",
max_cpus=1,
min_memory=1,
max_memory=2,
num_gpus=0,
image=ray_image,
write_to_file=True,
verify_tls=False,
)
)
cluster.up()
cluster.wait_ready()

generate_cert.generate_tls_cert(cluster_name, self.namespace)
generate_cert.export_env(cluster_name, self.namespace)

print(cluster.local_client_url())

ray.shutdown()
ray.init(address=cluster.local_client_url(), logging_level="DEBUG")

@ray.remote
def heavy_calculation_part(num_iterations):
result = 0.0
for i in range(num_iterations):
for j in range(num_iterations):
for k in range(num_iterations):
result += math.sin(i) * math.cos(j) * math.tan(k)
return result

@ray.remote
def heavy_calculation(num_iterations):
results = ray.get(
[heavy_calculation_part.remote(num_iterations // 30) for _ in range(30)]
)
return sum(results)

ref = heavy_calculation.remote(3000)
result = ray.get(ref)
assert result == 1789.4644387076714
ray.cancel(ref)
ray.shutdown()

cluster.down()
87 changes: 87 additions & 0 deletions tests/e2e/local_interactive_sdk_oauth_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
from codeflare_sdk import (
Cluster,
ClusterConfiguration,
TokenAuthentication,
generate_cert,
)

import math
import pytest
import ray

from support import *


@pytest.mark.openshift
class TestRayLocalInteractiveOauth:
def setup_method(self):
initialize_kubernetes_client(self)

def teardown_method(self):
delete_namespace(self)

def test_local_interactives(self):
self.setup_method()
create_namespace(self)
create_kueue_resources(self)
self.run_local_interactives()
self.teardown_method()

def run_local_interactives(self):
ray_image = get_ray_image()

auth = TokenAuthentication(
token=run_oc_command(["whoami", "--show-token=true"]),
server=run_oc_command(["whoami", "--show-server=true"]),
skip_tls=True,
)
auth.login()

cluster_name = "test-ray-cluster-li"

cluster = Cluster(
ClusterConfiguration(
namespace=self.namespace,
name=cluster_name,
num_workers=1,
min_cpus=1,
max_cpus=1,
min_memory=4,
max_memory=4,
num_gpus=0,
image=ray_image,
verify_tls=False,
)
)
cluster.up()
cluster.wait_ready()

generate_cert.generate_tls_cert(cluster_name, self.namespace)
generate_cert.export_env(cluster_name, self.namespace)

ray.shutdown()
ray.init(address=cluster.local_client_url(), logging_level="DEBUG")

@ray.remote
def heavy_calculation_part(num_iterations):
result = 0.0
for i in range(num_iterations):
for j in range(num_iterations):
for k in range(num_iterations):
result += math.sin(i) * math.cos(j) * math.tan(k)
return result

@ray.remote
def heavy_calculation(num_iterations):
results = ray.get(
[heavy_calculation_part.remote(num_iterations // 30) for _ in range(30)]
)
return sum(results)

ref = heavy_calculation.remote(3000)
result = ray.get(ref)
assert result == 1789.4644387076714
ray.cancel(ref)
ray.shutdown()

cluster.down()
1 change: 1 addition & 0 deletions tests/e2e/mnist_raycluster_sdk_kind_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def test_mnist_ray_cluster_sdk_kind(self):
create_namespace(self)
create_kueue_resources(self)
self.run_mnist_raycluster_sdk_kind()
self.teardown_method()

def run_mnist_raycluster_sdk_kind(self):
ray_image = get_ray_image()
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/mnist_raycluster_sdk_oauth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def test_mnist_ray_cluster_sdk_auth(self):
create_namespace(self)
create_kueue_resources(self)
self.run_mnist_raycluster_sdk_oauth()
self.teardown_method()

def run_mnist_raycluster_sdk_oauth(self):
ray_image = get_ray_image()
Expand Down

0 comments on commit 54e90f5

Please sign in to comment.