Skip to content

Commit d494d2e

Browse files
committed
Add RayCLuster Oauth Authentication test
1 parent 62be50e commit d494d2e

File tree

3 files changed

+542
-0
lines changed

3 files changed

+542
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import sys
2+
import os
3+
4+
from time import sleep
5+
6+
from torchx.specs.api import AppState, is_terminal
7+
8+
from codeflare_sdk.cluster.cluster import Cluster, ClusterConfiguration
9+
from codeflare_sdk.job.jobs import DDPJobDefinition
10+
from codeflare_sdk.cluster.auth import TokenAuthentication
11+
12+
namespace = sys.argv[1]
13+
ray_image = os.getenv("RAY_IMAGE")
14+
isAuthLoginEnable = os.getenv("OAUTH_LOGIN")
15+
cluster_token = os.getenv("CLUSTER_TOKEN")
16+
server_url = os.getenv("SERVER_URL")
17+
18+
cluster = Cluster(
19+
ClusterConfiguration(
20+
name="mnist",
21+
namespace=namespace,
22+
num_workers=1,
23+
head_cpus="500m",
24+
head_memory=2,
25+
min_cpus="500m",
26+
max_cpus=1,
27+
min_memory=1,
28+
max_memory=2,
29+
num_gpus=0,
30+
instascale=False,
31+
image=ray_image,
32+
openshift_oauth=True,
33+
)
34+
)
35+
36+
if isAuthLoginEnable == "true":
37+
auth = TokenAuthentication(token=cluster_token, server=server_url, skip_tls=True)
38+
auth.login()
39+
40+
cluster.up()
41+
42+
cluster.status()
43+
44+
cluster.wait_ready()
45+
46+
cluster.status()
47+
48+
cluster.details()
49+
50+
jobdef = DDPJobDefinition(
51+
name="mnist",
52+
script="mnist.py",
53+
scheduler_args={"requirements": "requirements.txt"},
54+
)
55+
job = jobdef.submit(cluster)
56+
57+
done = False
58+
time = 0
59+
timeout = 900
60+
while not done:
61+
status = job.status()
62+
if is_terminal(status.state):
63+
break
64+
if not done:
65+
print(status)
66+
if timeout and time >= timeout:
67+
raise TimeoutError(f"job has timed out after waiting {timeout}s")
68+
sleep(5)
69+
time += 5
70+
71+
print(f"Job has completed: {status.state}")
72+
73+
print(job.logs())
74+
75+
cluster.down()
76+
77+
if not status.state == AppState.SUCCEEDED:
78+
exit(1)
79+
else:
80+
exit(0)

0 commit comments

Comments
 (0)