Skip to content

Commit a3200c9

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

File tree

2 files changed

+157
-0
lines changed

2 files changed

+157
-0
lines changed

Diff for: tests/e2e/local_interactive_sdk_kind_test.py

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from codeflare_sdk import Cluster, ClusterConfiguration
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+
24+
def run_local_interactives(self):
25+
ray_image = get_ray_image()
26+
27+
cluster_name = "test-ray-cluster"
28+
29+
cluster = Cluster(
30+
ClusterConfiguration(
31+
namespace=self.namespace,
32+
name=cluster_name,
33+
num_workers=1,
34+
min_cpus=1,
35+
max_cpus=1,
36+
min_memory=4,
37+
max_memory=4,
38+
num_gpus=0,
39+
image=ray_image,
40+
verify_tls=False,
41+
)
42+
)
43+
cluster.up()
44+
cluster.wait_ready()
45+
46+
ray.shutdown()
47+
ray.init(address=cluster.local_client_url(), logging_level="DEBUG")
48+
49+
@ray.remote
50+
def heavy_calculation_part(num_iterations):
51+
result = 0.0
52+
for i in range(num_iterations):
53+
for j in range(num_iterations):
54+
for k in range(num_iterations):
55+
result += math.sin(i) * math.cos(j) * math.tan(k)
56+
return result
57+
58+
@ray.remote
59+
def heavy_calculation(num_iterations):
60+
results = ray.get(
61+
[heavy_calculation_part.remote(num_iterations // 30) for _ in range(30)]
62+
)
63+
return sum(results)
64+
65+
ref = heavy_calculation.remote(3000)
66+
result = ray.get(ref)
67+
assert result == 1789.4644387076714
68+
ray.cancel(ref)
69+
ray.shutdown()
70+
71+
cluster.down()

Diff for: tests/e2e/local_interactive_sdk_oauth_test.py

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
29+
def run_local_interactives(self):
30+
ray_image = get_ray_image()
31+
32+
auth = TokenAuthentication(
33+
token=run_oc_command(["whoami", "--show-token=true"]),
34+
server=run_oc_command(["whoami", "--show-server=true"]),
35+
skip_tls=True,
36+
)
37+
auth.login()
38+
39+
cluster_name = "test-ray-cluster"
40+
41+
cluster = Cluster(
42+
ClusterConfiguration(
43+
namespace=self.namespace,
44+
name=cluster_name,
45+
num_workers=1,
46+
min_cpus=1,
47+
max_cpus=1,
48+
min_memory=4,
49+
max_memory=4,
50+
num_gpus=0,
51+
image=ray_image,
52+
verify_tls=False,
53+
)
54+
)
55+
cluster.up()
56+
cluster.wait_ready()
57+
58+
generate_cert.generate_tls_cert(cluster_name, self.namespace)
59+
generate_cert.export_env(cluster_name, self.namespace)
60+
61+
ray.shutdown()
62+
ray.init(address=cluster.local_client_url(), logging_level="DEBUG")
63+
64+
@ray.remote
65+
def heavy_calculation_part(num_iterations):
66+
result = 0.0
67+
for i in range(num_iterations):
68+
for j in range(num_iterations):
69+
for k in range(num_iterations):
70+
result += math.sin(i) * math.cos(j) * math.tan(k)
71+
return result
72+
73+
@ray.remote
74+
def heavy_calculation(num_iterations):
75+
results = ray.get(
76+
[heavy_calculation_part.remote(num_iterations // 30) for _ in range(30)]
77+
)
78+
return sum(results)
79+
80+
ref = heavy_calculation.remote(3000)
81+
result = ray.get(ref)
82+
assert result == 1789.4644387076714
83+
ray.cancel(ref)
84+
ray.shutdown()
85+
86+
cluster.down()

0 commit comments

Comments
 (0)