2424from codeflare_sdk .cluster .cluster import (
2525 Cluster ,
2626 ClusterConfiguration ,
27- get_current_namespace ,
2827 list_all_clusters ,
2928 list_all_queued ,
3029 _copy_to_ray ,
@@ -240,6 +239,23 @@ def test_cluster_creation():
240239 return cluster
241240
242241
242+ def test_default_cluster_creation (mocker ):
243+ mocker .patch (
244+ "openshift.get_project_name" ,
245+ return_value = "opendatahub" ,
246+ )
247+ default_config = ClusterConfiguration (
248+ name = "unit-test-default-cluster" ,
249+ )
250+ cluster = Cluster (default_config )
251+
252+ assert cluster .app_wrapper_yaml == "unit-test-default-cluster.yaml"
253+ assert cluster .app_wrapper_name == "unit-test-default-cluster"
254+ assert cluster .config .namespace == "opendatahub"
255+
256+ return cluster
257+
258+
243259def arg_check_apply_effect (* args ):
244260 assert args [0 ] == "apply"
245261 assert args [1 ] == ["-f" , "unit-test-cluster.yaml" ]
@@ -496,14 +512,6 @@ def act_side_effect_list(self):
496512 return [self ]
497513
498514
499- def test_get_namespace (mocker ):
500- mocker .patch ("openshift.invoke" , side_effect = arg_side_effect )
501- mock_res = mocker .patch .object (openshift .Result , "actions" )
502- mock_res .side_effect = lambda : act_side_effect_list (fake_res )
503- vars = get_current_namespace ()
504- assert vars == "('project', ['-q'])"
505-
506-
507515def get_selector (* args ):
508516 selector = Selector ({"operation" : "selector" , "status" : 0 , "actions" : []})
509517 return selector
@@ -1593,22 +1601,6 @@ def test_wait_ready(mocker, capsys):
15931601 )
15941602
15951603
1596- def test_cmd_line_generation ():
1597- os .system (
1598- f"python3 { parent } /src/codeflare_sdk/utils/generate_yaml.py --name=unit-cmd-cluster --min-cpu=1 --max-cpu=1 --min-memory=2 --max-memory=2 --gpu=1 --workers=2 --template=src/codeflare_sdk/templates/new-template.yaml"
1599- )
1600- assert filecmp .cmp (
1601- "unit-cmd-cluster.yaml" , f"{ parent } /tests/test-case-cmd.yaml" , shallow = True
1602- )
1603- os .remove ("unit-test-cluster.yaml" )
1604- os .remove ("unit-cmd-cluster.yaml" )
1605-
1606-
1607- def test_cleanup ():
1608- os .remove ("test.yaml" )
1609- os .remove ("raytest2.yaml" )
1610-
1611-
16121604def test_jobdefinition_coverage ():
16131605 abstract = JobDefinition ()
16141606 cluster = Cluster (test_config_creation ())
@@ -1673,7 +1665,6 @@ def test_DDPJobDefinition_dry_run():
16731665 assert type (ddp_job ._scheduler ) == type (str ())
16741666
16751667 assert ddp_job .request .app_id .startswith ("test" )
1676- assert ddp_job .request .working_dir .startswith ("/tmp/torchx_workspace" )
16771668 assert ddp_job .request .cluster_name == "unit-test-cluster"
16781669 assert ddp_job .request .requirements == "test"
16791670
@@ -1687,12 +1678,18 @@ def test_DDPJobDefinition_dry_run():
16871678 assert ddp_job ._scheduler == "ray"
16881679
16891680
1690- def test_DDPJobDefinition_dry_run_no_cluster ():
1681+ def test_DDPJobDefinition_dry_run_no_cluster (mocker ):
16911682 """
16921683 Test that the dry run method returns the correct type: AppDryRunInfo,
16931684 that the attributes of the returned object are of the correct type,
16941685 and that the values from cluster and job definition are correctly passed.
16951686 """
1687+
1688+ mocker .patch (
1689+ "openshift.get_project_name" ,
1690+ return_value = "opendatahub" ,
1691+ )
1692+
16961693 ddp = test_DDPJobDefinition_creation ()
16971694 ddp .image = "fake-image"
16981695 ddp_job = ddp ._dry_run_no_cluster ()
@@ -1750,12 +1747,18 @@ def test_DDPJobDefinition_dry_run_no_resource_args():
17501747 )
17511748
17521749
1753- def test_DDPJobDefinition_dry_run_no_cluster_no_resource_args ():
1750+ def test_DDPJobDefinition_dry_run_no_cluster_no_resource_args (mocker ):
17541751 """
17551752 Test that the dry run method returns the correct type: AppDryRunInfo,
17561753 that the attributes of the returned object are of the correct type,
17571754 and that the values from cluster and job definition are correctly passed.
17581755 """
1756+
1757+ mocker .patch (
1758+ "openshift.get_project_name" ,
1759+ return_value = "opendatahub" ,
1760+ )
1761+
17591762 ddp = test_DDPJobDefinition_creation ()
17601763 try :
17611764 ddp ._dry_run_no_cluster ()
@@ -1806,6 +1809,10 @@ def test_DDPJobDefinition_submit(mocker):
18061809 """
18071810 ddp_def = test_DDPJobDefinition_creation ()
18081811 cluster = Cluster (test_config_creation ())
1812+ mocker .patch (
1813+ "openshift.get_project_name" ,
1814+ return_value = "opendatahub" ,
1815+ )
18091816 mocker .patch (
18101817 "codeflare_sdk.job.jobs.torchx_runner.schedule" ,
18111818 return_value = "fake-dashboard-url" ,
@@ -1852,6 +1859,10 @@ def test_DDPJob_creation(mocker):
18521859def test_DDPJob_creation_no_cluster (mocker ):
18531860 ddp_def = test_DDPJobDefinition_creation ()
18541861 ddp_def .image = "fake-image"
1862+ mocker .patch (
1863+ "openshift.get_project_name" ,
1864+ return_value = "opendatahub" ,
1865+ )
18551866 mocker .patch (
18561867 "codeflare_sdk.job.jobs.torchx_runner.schedule" ,
18571868 return_value = "fake-app-handle" ,
@@ -1898,6 +1909,10 @@ def arg_check_side_effect(*args):
18981909
18991910def test_DDPJob_cancel (mocker ):
19001911 ddp_job = test_DDPJob_creation_no_cluster (mocker )
1912+ mocker .patch (
1913+ "openshift.get_project_name" ,
1914+ return_value = "opendatahub" ,
1915+ )
19011916 mocker .patch (
19021917 "codeflare_sdk.job.jobs.torchx_runner.cancel" , side_effect = arg_check_side_effect
19031918 )
@@ -1916,3 +1931,22 @@ def parse_j(cmd):
19161931 max_worker = args [1 ]
19171932 gpu = args [3 ]
19181933 return f"{ max_worker } x{ gpu } "
1934+
1935+
1936+ # Make sure to keep this function and the efollowing function at the end of the file
1937+ def test_cmd_line_generation ():
1938+ os .system (
1939+ f"python3 { parent } /src/codeflare_sdk/utils/generate_yaml.py --name=unit-cmd-cluster --min-cpu=1 --max-cpu=1 --min-memory=2 --max-memory=2 --gpu=1 --workers=2 --template=src/codeflare_sdk/templates/new-template.yaml"
1940+ )
1941+ assert filecmp .cmp (
1942+ "unit-cmd-cluster.yaml" , f"{ parent } /tests/test-case-cmd.yaml" , shallow = True
1943+ )
1944+ os .remove ("unit-test-cluster.yaml" )
1945+ os .remove ("unit-test-default-cluster.yaml" )
1946+ os .remove ("unit-cmd-cluster.yaml" )
1947+
1948+
1949+ # Make sure to always keep this function last
1950+ def test_cleanup ():
1951+ os .remove ("test.yaml" )
1952+ os .remove ("raytest2.yaml" )
0 commit comments