4
4
import os
5
5
import logging
6
6
from kubernetes import client , config
7
-
8
7
from kubeflow .katib import ApiClient , KatibClient , models
9
8
from kubeflow .katib .utils .utils import FakeResponse
10
9
from kubeflow .katib .constants import constants
13
12
EXPERIMENT_TIMEOUT = 60 * 40
14
13
15
14
# The default logging config.
16
- logging .basicConfig (level = logging .DEBUG )
15
+ logging .basicConfig (level = logging .INFO )
17
16
18
17
19
18
def verify_experiment_results (
@@ -111,45 +110,47 @@ def verify_experiment_results(
111
110
):
112
111
resource_name = exp_name + "-" + experiment .spec .algorithm .algorithm_name
113
112
114
- # Suggestion's Service and Deployment should be deleted.
115
113
config .load_kube_config ()
116
- for _ in range (10 ):
117
-
118
- services = client .CoreV1Api ().list_namespaced_service (exp_namespace )
119
- for i in services .items :
120
- is_deleted = 0 if i .metadata .name == resource_name else 1
121
-
122
- deployments = client .AppsV1Api ().list_namespaced_deployment (exp_namespace )
123
- for i in deployments .items :
124
- is_deleted *= 0 if i .metadata .name == resource_name else 1
125
- if is_deleted == 1 :
126
- break
127
-
128
- # Deployment and Service deletion might take some time.
114
+ # Suggestion's Service and Deployment should be deleted.
115
+ for i in range (10 ):
116
+ try :
117
+ client .AppsV1Api ().read_namespaced_deployment (
118
+ resource_name , exp_namespace
119
+ )
120
+ except client .ApiException as e :
121
+ if e .status == 404 :
122
+ break
123
+ else :
124
+ raise e
125
+ # Deployment deletion might take some time.
129
126
time .sleep (1 )
127
+ if i == 10 :
128
+ raise Exception (
129
+ "Suggestion Deployment is still alive for Resume Policy: {}" .format (
130
+ experiment .spec .resume_policy
131
+ )
132
+ )
130
133
131
- if is_deleted == 0 :
134
+ try :
135
+ client .CoreV1Api ().read_namespaced_service (resource_name , exp_namespace )
136
+ except client .ApiException as e :
137
+ if e .status != 404 :
138
+ raise e
139
+ else :
132
140
raise Exception (
133
- "Suggestion Service or Deployment is still alive for "
134
- f"ResumePolicy == { experiment .spec .resume_policy } . "
135
- f"Alive Services: { [i .metadata .name for i in services .items ]} . "
136
- f"Alive Deployments: { [i .metadata .name for i in deployments .items ]} ."
141
+ "Suggestion Service is still alive for Resume Policy: {}" .format (
142
+ experiment .spec .resume_policy
143
+ )
137
144
)
138
145
139
146
# For FromVolume resume policy PVC should not be deleted.
140
147
if experiment .spec .resume_policy == "FromVolume" :
141
- PVCs = client .CoreV1Api ().list_namespaced_persistent_volume_claim (
142
- exp_namespace
143
- )
144
- is_deleted = 1
145
- for i in PVCs .items :
146
- if i .metadata .name == resource_name :
147
- is_deleted = 0
148
- if is_deleted == 1 :
149
- raise Exception (
150
- "PVC is deleted for FromVolume resume policy. "
151
- f"Alive PVCs: { [i .metadata .name for i in PVCs .items ]} ."
148
+ try :
149
+ client .CoreV1Api ().read_namespaced_persistent_volume_claim (
150
+ resource_name , exp_namespace
152
151
)
152
+ except client .ApiException :
153
+ raise Exception ("PVC is deleted for FromVolume Resume Policy" )
153
154
154
155
155
156
def run_e2e_experiment (
@@ -206,15 +207,9 @@ def run_e2e_experiment(
206
207
# Verify the Experiment results.
207
208
verify_experiment_results (katib_client , experiment , exp_name , exp_namespace )
208
209
209
- # Describe the Experiment and Suggestion.
210
- logging .debug (
211
- os .popen (f"kubectl describe experiment { exp_name } -n { exp_namespace } " ).read ()
212
- )
213
- logging .debug ("---------------------------------------------------------------" )
214
- logging .debug ("---------------------------------------------------------------" )
215
- logging .debug (
216
- os .popen (f"kubectl describe suggestion { exp_name } -n { exp_namespace } " ).read ()
217
- )
210
+ # Print the Experiment and Suggestion.
211
+ logging .debug (katib_client .get_experiment (exp_name , exp_namespace ))
212
+ logging .debug (katib_client .get_suggestion (exp_name , exp_namespace ))
218
213
219
214
220
215
if __name__ == "__main__" :
@@ -231,7 +226,7 @@ def run_e2e_experiment(
231
226
args = parser .parse_args ()
232
227
233
228
if args .verbose :
234
- logging .getLogger ().setLevel (logging .INFO )
229
+ logging .getLogger ().setLevel (logging .DEBUG )
235
230
236
231
logging .info ("---------------------------------------------------------------" )
237
232
logging .info ("---------------------------------------------------------------" )
0 commit comments