1414
1515import pytest
1616
17- from support import random_choice
17+ from support import random_choice , get_ray_image
1818
1919# Creates a Ray cluster, and trains the MNIST dataset using the CodeFlare SDK.
2020# Asserts creation of AppWrapper, RayCluster, and successful completion of the training job.
2121# Covers successfull installation of CodeFlare-SDK
2222
23+
2324class TestMNISTRayClusterSDK :
2425 def setup_method (self ):
2526 # Load the kube config from the environment or Kube config file.
2627 config .load_kube_config ()
2728
2829 # Initialize Kubernetes client
2930 self .api_instance = client .CoreV1Api ()
30- self .custom_api = kubernetes .client .CustomObjectsApi (self .api_instance .api_client )
31+ self .custom_api = kubernetes .client .CustomObjectsApi (
32+ self .api_instance .api_client
33+ )
3134
3235 def teardown_method (self ):
33- if hasattr (self , ' namespace' ):
36+ if hasattr (self , " namespace" ):
3437 self .api_instance .delete_namespace (self .namespace )
35- if hasattr (self , 'configmap' ):
36- self .api_instance .delete_namespaced_config_map (self .configmap .metadata .name , self .namespace )
38+ if hasattr (self , "configmap" ):
39+ self .api_instance .delete_namespaced_config_map (
40+ self .configmap .metadata .name , self .namespace
41+ )
3742
3843 def test_mnist_ray_cluster_sdk (self ):
3944 self .create_test_namespace ()
4045 self .run_mnist_raycluster_sdk ()
4146
4247 def create_test_namespace (self ):
4348 self .namespace = f"test-ns-{ random_choice ()} "
44- namespace_body = client .V1Namespace (metadata = client .V1ObjectMeta (name = self .namespace ))
49+ namespace_body = client .V1Namespace (
50+ metadata = client .V1ObjectMeta (name = self .namespace )
51+ )
4552 self .api_instance .create_namespace (namespace_body )
4653 return self .namespace
4754
4855 def run_mnist_raycluster_sdk (self ):
49- ray_image = "quay.io/project-codeflare/ray:latest-py39-cu118"
56+ ray_image = get_ray_image ()
5057 host = os .getenv ("CLUSTER_HOSTNAME" )
5158
5259 ingress_options = {}
@@ -61,7 +68,7 @@ def run_mnist_raycluster_sdk(self):
6168 "host" : host ,
6269 "annotations" : {
6370 "nginx.ingress.kubernetes.io/proxy-body-size" : "100M" ,
64- }
71+ },
6572 },
6673 ]
6774 }
@@ -127,17 +134,29 @@ def run_mnist_raycluster_sdk(self):
127134 # Assertions
128135 def assert_appwrapper_exists (self ):
129136 try :
130- self .custom_api .get_namespaced_custom_object ("workload.codeflare.dev" , "v1beta1" , self .namespace , "appwrappers" , "mnist" )
131- print (f"AppWrapper 'mnist' has been created in the namespace: '{ self .namespace } '" )
137+ self .custom_api .get_namespaced_custom_object (
138+ "workload.codeflare.dev" ,
139+ "v1beta1" ,
140+ self .namespace ,
141+ "appwrappers" ,
142+ "mnist" ,
143+ )
144+ print (
145+ f"AppWrapper 'mnist' has been created in the namespace: '{ self .namespace } '"
146+ )
132147 assert True
133148 except Exception as e :
134149 print (f"AppWrapper 'mnist' has not been created. Error: { e } " )
135150 assert False
136151
137152 def assert_raycluster_exists (self ):
138153 try :
139- self .custom_api .get_namespaced_custom_object ("ray.io" , "v1" , self .namespace , "rayclusters" , "mnist" )
140- print (f"RayCluster 'mnist' created successfully in the namespace: '{ self .namespace } '" )
154+ self .custom_api .get_namespaced_custom_object (
155+ "ray.io" , "v1" , self .namespace , "rayclusters" , "mnist"
156+ )
157+ print (
158+ f"RayCluster 'mnist' created successfully in the namespace: '{ self .namespace } '"
159+ )
141160 assert True
142161 except Exception as e :
143162 print (f"RayCluster 'mnist' has not been created. Error: { e } " )
0 commit comments