3434MODEL_VERSION = "1"
3535
3636
37- @pytest .fixture (scope = "module" , autouse = True )
38- def setup_and_teardown ():
39- """Clean up project before and after tests."""
40- # Setup: Login and configure docker env for minikube
41- print ("[DEBUG] Setting up e2e test environment" )
42-
43- # Check minikube status first
44- try :
45- result = subprocess .run (["minikube" , "status" ], capture_output = True , text = True , timeout = 30 )
46- print (f"[DEBUG] minikube status exit code: { result .returncode } " )
47- print (f"[DEBUG] minikube status output:\n { result .stdout } " )
48- if result .stderr :
49- print (f"[DEBUG] minikube status stderr:\n { result .stderr } " )
50- except Exception as exc :
51- print (f"[DEBUG] Error checking minikube status: { exc } " )
52-
53- _setup_minikube_docker_env ()
54- assert login () == 0 , "Login failed"
55-
56- yield
57-
58- # Teardown: cleanup
59- cleanup_project (PROJECT_NAME )
60-
61-
6237def test_health_endpoint_responds ():
6338 """Test that the platform health endpoint responds."""
6439 result = subprocess .run (
@@ -186,11 +161,29 @@ def _dump_deployment_debug_info(deployment_name):
186161 "kubectl get events" ,
187162 ["kubectl" , "get" , "events" , "-n" , PROJECT_NAME , "--sort-by=.metadata.creationTimestamp" ],
188163 )
189- pod_name = _first_pod_name (PROJECT_NAME )
190- if pod_name :
191- _run_debug_cmd ("kubectl describe pod" , ["kubectl" , "describe" , "pod" , pod_name , "-n" , PROJECT_NAME ])
192- _run_debug_cmd ("kubectl logs current" , ["kubectl" , "logs" , pod_name , "-n" , PROJECT_NAME ])
193- _run_debug_cmd ("kubectl logs previous" , ["kubectl" , "logs" , pod_name , "-n" , PROJECT_NAME , "--previous" ])
164+
165+ # Get all pods for this deployment to check their logs
166+ result = subprocess .run (
167+ ["kubectl" , "get" , "pods" , "-n" , PROJECT_NAME , "-l" , f"app={ deployment_name } " , "--no-headers" ],
168+ capture_output = True ,
169+ text = True ,
170+ timeout = 20 ,
171+ )
172+ if result .returncode == 0 and result .stdout .strip ():
173+ pod_lines = result .stdout .strip ().splitlines ()
174+ for line in pod_lines :
175+ pod_name = line .split ()[0 ]
176+ print (f"[DEBUG] Checking logs for pod: { pod_name } " )
177+ _run_debug_cmd (
178+ f"kubectl describe pod { pod_name } " , ["kubectl" , "describe" , "pod" , pod_name , "-n" , PROJECT_NAME ]
179+ )
180+ _run_debug_cmd (
181+ f"kubectl logs current { pod_name } " , ["kubectl" , "logs" , pod_name , "-n" , PROJECT_NAME , "--tail=100" ]
182+ )
183+ _run_debug_cmd (
184+ f"kubectl logs previous { pod_name } " ,
185+ ["kubectl" , "logs" , pod_name , "-n" , PROJECT_NAME , "--previous" , "--tail=100" ],
186+ )
194187
195188 # Also check available images in minikube
196189 _run_debug_cmd ("minikube image ls" , ["minikube" , "image" , "ls" ])
@@ -231,6 +224,9 @@ def test_deploy_model():
231224 """Test model deployment."""
232225 _skip_if_mlflow_not_ready ()
233226
227+ # Configure minikube docker environment before deployment
228+ _setup_minikube_docker_env ()
229+
234230 # Verify Docker environment is still configured for minikube
235231 docker_host = os .environ .get ("DOCKER_HOST" , "not set" )
236232 print (f"[DEBUG] Deploy test - Current DOCKER_HOST: { docker_host } " )
@@ -255,6 +251,48 @@ def test_deployed_model_health_check():
255251 _skip_if_mlflow_not_ready ()
256252 time .sleep (180 )
257253 deployment_name = sanitize_ressource_name (f"{ PROJECT_NAME } -{ MODEL_NAME } -{ MODEL_VERSION } -deployment" )
254+
255+ # Check if the expected image exists in minikube
256+ expected_image_name = (
257+ f"{ PROJECT_NAME .lower ().replace ('_' , '-' )} -{ MODEL_NAME .lower ().replace ('_' , '-' )} -{ MODEL_VERSION } -ctr:latest"
258+ )
259+ print (f"[DEBUG] Checking for image: { expected_image_name } " )
260+ result = subprocess .run (
261+ ["minikube" , "image" , "ls" , "--format" , "table" ],
262+ capture_output = True ,
263+ text = True ,
264+ timeout = 30 ,
265+ )
266+ if result .returncode == 0 :
267+ if expected_image_name in result .stdout :
268+ print (f"[DEBUG] Image { expected_image_name } found in minikube" )
269+ else :
270+ print (f"[DEBUG] Image { expected_image_name } NOT found in minikube" )
271+ print (f"[DEBUG] Available images:\n { result .stdout } " )
272+
273+ # First check if the pod is running
274+ print (f"[DEBUG] Checking pod status for deployment { deployment_name } " )
275+ result = subprocess .run (
276+ ["kubectl" , "get" , "pods" , "-n" , PROJECT_NAME , "-l" , f"app={ deployment_name } " , "--no-headers" ],
277+ capture_output = True ,
278+ text = True ,
279+ timeout = 20 ,
280+ )
281+ if result .returncode == 0 and result .stdout .strip ():
282+ pod_lines = result .stdout .strip ().splitlines ()
283+ for line in pod_lines :
284+ parts = line .split ()
285+ pod_name , ready , status = parts [0 ], parts [1 ], parts [2 ]
286+ print (f"[DEBUG] Pod { pod_name } : ready={ ready } , status={ status } " )
287+ if status != "Running" :
288+ print (f"[DEBUG] Pod is not running, checking logs..." )
289+ _run_debug_cmd (
290+ f"kubectl logs { pod_name } " , ["kubectl" , "logs" , pod_name , "-n" , PROJECT_NAME , "--tail=50" ]
291+ )
292+ _run_debug_cmd (
293+ f"kubectl describe pod { pod_name } " , ["kubectl" , "describe" , "pod" , pod_name , "-n" , PROJECT_NAME ]
294+ )
295+
258296 health_url = f"http://{ MP_HOSTNAME } /deploy/{ PROJECT_NAME } /{ deployment_name } /health"
259297 timeout = time .time () + 300 # Increase timeout to 5 minutes for CI environments
260298 start = time .time ()
@@ -267,7 +305,9 @@ def test_deployed_model_health_check():
267305 )
268306 last_status = result .stdout .strip ()
269307 if last_status == "200" :
308+ print (f"[DEBUG] Health check successful after { time .time () - start :.1f} s" )
270309 return
310+ print (f"[DEBUG] Health check attempt after { time .time () - start :.1f} s: status={ last_status } " )
271311 time .sleep (5 ) # Retry every 5 seconds
272312
273313 print (
0 commit comments