Skip to content

Commit 816d8dc

Browse files
committed
RHOAIENG-5344 - E2E test for Ray local interactive
1 parent 179fd75 commit 816d8dc

File tree

2 files changed

+166
-0
lines changed

2 files changed

+166
-0
lines changed

Diff for: tests/e2e/local_interactive_sdk_kind_test.py

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
from codeflare_sdk import Cluster, ClusterConfiguration, TokenAuthentication
2+
3+
import pytest
4+
import ray
5+
import math
6+
7+
from support import *
8+
9+
10+
@pytest.mark.kind
11+
class TestRayLocalInteractiveOauth:
12+
def setup_method(self):
13+
initialize_kubernetes_client(self)
14+
15+
def teardown_method(self):
16+
delete_namespace(self)
17+
18+
def test_local_interactives(self):
19+
self.setup_method()
20+
create_namespace(self)
21+
create_kueue_resources(self)
22+
self.run_local_interactives()
23+
delete_namespace(self)
24+
25+
def run_local_interactives(self):
26+
ray_image = get_ray_image()
27+
28+
cluster_name = "test-ray-cluster-li"
29+
30+
auth = TokenAuthentication(
31+
token=run_oc_command(["whoami", "--show-token=true"]),
32+
server=run_oc_command(["whoami", "--show-server=true"]),
33+
skip_tls=True,
34+
)
35+
auth.login()
36+
37+
cluster = Cluster(
38+
ClusterConfiguration(
39+
namespace=self.namespace,
40+
name=cluster_name,
41+
num_workers=1,
42+
min_cpus=1,
43+
max_cpus=1,
44+
min_memory=4,
45+
max_memory=4,
46+
num_gpus=0,
47+
image=ray_image,
48+
verify_tls=False,
49+
)
50+
)
51+
cluster.up()
52+
cluster.wait_ready()
53+
54+
ray.shutdown()
55+
ray.init(address=cluster.local_client_url(), logging_level="DEBUG")
56+
57+
@ray.remote
58+
def heavy_calculation_part(num_iterations):
59+
result = 0.0
60+
for i in range(num_iterations):
61+
for j in range(num_iterations):
62+
for k in range(num_iterations):
63+
result += math.sin(i) * math.cos(j) * math.tan(k)
64+
return result
65+
66+
@ray.remote
67+
def heavy_calculation(num_iterations):
68+
results = ray.get(
69+
[heavy_calculation_part.remote(num_iterations // 30) for _ in range(30)]
70+
)
71+
return sum(results)
72+
73+
ref = heavy_calculation.remote(3000)
74+
result = ray.get(ref)
75+
assert result == 1789.4644387076714
76+
ray.cancel(ref)
77+
ray.shutdown()
78+
79+
cluster.down()

Diff for: tests/e2e/local_interactive_sdk_oauth_test.py

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
from codeflare_sdk import (
2+
Cluster,
3+
ClusterConfiguration,
4+
TokenAuthentication,
5+
generate_cert,
6+
)
7+
8+
import math
9+
import pytest
10+
import ray
11+
12+
from support import *
13+
14+
15+
@pytest.mark.openshift
16+
class TestRayLocalInteractiveOauth:
17+
def setup_method(self):
18+
initialize_kubernetes_client(self)
19+
20+
def teardown_method(self):
21+
delete_namespace(self)
22+
23+
def test_local_interactives(self):
24+
self.setup_method()
25+
create_namespace(self)
26+
create_kueue_resources(self)
27+
self.run_local_interactives()
28+
delete_namespace(self)
29+
30+
def run_local_interactives(self):
31+
ray_image = get_ray_image()
32+
33+
auth = TokenAuthentication(
34+
token=run_oc_command(["whoami", "--show-token=true"]),
35+
server=run_oc_command(["whoami", "--show-server=true"]),
36+
skip_tls=True,
37+
)
38+
auth.login()
39+
40+
cluster_name = "test-ray-cluster-li"
41+
42+
cluster = Cluster(
43+
ClusterConfiguration(
44+
namespace=self.namespace,
45+
name=cluster_name,
46+
num_workers=1,
47+
min_cpus=1,
48+
max_cpus=1,
49+
min_memory=4,
50+
max_memory=4,
51+
num_gpus=0,
52+
image=ray_image,
53+
verify_tls=False,
54+
)
55+
)
56+
cluster.up()
57+
cluster.wait_ready()
58+
59+
generate_cert.generate_tls_cert(cluster_name, self.namespace)
60+
generate_cert.export_env(cluster_name, self.namespace)
61+
62+
ray.shutdown()
63+
ray.init(address=cluster.local_client_url(), logging_level="DEBUG")
64+
65+
@ray.remote
66+
def heavy_calculation_part(num_iterations):
67+
result = 0.0
68+
for i in range(num_iterations):
69+
for j in range(num_iterations):
70+
for k in range(num_iterations):
71+
result += math.sin(i) * math.cos(j) * math.tan(k)
72+
return result
73+
74+
@ray.remote
75+
def heavy_calculation(num_iterations):
76+
results = ray.get(
77+
[heavy_calculation_part.remote(num_iterations // 30) for _ in range(30)]
78+
)
79+
return sum(results)
80+
81+
ref = heavy_calculation.remote(3000)
82+
result = ray.get(ref)
83+
assert result == 1789.4644387076714
84+
ray.cancel(ref)
85+
ray.shutdown()
86+
87+
cluster.down()

0 commit comments

Comments
 (0)