21
21
)
22
22
from .tester import ConnectionTesterFactory
23
23
from .utils import (
24
+ DeploymentError ,
24
25
get_conflicting_ports_from_compose ,
25
26
get_host_ip ,
26
27
get_huggingface_token_from_file ,
@@ -219,14 +220,11 @@ def run_interactive_deployment(self):
219
220
return
220
221
221
222
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." )
224
224
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." )
227
226
if not self .configure_services ():
228
- log_message ("ERROR" , "Service configuration failed. Aborting deployment." )
229
- return
227
+ raise DeploymentError ("Service configuration failed. Aborting deployment." )
230
228
231
229
if self .args .deploy_mode == "docker" :
232
230
self .project_name = f"{ self .example_name .lower ().replace (' ' , '' )} -{ self .args .device } "
@@ -253,14 +251,9 @@ def run_interactive_deployment(self):
253
251
env_vars = parse_shell_env_file (local_env_file )
254
252
conflicting_ports = get_conflicting_ports_from_compose (self ._get_docker_compose_files (), env_vars )
255
253
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 )} " )
261
255
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
264
257
265
258
try :
266
259
log_message ("INFO" , "Starting deployment..." )
@@ -290,7 +283,7 @@ def run_interactive_deployment(self):
290
283
elif self .args .deploy_mode == "k8s" :
291
284
ns = self .config ["kubernetes" ]["namespace" ]
292
285
log_message ("INFO" , f"Inspect pods with 'kubectl get pods -n { ns } '." )
293
- return
286
+ raise DeploymentError ( "Deployment command failed." ) from e
294
287
295
288
if self .args .do_test_connection :
296
289
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):
311
304
elif self .args .deploy_mode == "k8s" :
312
305
ns = self .config ["kubernetes" ]["namespace" ]
313
306
log_message ("INFO" , f"Please inspect pod status with 'kubectl get pods -n { ns } '." )
307
+ raise DeploymentError ("Connection tests failed after deployment." )
314
308
else :
315
309
log_message ("OK" , "All connection tests passed." )
316
310
@@ -413,10 +407,12 @@ def run_interactive_clear(self):
413
407
return
414
408
415
409
try :
416
- self .clear_deployment ()
410
+ if not self .clear_deployment ():
411
+ raise DeploymentError ("Cleanup process failed. Please check logs." )
417
412
log_message ("OK" , "Cleanup process completed successfully." )
418
413
except Exception as e :
419
414
log_message ("ERROR" , f"An unexpected error occurred during cleanup: { e } " )
415
+ raise # Re-raise the exception to be caught by the main CLI
420
416
421
417
def _interactive_setup_for_clear (self ):
422
418
section_header (f"{ self .example_name } Interactive Clear Setup" )
@@ -450,10 +446,12 @@ def run_interactive_test(self):
450
446
return
451
447
452
448
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." )
455
452
except Exception as e :
456
453
log_message ("ERROR" , f"An unexpected error occurred during testing: { e } " )
454
+ raise # Re-raise
457
455
458
456
def _interactive_setup_for_test (self ):
459
457
"""Gathers necessary information for testing and updates self.args."""
@@ -755,25 +753,28 @@ def clear_deployment(self, clear_local_config=True):
755
753
log_message ("ERROR" , f" STDOUT: { result .stdout .strip ()} " )
756
754
if result .stderr :
757
755
log_message ("ERROR" , f" STDERR: { result .stderr .strip ()} " )
756
+ raise DeploymentError ("Docker Compose down command failed." )
758
757
else :
759
758
log_message ("OK" , "Docker Compose services stopped and removed." )
760
759
if clear_local_config :
761
760
local_env_file = self ._get_local_env_file_path ()
762
761
if local_env_file and local_env_file .exists ():
763
762
local_env_file .unlink ()
764
763
log_message ("INFO" , f"Removed generated config file: { local_env_file .name } " )
765
- return result . returncode == 0
764
+ return True
766
765
except Exception as e :
767
766
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
769
768
770
769
elif self .args .deploy_mode == "k8s" :
771
770
cfg = self .config ["kubernetes" ]
771
+ all_ok = True
772
772
try :
773
773
run_command (["helm" , "uninstall" , cfg ["release_name" ], "--namespace" , cfg ["namespace" ]], check = False )
774
774
log_message ("OK" , f"Helm release '{ cfg ['release_name' ]} ' uninstalled." )
775
775
except Exception as e :
776
776
log_message ("WARN" , f"Helm uninstall may have failed: { e } " )
777
+ all_ok = False
777
778
local_values_file = self ._get_local_helm_values_file_path ()
778
779
if local_values_file and local_values_file .exists ():
779
780
try :
@@ -790,7 +791,10 @@ def clear_deployment(self, clear_local_config=True):
790
791
log_message ("OK" , f"Namespace '{ cfg ['namespace' ]} ' deleted." )
791
792
except Exception as e :
792
793
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." )
794
798
return True
795
799
return False
796
800
0 commit comments