Skip to content

Commit 39213b2

Browse files
committed
remove: JobDefinition and update tests
1 parent 465d9c4 commit 39213b2

File tree

7 files changed

+57
-102
lines changed

7 files changed

+57
-102
lines changed

src/codeflare_sdk/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
get_cluster,
1515
)
1616

17-
from .job import JobDefinition, Job, RayJobClient
17+
from .job import RayJobClient
1818

1919
from .utils import generate_cert

src/codeflare_sdk/job/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
from .jobs import JobDefinition, Job
2-
31
from .ray_jobs import RayJobClient

src/codeflare_sdk/job/jobs.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

tests/e2e/mnist_raycluster_sdk_oauth_test.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from torchx.specs.api import AppState, is_terminal
66

77
from codeflare_sdk import Cluster, ClusterConfiguration, TokenAuthentication
8-
from codeflare_sdk.job.jobs import JobDefinition
8+
from codeflare_sdk.job import RayJobClient
99

1010
import pytest
1111

@@ -97,18 +97,25 @@ def assert_jobsubmit_withoutLogin(self, cluster):
9797

9898
def assert_jobsubmit_withlogin(self, cluster):
9999
self.assert_appwrapper_exists()
100-
jobdef = JobDefinition(
101-
name="mnist",
102-
script="./tests/e2e/mnist.py",
103-
scheduler_args={"requirements": "./tests/e2e/mnist_pip_requirements.txt"},
100+
auth_token = run_oc_command(["whoami", "--show-token=true"])
101+
ray_dashboard = cluster.cluster_dashboard_uri()
102+
header = {"Authorization": f"Bearer {auth_token}"}
103+
client = RayJobClient(address=ray_dashboard, headers=header, verify=True)
104+
105+
# Submit the job
106+
submission_id = client.submit_job(
107+
entrypoint="python mnist.py",
108+
runtime_env={
109+
"working_dir": "./tests/e2e/",
110+
"pip": "mnist_pip_requirements.txt",
111+
},
104112
)
105-
job = jobdef.submit(cluster)
106-
113+
print(f"Submitted job with ID: {submission_id}")
107114
done = False
108115
time = 0
109116
timeout = 900
110117
while not done:
111-
status = job.status()
118+
status = client.get_job_status(submission_id)
112119
if is_terminal(status.state):
113120
break
114121
if not done:
@@ -118,11 +125,12 @@ def assert_jobsubmit_withlogin(self, cluster):
118125
sleep(5)
119126
time += 5
120127

121-
print(job.status())
122-
self.assert_job_completion(status)
128+
logs = client.get_job_logs(submission_id)
129+
print(logs)
123130

124-
print(job.logs())
131+
self.assert_job_completion(status)
125132

133+
client.delete_job(submission_id)
126134
cluster.down()
127135

128136
def assert_appwrapper_exists(self):

tests/e2e/mnist_raycluster_sdk_test.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from torchx.specs.api import AppState, is_terminal
1111

1212
from codeflare_sdk.cluster.cluster import Cluster, ClusterConfiguration
13-
from codeflare_sdk.job.jobs import JobDefinition
13+
from codeflare_sdk.job import RayJobClient
1414

1515
import pytest
1616

@@ -87,18 +87,25 @@ def run_mnist_raycluster_sdk(self):
8787

8888
cluster.details()
8989

90-
jobdef = JobDefinition(
91-
name="mnist",
92-
script="./tests/e2e/mnist.py",
93-
scheduler_args={"requirements": "./tests/e2e/mnist_pip_requirements.txt"},
90+
auth_token = run_oc_command(["whoami", "--show-token=true"])
91+
ray_dashboard = cluster.cluster_dashboard_uri()
92+
header = {"Authorization": f"Bearer {auth_token}"}
93+
client = RayJobClient(address=ray_dashboard, headers=header, verify=True)
94+
95+
# Submit the job
96+
submission_id = client.submit_job(
97+
entrypoint="python mnist.py",
98+
runtime_env={
99+
"working_dir": "./tests/e2e/",
100+
"pip": "mnist_pip_requirements.txt",
101+
},
94102
)
95-
job = jobdef.submit(cluster)
96-
103+
print(f"Submitted job with ID: {submission_id}")
97104
done = False
98105
time = 0
99106
timeout = 900
100107
while not done:
101-
status = job.status()
108+
status = client.get_job_status(submission_id)
102109
if is_terminal(status.state):
103110
break
104111
if not done:
@@ -108,11 +115,12 @@ def run_mnist_raycluster_sdk(self):
108115
sleep(5)
109116
time += 5
110117

111-
print(job.status())
112-
self.assert_job_completion(status)
118+
logs = client.get_job_logs(submission_id)
119+
print(logs)
113120

114-
print(job.logs())
121+
self.assert_job_completion(status)
115122

123+
client.delete_job(submission_id)
116124
cluster.down()
117125

118126
# Assertions

tests/e2e/mnist_rayjob.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,33 @@
44

55
from torchx.specs.api import AppState, is_terminal
66

7+
from support import *
8+
79
from codeflare_sdk.cluster.cluster import get_cluster
8-
from codeflare_sdk.job.jobs import JobDefinition
10+
from codeflare_sdk.job import RayJobClient
911

1012
namespace = sys.argv[1]
1113

1214
cluster = get_cluster("mnist", namespace)
1315

1416
cluster.details()
1517

16-
jobdef = JobDefinition(
17-
name="mnist",
18-
script="mnist.py",
19-
scheduler_args={"requirements": "requirements.txt"},
20-
)
21-
job = jobdef.submit(cluster)
18+
auth_token = run_oc_command(["whoami", "--show-token=true"])
19+
ray_dashboard = cluster.cluster_dashboard_uri()
20+
header = {"Authorization": f"Bearer {auth_token}"}
21+
client = RayJobClient(address=ray_dashboard, headers=header, verify=True)
2222

23+
# Submit the job
24+
submission_id = client.submit_job(
25+
entrypoint="python mnist.py",
26+
runtime_env={"working_dir": "/", "pip": "requirements.txt"},
27+
)
28+
print(f"Submitted job with ID: {submission_id}")
2329
done = False
2430
time = 0
2531
timeout = 900
2632
while not done:
27-
status = job.status()
33+
status = client.get_job_status(submission_id)
2834
if is_terminal(status.state):
2935
break
3036
if not done:
@@ -34,12 +40,13 @@
3440
sleep(5)
3541
time += 5
3642

37-
print(f"Job has completed: {status.state}")
38-
39-
print(job.logs())
43+
logs = client.get_job_logs(submission_id)
44+
print(logs)
4045

46+
client.delete_job(submission_id)
4147
cluster.down()
4248

49+
4350
if not status.state == AppState.SUCCEEDED:
4451
exit(1)
4552
else:

tests/unit_test.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@
5959
RayClusterStatus,
6060
CodeFlareClusterStatus,
6161
)
62-
from codeflare_sdk.job.jobs import (
63-
JobDefinition,
64-
Job,
65-
)
6662
from codeflare_sdk.utils.generate_cert import (
6763
generate_ca_cert,
6864
generate_tls_cert,
@@ -2487,24 +2483,6 @@ def test_wait_ready(mocker, capsys):
24872483
)
24882484

24892485

2490-
def test_jobdefinition_coverage(mocker):
2491-
mocker.patch("kubernetes.client.ApisApi.get_api_versions")
2492-
mocker.patch(
2493-
"kubernetes.client.CustomObjectsApi.get_cluster_custom_object",
2494-
return_value={"spec": {"domain": ""}},
2495-
)
2496-
abstract = JobDefinition()
2497-
cluster = createClusterWithConfig(mocker)
2498-
abstract._dry_run(cluster)
2499-
abstract.submit(cluster)
2500-
2501-
2502-
def test_job_coverage():
2503-
abstract = Job()
2504-
abstract.status()
2505-
abstract.logs()
2506-
2507-
25082486
def arg_check_side_effect(*args):
25092487
assert args[0] == "fake-app-handle"
25102488

0 commit comments

Comments
 (0)