@@ -157,6 +157,12 @@ def deploy_machines(self, lab: Lab, selected_machines: Set[str] = None) -> None:
157
157
# Do not open terminals on Megalos
158
158
Setting .get_instance ().open_terminals = False
159
159
160
+ wait_thread = threading .Thread (
161
+ target = self ._wait_machines_startup ,
162
+ args = (lab , selected_machines if selected_machines else None )
163
+ )
164
+ wait_thread .start ()
165
+
160
166
# Deploy all lab machines.
161
167
# If there is no lab.dep file, machines can be deployed using multithreading.
162
168
# If not, they're started sequentially
@@ -171,7 +177,7 @@ def deploy_machines(self, lab: Lab, selected_machines: Set[str] = None) -> None:
171
177
for item in machines :
172
178
self ._deploy_machine (item )
173
179
174
- self . _wait_machines_startup ( lab , selected_machines if selected_machines else None )
180
+ wait_thread . join ( )
175
181
176
182
def _wait_machines_startup (self , lab : Lab , selected_machines : Set [str ]) -> None :
177
183
"""Wait the startup of the selected machines. Return when the selected machines become `Ready`.
@@ -492,14 +498,17 @@ def undeploy(self, lab_hash: str, selected_machines: Optional[Set[str]] = None)
492
498
selected_machines = {item .metadata .labels ["name" ] for item in pods }
493
499
494
500
if len (pods ) > 0 :
501
+ wait_thread = threading .Thread (target = self ._wait_machines_shutdown , args = (lab_hash , selected_machines ))
502
+ wait_thread .start ()
503
+
495
504
pool_size = utils .get_pool_size ()
496
505
items = utils .chunk_list (pods , pool_size )
497
506
498
507
with Pool (pool_size ) as machines_pool :
499
508
for chunk in items :
500
509
machines_pool .map (func = self ._undeploy_machine , iterable = chunk )
501
510
502
- self . _wait_machines_shutdown ( lab_hash , selected_machines )
511
+ wait_thread . join ( )
503
512
504
513
def _wait_machines_shutdown (self , lab_hash : str , selected_machines : Set [str ]):
505
514
"""Wait the shutdown of the selected machines. Return when all the selected machines are terminated.
@@ -576,24 +585,15 @@ def _delete_machine(self, pod_api_object: client.V1Pod) -> None:
576
585
try :
577
586
shell_env_value = self .get_env_var_value_from_pod (pod_api_object , "_MEGALOS_SHELL" )
578
587
shell = shell_env_value if shell_env_value else Setting .get_instance ().device_shell
579
- output = self .exec (machine_namespace ,
580
- machine_name ,
581
- command = [shell , '-c' , shutdown_commands_string ],
582
- )
583
-
584
- try :
585
- next (output )
586
- except StopIteration :
587
- pass
588
-
589
- deployment_name = self .get_deployment_name (machine_name )
590
- self .kubernetes_config_map .delete_for_machine (deployment_name , machine_namespace )
591
-
592
- self .client .delete_namespaced_deployment (name = deployment_name ,
593
- namespace = machine_namespace
594
- )
588
+ self .exec (machine_namespace , machine_name , command = [shell , '-c' , shutdown_commands_string ], is_stream = False )
595
589
except ApiException :
596
- return
590
+ pass
591
+ except MachineNotRunningError :
592
+ pass
593
+
594
+ deployment_name = self .get_deployment_name (machine_name )
595
+ self .kubernetes_config_map .delete_for_machine (deployment_name , machine_namespace )
596
+ self .client .delete_namespaced_deployment (name = deployment_name , namespace = machine_namespace )
597
597
598
598
def connect (self , lab_hash : str , machine_name : str , shell : Union [str , List [str ]] = None , logs : bool = False ) \
599
599
-> None :
0 commit comments