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