2121)
2222from .tester import ConnectionTesterFactory
2323from .utils import (
24+ DeploymentError ,
2425 get_conflicting_ports_from_compose ,
2526 get_host_ip ,
2627 get_huggingface_token_from_file ,
@@ -219,14 +220,11 @@ def run_interactive_deployment(self):
219220 return
220221
221222 if self .args .do_check_env and not self .check_environment ():
222- log_message ("ERROR" , "Environment check failed. Aborting deployment." )
223- return
223+ raise DeploymentError ("Environment check failed. Aborting deployment." )
224224 if self .args .do_update_images and not self .update_images ():
225- log_message ("ERROR" , "Image update failed. Aborting deployment." )
226- return
225+ raise DeploymentError ("Image update failed. Aborting deployment." )
227226 if not self .configure_services ():
228- log_message ("ERROR" , "Service configuration failed. Aborting deployment." )
229- return
227+ raise DeploymentError ("Service configuration failed. Aborting deployment." )
230228
231229 if self .args .deploy_mode == "docker" :
232230 self .project_name = f"{ self .example_name .lower ().replace (' ' , '' )} -{ self .args .device } "
@@ -253,14 +251,9 @@ def run_interactive_deployment(self):
253251 env_vars = parse_shell_env_file (local_env_file )
254252 conflicting_ports = get_conflicting_ports_from_compose (self ._get_docker_compose_files (), env_vars )
255253 if conflicting_ports :
256- log_message (
257- "ERROR" ,
258- f"Deployment aborted. Ports are in use by other applications: { sorted (conflicting_ports )} " ,
259- )
260- return
254+ raise DeploymentError (f"Ports are in use by other applications: { sorted (conflicting_ports )} " )
261255 except Exception as e :
262- log_message ("ERROR" , f"Failed during pre-deployment check: { e } " )
263- return
256+ raise DeploymentError (f"Failed during pre-deployment check: { e } " ) from e
264257
265258 try :
266259 log_message ("INFO" , "Starting deployment..." )
@@ -290,7 +283,7 @@ def run_interactive_deployment(self):
290283 elif self .args .deploy_mode == "k8s" :
291284 ns = self .config ["kubernetes" ]["namespace" ]
292285 log_message ("INFO" , f"Inspect pods with 'kubectl get pods -n { ns } '." )
293- return
286+ raise DeploymentError ( "Deployment command failed." ) from e
294287
295288 if self .args .do_test_connection :
296289 log_message ("INFO" , f"Waiting for { POST_DEPLOY_WAIT_S } seconds for services to stabilize before testing..." )
@@ -311,6 +304,7 @@ def run_interactive_deployment(self):
311304 elif self .args .deploy_mode == "k8s" :
312305 ns = self .config ["kubernetes" ]["namespace" ]
313306 log_message ("INFO" , f"Please inspect pod status with 'kubectl get pods -n { ns } '." )
307+ raise DeploymentError ("Connection tests failed after deployment." )
314308 else :
315309 log_message ("OK" , "All connection tests passed." )
316310
@@ -413,10 +407,12 @@ def run_interactive_clear(self):
413407 return
414408
415409 try :
416- self .clear_deployment ()
410+ if not self .clear_deployment ():
411+ raise DeploymentError ("Cleanup process failed. Please check logs." )
417412 log_message ("OK" , "Cleanup process completed successfully." )
418413 except Exception as e :
419414 log_message ("ERROR" , f"An unexpected error occurred during cleanup: { e } " )
415+ raise # Re-raise the exception to be caught by the main CLI
420416
421417 def _interactive_setup_for_clear (self ):
422418 section_header (f"{ self .example_name } Interactive Clear Setup" )
@@ -450,10 +446,12 @@ def run_interactive_test(self):
450446 return
451447
452448 try :
453- self .test_connection ()
454- log_message ("OK" , "Testing process completed." )
449+ if not self .test_connection ():
450+ raise DeploymentError ("Connection tests failed." )
451+ log_message ("OK" , "Testing process completed successfully." )
455452 except Exception as e :
456453 log_message ("ERROR" , f"An unexpected error occurred during testing: { e } " )
454+ raise # Re-raise
457455
458456 def _interactive_setup_for_test (self ):
459457 """Gathers necessary information for testing and updates self.args."""
@@ -755,25 +753,28 @@ def clear_deployment(self, clear_local_config=True):
755753 log_message ("ERROR" , f" STDOUT: { result .stdout .strip ()} " )
756754 if result .stderr :
757755 log_message ("ERROR" , f" STDERR: { result .stderr .strip ()} " )
756+ raise DeploymentError ("Docker Compose down command failed." )
758757 else :
759758 log_message ("OK" , "Docker Compose services stopped and removed." )
760759 if clear_local_config :
761760 local_env_file = self ._get_local_env_file_path ()
762761 if local_env_file and local_env_file .exists ():
763762 local_env_file .unlink ()
764763 log_message ("INFO" , f"Removed generated config file: { local_env_file .name } " )
765- return result . returncode == 0
764+ return True
766765 except Exception as e :
767766 log_message ("ERROR" , f"Failed to clear Docker Compose deployment: { e } " )
768- return False
767+ raise DeploymentError ( "Failed to clear Docker Compose deployment." ) from e
769768
770769 elif self .args .deploy_mode == "k8s" :
771770 cfg = self .config ["kubernetes" ]
771+ all_ok = True
772772 try :
773773 run_command (["helm" , "uninstall" , cfg ["release_name" ], "--namespace" , cfg ["namespace" ]], check = False )
774774 log_message ("OK" , f"Helm release '{ cfg ['release_name' ]} ' uninstalled." )
775775 except Exception as e :
776776 log_message ("WARN" , f"Helm uninstall may have failed: { e } " )
777+ all_ok = False
777778 local_values_file = self ._get_local_helm_values_file_path ()
778779 if local_values_file and local_values_file .exists ():
779780 try :
@@ -790,7 +791,10 @@ def clear_deployment(self, clear_local_config=True):
790791 log_message ("OK" , f"Namespace '{ cfg ['namespace' ]} ' deleted." )
791792 except Exception as e :
792793 log_message ("ERROR" , f"Failed to delete namespace: { e } " )
793- return False
794+ all_ok = False
795+
796+ if not all_ok :
797+ raise DeploymentError ("Kubernetes cleanup failed. Some resources may remain." )
794798 return True
795799 return False
796800
0 commit comments