14
14
15
15
import pytest
16
16
17
- from support import random_choice
17
+ from support import random_choice , get_ray_image
18
18
19
19
# Creates a Ray cluster, and trains the MNIST dataset using the CodeFlare SDK.
20
20
# Asserts creation of AppWrapper, RayCluster, and successful completion of the training job.
21
21
# Covers successfull installation of CodeFlare-SDK
22
22
23
+
23
24
class TestMNISTRayClusterSDK :
24
25
def setup_method (self ):
25
26
# Load the kube config from the environment or Kube config file.
26
27
config .load_kube_config ()
27
28
28
29
# Initialize Kubernetes client
29
30
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
+ )
31
34
32
35
def teardown_method (self ):
33
- if hasattr (self , ' namespace' ):
36
+ if hasattr (self , " namespace" ):
34
37
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
+ )
37
42
38
43
def test_mnist_ray_cluster_sdk (self ):
39
44
self .create_test_namespace ()
40
45
self .run_mnist_raycluster_sdk ()
41
46
42
47
def create_test_namespace (self ):
43
48
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
+ )
45
52
self .api_instance .create_namespace (namespace_body )
46
53
return self .namespace
47
54
48
55
def run_mnist_raycluster_sdk (self ):
49
- ray_image = "quay.io/project-codeflare/ray:latest-py39-cu118"
56
+ ray_image = get_ray_image ()
50
57
host = os .getenv ("CLUSTER_HOSTNAME" )
51
58
52
59
ingress_options = {}
@@ -61,7 +68,7 @@ def run_mnist_raycluster_sdk(self):
61
68
"host" : host ,
62
69
"annotations" : {
63
70
"nginx.ingress.kubernetes.io/proxy-body-size" : "100M" ,
64
- }
71
+ },
65
72
},
66
73
]
67
74
}
@@ -127,17 +134,29 @@ def run_mnist_raycluster_sdk(self):
127
134
# Assertions
128
135
def assert_appwrapper_exists (self ):
129
136
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
+ )
132
147
assert True
133
148
except Exception as e :
134
149
print (f"AppWrapper 'mnist' has not been created. Error: { e } " )
135
150
assert False
136
151
137
152
def assert_raycluster_exists (self ):
138
153
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
+ )
141
160
assert True
142
161
except Exception as e :
143
162
print (f"RayCluster 'mnist' has not been created. Error: { e } " )
0 commit comments