Skip to content

Commit e85fe63

Browse files
Changed returns for delete_jobs and stop_jobs and updated unit tests
1 parent 5d75224 commit e85fe63

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

src/codeflare_sdk.egg-info/SOURCES.txt

+2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ src/codeflare_sdk/cluster/config.py
1414
src/codeflare_sdk/cluster/model.py
1515
src/codeflare_sdk/job/__init__.py
1616
src/codeflare_sdk/job/jobs.py
17+
src/codeflare_sdk/job/ray_jobs.py
1718
src/codeflare_sdk/utils/__init__.py
1819
src/codeflare_sdk/utils/generate_cert.py
1920
src/codeflare_sdk/utils/generate_yaml.py
2021
src/codeflare_sdk/utils/kube_api_helpers.py
22+
src/codeflare_sdk/utils/openshift_oauth.py
2123
src/codeflare_sdk/utils/pretty_print.py

src/codeflare_sdk/job/ray_jobs.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,18 @@ def submit_job(
6868
entrypoint_resources=entrypoint_resources,
6969
)
7070

71-
def delete_job(self, job_id: str) -> bool:
71+
def delete_job(self, job_id: str) -> (bool, str):
7272
"""
7373
Method for deleting jobs with the job id being a mandatory field.
7474
"""
7575
deletion_status = self.rayJobClient.delete_job(job_id=job_id)
7676

7777
if deletion_status:
78-
print(f"Successfully deleted Job {job_id}")
79-
return deletion_status
78+
message = f"Successfully deleted Job {job_id}"
8079
else:
81-
print(f"Failed to delete Job {job_id}")
82-
return deletion_status
80+
message = f"Failed to delete Job {job_id}"
81+
82+
return deletion_status, message
8383

8484
def get_address(self) -> str:
8585
"""
@@ -95,7 +95,7 @@ def get_job_info(self, job_id: str):
9595

9696
def get_job_logs(self, job_id: str) -> str:
9797
"""
98-
Method for getting the job info with the job id being a mandatory field.
98+
Method for getting the job logs with the job id being a mandatory field.
9999
"""
100100
return self.rayJobClient.get_job_logs(job_id=job_id)
101101

@@ -111,16 +111,16 @@ def list_jobs(self):
111111
"""
112112
return self.rayJobClient.list_jobs()
113113

114-
def stop_job(self, job_id: str) -> bool:
114+
def stop_job(self, job_id: str) -> (bool, str):
115115
"""
116116
Method for stopping a job with the job id being a mandatory field.
117117
"""
118118
stop_job_status = self.rayJobClient.stop_job(job_id=job_id)
119119
if stop_job_status:
120-
print(f"Successfully stopped Job {job_id}")
120+
message = f"Successfully stopped Job {job_id}"
121121
else:
122-
print(f"Failed to stop Job, {job_id} could have already completed.")
123-
return stop_job_status
122+
message = f"Failed to stop Job, {job_id} could have already completed."
123+
return stop_job_status, message
124124

125125
def tail_job_logs(self, job_id: str) -> Iterator[str]:
126126
"""

tests/unit_test.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -2890,36 +2890,39 @@ def test_rjc_delete_job(ray_job_client, mocker):
28902890
result = ray_job_client.delete_job(job_id="mocked_job_id")
28912891

28922892
mocked_delete_job_True.assert_called_once_with(job_id="mocked_job_id")
2893-
assert result is True
2893+
assert result == (True, "Successfully deleted Job mocked_job_id")
28942894

28952895
# Case return False
28962896
mocked_delete_job_False = mocker.patch.object(
2897-
JobSubmissionClient, "delete_job", return_value=False
2897+
JobSubmissionClient, "delete_job", return_value=(False)
28982898
)
28992899
result = ray_job_client.delete_job(job_id="mocked_job_id")
29002900

29012901
mocked_delete_job_False.assert_called_once_with(job_id="mocked_job_id")
2902-
assert result is False
2902+
assert result == (False, "Failed to delete Job mocked_job_id")
29032903

29042904

29052905
def test_rjc_stop_job(ray_job_client, mocker):
29062906
# Case return True
29072907
mocked_stop_job_True = mocker.patch.object(
2908-
JobSubmissionClient, "stop_job", return_value=True
2908+
JobSubmissionClient, "stop_job", return_value=(True)
29092909
)
29102910
result = ray_job_client.stop_job(job_id="mocked_job_id")
29112911

29122912
mocked_stop_job_True.assert_called_once_with(job_id="mocked_job_id")
2913-
assert result is True
2913+
assert result == (True, "Successfully stopped Job mocked_job_id")
29142914

29152915
# Case return False
29162916
mocked_stop_job_False = mocker.patch.object(
2917-
JobSubmissionClient, "stop_job", return_value=False
2917+
JobSubmissionClient, "stop_job", return_value=(False)
29182918
)
29192919
result = ray_job_client.stop_job(job_id="mocked_job_id")
29202920

29212921
mocked_stop_job_False.assert_called_once_with(job_id="mocked_job_id")
2922-
assert result is False
2922+
assert result == (
2923+
False,
2924+
"Failed to stop Job, mocked_job_id could have already completed.",
2925+
)
29232926

29242927

29252928
def test_rjc_address(ray_job_client, mocker):

0 commit comments

Comments
 (0)