@@ -104,6 +104,10 @@ class Azure(Machinery):
104
104
WINDOWS_PLATFORM = "windows"
105
105
LINUX_PLATFORM = "linux"
106
106
107
+ # Statuses for machines
108
+ ABSENT = "absent_vm"
109
+ REIMAGE_FAILING = "failed_reimaging"
110
+
107
111
def set_options (self , options : dict ) -> None :
108
112
"""Set machine manager options.
109
113
@param options: machine manager options dict.
@@ -454,17 +458,11 @@ def start(self, label=None):
454
458
# Something bad happened, we are starting a task on a machine that needs to be deleted
455
459
with vms_currently_being_deleted_lock :
456
460
if label in vms_currently_being_deleted :
457
- err_msg = (
458
- f"Attempting to start a task with machine { label } while it is scheduled for deletion."
459
- f"Reassigning the task and removing { label } from the database."
460
- )
461
- log .error (err_msg )
462
- raise CuckooMachineError (err_msg )
461
+ raise CuckooMachineError (f"Attempting to start a task with machine { label } while it is scheduled for deletion." )
463
462
464
463
def stop (self , label = None ):
465
464
"""
466
- If the VMSS is in the "scaling-down" state, delete machine,
467
- otherwise reimage it.
465
+ If the VMSS is NOT in the "scaling-down" state, reimage it.
468
466
@param label: virtual machine label
469
467
@return: End method call
470
468
"""
@@ -486,8 +484,16 @@ def stop(self, label=None):
486
484
label_in_reimage_vm_list = label in [f"{ vm ['vmss' ]} _{ vm ['id' ]} " for vm in reimage_vm_list ]
487
485
488
486
def release (self , machine : Machine ):
487
+ """
488
+ Delete machine if its VMSS is in the "scaling-down" state, it was found to be absent from its VMSS during
489
+ reimaging, or reimaging timed out.
490
+ Otherwise, release the successfully reimaged machine.
491
+ @param label: machine label.
492
+ """
489
493
vmss_name = machine .label .split ("_" )[0 ]
490
- if machine_pools [vmss_name ]["is_scaling_down" ]:
494
+ if machine .status == Azure .ABSENT :
495
+ self .delete_machine (machine .label , delete_from_vmss = False )
496
+ elif machine .status == Azure .REIMAGE_FAILING or machine_pools [vmss_name ]["is_scaling_down" ]:
491
497
self .delete_machine (machine .label )
492
498
else :
493
499
_ = super (Azure , self ).release (machine )
@@ -1282,8 +1288,7 @@ def _thr_reimage_list_reader(self):
1282
1288
vms_currently_being_deleted .append (f"{ vmss_to_reimage } _{ instance_id } " )
1283
1289
with delete_lock :
1284
1290
delete_vm_list .append ({"vmss" : vmss_to_reimage , "id" : instance_id , "time_added" : time .time ()})
1285
-
1286
- self .delete_machine (f"{ vmss_to_reimage } _{ instance_id } " , delete_from_vmss = False )
1291
+ self .set_status (f"{ vmss_to_reimage } _{ instance_id } " , Azure .ABSENT )
1287
1292
vms_currently_being_reimaged .remove (f"{ vmss_to_reimage } _{ instance_id } " )
1288
1293
instance_ids .remove (instance_id )
1289
1294
@@ -1299,12 +1304,12 @@ def _thr_reimage_list_reader(self):
1299
1304
if (timeit .default_timer () - start_time ) > AZURE_TIMEOUT :
1300
1305
reimaged = False
1301
1306
1302
- log .debug (
1307
+ log .warning (
1303
1308
f"Reimaging machines { instance_ids } in { vmss_to_reimage } took too long, deleting them from the DB and the VMSS."
1304
1309
)
1305
- # That sucks, now we have to delete each one
1310
+ # That sucks, now we have mark each one for deletion
1306
1311
for instance_id in instance_ids :
1307
- self .delete_machine (f"{ vmss_to_reimage } _{ instance_id } " )
1312
+ self .set_status (f"{ vmss_to_reimage } _{ instance_id } " , Azure . REIMAGE_FAILING )
1308
1313
break
1309
1314
time .sleep (2 )
1310
1315
@@ -1373,7 +1378,7 @@ def _thr_delete_list_reader(self):
1373
1378
while not async_delete_some_machines .done ():
1374
1379
deleted = True
1375
1380
if (timeit .default_timer () - start_time ) > AZURE_TIMEOUT :
1376
- log .debug (f"Deleting machines { instance_ids } in { vmss_to_delete_from } took too long." )
1381
+ log .warning (f"Deleting machines { instance_ids } in { vmss_to_delete_from } took too long." )
1377
1382
deleted = False
1378
1383
break
1379
1384
time .sleep (2 )
0 commit comments