-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RHOAIENG-5344 - E2E test for Ray local interactive (#532)
- Loading branch information
1 parent
b4c55e4
commit 54e90f5
Showing
4 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters