Skip to content

Commit

Permalink
RHOAIENG-5344 - E2E test for Ray local interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
jiripetrlik committed May 20, 2024
1 parent 179fd75 commit a3200c9
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 0 deletions.
71 changes: 71 additions & 0 deletions tests/e2e/local_interactive_sdk_kind_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from codeflare_sdk import Cluster, ClusterConfiguration

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()

def run_local_interactives(self):
ray_image = get_ray_image()

cluster_name = "test-ray-cluster"

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()

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()
86 changes: 86 additions & 0 deletions tests/e2e/local_interactive_sdk_oauth_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
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()

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"

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()

0 comments on commit a3200c9

Please sign in to comment.