24
24
from codeflare_sdk .cluster .cluster import (
25
25
Cluster ,
26
26
ClusterConfiguration ,
27
- get_current_namespace ,
28
27
list_all_clusters ,
29
28
list_all_queued ,
30
29
_copy_to_ray ,
@@ -240,6 +239,23 @@ def test_cluster_creation():
240
239
return cluster
241
240
242
241
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
+
243
259
def arg_check_apply_effect (* args ):
244
260
assert args [0 ] == "apply"
245
261
assert args [1 ] == ["-f" , "unit-test-cluster.yaml" ]
@@ -496,14 +512,6 @@ def act_side_effect_list(self):
496
512
return [self ]
497
513
498
514
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
-
507
515
def get_selector (* args ):
508
516
selector = Selector ({"operation" : "selector" , "status" : 0 , "actions" : []})
509
517
return selector
@@ -1593,22 +1601,6 @@ def test_wait_ready(mocker, capsys):
1593
1601
)
1594
1602
1595
1603
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
-
1612
1604
def test_jobdefinition_coverage ():
1613
1605
abstract = JobDefinition ()
1614
1606
cluster = Cluster (test_config_creation ())
@@ -1673,7 +1665,6 @@ def test_DDPJobDefinition_dry_run():
1673
1665
assert type (ddp_job ._scheduler ) == type (str ())
1674
1666
1675
1667
assert ddp_job .request .app_id .startswith ("test" )
1676
- assert ddp_job .request .working_dir .startswith ("/tmp/torchx_workspace" )
1677
1668
assert ddp_job .request .cluster_name == "unit-test-cluster"
1678
1669
assert ddp_job .request .requirements == "test"
1679
1670
@@ -1687,12 +1678,18 @@ def test_DDPJobDefinition_dry_run():
1687
1678
assert ddp_job ._scheduler == "ray"
1688
1679
1689
1680
1690
- def test_DDPJobDefinition_dry_run_no_cluster ():
1681
+ def test_DDPJobDefinition_dry_run_no_cluster (mocker ):
1691
1682
"""
1692
1683
Test that the dry run method returns the correct type: AppDryRunInfo,
1693
1684
that the attributes of the returned object are of the correct type,
1694
1685
and that the values from cluster and job definition are correctly passed.
1695
1686
"""
1687
+
1688
+ mocker .patch (
1689
+ "openshift.get_project_name" ,
1690
+ return_value = "opendatahub" ,
1691
+ )
1692
+
1696
1693
ddp = test_DDPJobDefinition_creation ()
1697
1694
ddp .image = "fake-image"
1698
1695
ddp_job = ddp ._dry_run_no_cluster ()
@@ -1750,12 +1747,18 @@ def test_DDPJobDefinition_dry_run_no_resource_args():
1750
1747
)
1751
1748
1752
1749
1753
- def test_DDPJobDefinition_dry_run_no_cluster_no_resource_args ():
1750
+ def test_DDPJobDefinition_dry_run_no_cluster_no_resource_args (mocker ):
1754
1751
"""
1755
1752
Test that the dry run method returns the correct type: AppDryRunInfo,
1756
1753
that the attributes of the returned object are of the correct type,
1757
1754
and that the values from cluster and job definition are correctly passed.
1758
1755
"""
1756
+
1757
+ mocker .patch (
1758
+ "openshift.get_project_name" ,
1759
+ return_value = "opendatahub" ,
1760
+ )
1761
+
1759
1762
ddp = test_DDPJobDefinition_creation ()
1760
1763
try :
1761
1764
ddp ._dry_run_no_cluster ()
@@ -1806,6 +1809,10 @@ def test_DDPJobDefinition_submit(mocker):
1806
1809
"""
1807
1810
ddp_def = test_DDPJobDefinition_creation ()
1808
1811
cluster = Cluster (test_config_creation ())
1812
+ mocker .patch (
1813
+ "openshift.get_project_name" ,
1814
+ return_value = "opendatahub" ,
1815
+ )
1809
1816
mocker .patch (
1810
1817
"codeflare_sdk.job.jobs.torchx_runner.schedule" ,
1811
1818
return_value = "fake-dashboard-url" ,
@@ -1852,6 +1859,10 @@ def test_DDPJob_creation(mocker):
1852
1859
def test_DDPJob_creation_no_cluster (mocker ):
1853
1860
ddp_def = test_DDPJobDefinition_creation ()
1854
1861
ddp_def .image = "fake-image"
1862
+ mocker .patch (
1863
+ "openshift.get_project_name" ,
1864
+ return_value = "opendatahub" ,
1865
+ )
1855
1866
mocker .patch (
1856
1867
"codeflare_sdk.job.jobs.torchx_runner.schedule" ,
1857
1868
return_value = "fake-app-handle" ,
@@ -1898,6 +1909,10 @@ def arg_check_side_effect(*args):
1898
1909
1899
1910
def test_DDPJob_cancel (mocker ):
1900
1911
ddp_job = test_DDPJob_creation_no_cluster (mocker )
1912
+ mocker .patch (
1913
+ "openshift.get_project_name" ,
1914
+ return_value = "opendatahub" ,
1915
+ )
1901
1916
mocker .patch (
1902
1917
"codeflare_sdk.job.jobs.torchx_runner.cancel" , side_effect = arg_check_side_effect
1903
1918
)
@@ -1916,3 +1931,22 @@ def parse_j(cmd):
1916
1931
max_worker = args [1 ]
1917
1932
gpu = args [3 ]
1918
1933
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