@@ -390,7 +390,7 @@ def test_submit_validation_no_entrypoint(mocker):
390
390
)
391
391
392
392
with pytest .raises (
393
- ValueError , match = "entrypoint must be provided to submit a RayJob"
393
+ ValueError , match = "Entrypoint must be provided to submit a RayJob"
394
394
):
395
395
rayjob .submit ()
396
396
@@ -1878,3 +1878,123 @@ def test_add_script_volumes_existing_mount_skip():
1878
1878
# Should still have only one mount and no volume added
1879
1879
assert len (config .volumes ) == 0 # Volume not added due to mount skip
1880
1880
assert len (config .volume_mounts ) == 1
1881
+
1882
+
1883
+ def test_rayjob_stop_success (mocker , caplog ):
1884
+ """Test successful RayJob stop operation."""
1885
+ mocker .patch ("kubernetes.config.load_kube_config" )
1886
+
1887
+ mock_api_class = mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
1888
+ mock_api_instance = MagicMock ()
1889
+ mock_api_class .return_value = mock_api_instance
1890
+
1891
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
1892
+
1893
+ mock_api_instance .suspend_job .return_value = {
1894
+ "metadata" : {"name" : "test-rayjob" },
1895
+ "spec" : {"suspend" : True },
1896
+ }
1897
+
1898
+ rayjob = RayJob (
1899
+ job_name = "test-rayjob" ,
1900
+ cluster_name = "test-cluster" ,
1901
+ namespace = "test-namespace" ,
1902
+ entrypoint = "python script.py" ,
1903
+ )
1904
+
1905
+ with caplog .at_level ("INFO" ):
1906
+ result = rayjob .stop ()
1907
+
1908
+ assert result is True
1909
+
1910
+ mock_api_instance .suspend_job .assert_called_once_with (
1911
+ name = "test-rayjob" , k8s_namespace = "test-namespace"
1912
+ )
1913
+
1914
+ # Verify success message was logged
1915
+ assert "Successfully stopped the RayJob test-rayjob" in caplog .text
1916
+
1917
+
1918
+ def test_rayjob_stop_failure (mocker ):
1919
+ """Test RayJob stop operation when API call fails."""
1920
+ mocker .patch ("kubernetes.config.load_kube_config" )
1921
+
1922
+ mock_api_class = mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
1923
+ mock_api_instance = MagicMock ()
1924
+ mock_api_class .return_value = mock_api_instance
1925
+
1926
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
1927
+
1928
+ mock_api_instance .suspend_job .return_value = None
1929
+
1930
+ rayjob = RayJob (
1931
+ job_name = "test-rayjob" ,
1932
+ cluster_name = "test-cluster" ,
1933
+ namespace = "test-namespace" ,
1934
+ entrypoint = "python script.py" ,
1935
+ )
1936
+
1937
+ with pytest .raises (RuntimeError , match = "Failed to stop the RayJob test-rayjob" ):
1938
+ rayjob .stop ()
1939
+
1940
+ mock_api_instance .suspend_job .assert_called_once_with (
1941
+ name = "test-rayjob" , k8s_namespace = "test-namespace"
1942
+ )
1943
+
1944
+
1945
+ def test_rayjob_resubmit_success (mocker ):
1946
+ """Test successful RayJob resubmit operation."""
1947
+ mocker .patch ("kubernetes.config.load_kube_config" )
1948
+
1949
+ mock_api_class = mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
1950
+ mock_api_instance = MagicMock ()
1951
+ mock_api_class .return_value = mock_api_instance
1952
+
1953
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
1954
+
1955
+ mock_api_instance .resubmit_job .return_value = {
1956
+ "metadata" : {"name" : "test-rayjob" },
1957
+ "spec" : {"suspend" : False },
1958
+ }
1959
+
1960
+ rayjob = RayJob (
1961
+ job_name = "test-rayjob" ,
1962
+ cluster_name = "test-cluster" ,
1963
+ namespace = "test-namespace" ,
1964
+ entrypoint = "python script.py" ,
1965
+ )
1966
+
1967
+ result = rayjob .resubmit ()
1968
+
1969
+ assert result is True
1970
+
1971
+ mock_api_instance .resubmit_job .assert_called_once_with (
1972
+ name = "test-rayjob" , k8s_namespace = "test-namespace"
1973
+ )
1974
+
1975
+
1976
+ def test_rayjob_resubmit_failure (mocker ):
1977
+ """Test RayJob resubmit operation when API call fails."""
1978
+ mocker .patch ("kubernetes.config.load_kube_config" )
1979
+
1980
+ mock_api_class = mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
1981
+ mock_api_instance = MagicMock ()
1982
+ mock_api_class .return_value = mock_api_instance
1983
+
1984
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayClusterApi" )
1985
+
1986
+ mock_api_instance .resubmit_job .return_value = None
1987
+
1988
+ rayjob = RayJob (
1989
+ job_name = "test-rayjob" ,
1990
+ cluster_name = "test-cluster" ,
1991
+ namespace = "test-namespace" ,
1992
+ entrypoint = "python script.py" ,
1993
+ )
1994
+
1995
+ with pytest .raises (RuntimeError , match = "Failed to resubmit the RayJob test-rayjob" ):
1996
+ rayjob .resubmit ()
1997
+
1998
+ mock_api_instance .resubmit_job .assert_called_once_with (
1999
+ name = "test-rayjob" , k8s_namespace = "test-namespace"
2000
+ )
0 commit comments