Fix bugs for node flush for stop/shutdown/restart

Previously VMs in stop/shutdown/restart states wouldn't be properly
handled during a node flush. This fixes the bugs and ensures that the
transient VM states (shutdown/restart) are completed before proceeding,
and then avoids setting a stopped/shutdown VM to shutdown/auotstart.
This commit is contained in:
Joshua Boniface 2023-08-18 10:56:03 -04:00
parent 3a4914fa5e
commit b5f996febd
1 changed files with 22 additions and 7 deletions

View File

@ -790,6 +790,19 @@ class NodeInstance(object):
self.flush_stopper = False self.flush_stopper = False
return return
# Wait for a VM in "restart" or "shutdown" state to complete transition
while self.zkhandler.read(("domain.state", dom_uuid)) in [
"restart",
"shutdown",
]:
self.logger.out(
'Waiting 2s for VM state change completion for VM "{}"'.format(
dom_uuid
),
state="i",
)
time.sleep(2)
self.logger.out( self.logger.out(
'Selecting target to migrate VM "{}"'.format(dom_uuid), state="i" 'Selecting target to migrate VM "{}"'.format(dom_uuid), state="i"
) )
@ -806,17 +819,19 @@ class NodeInstance(object):
if target_node is None: if target_node is None:
self.logger.out( self.logger.out(
'Failed to find migration target for VM "{}"; shutting down and setting autostart flag'.format( 'Failed to find migration target for running VM "{}"; shutting down and setting autostart flag'.format(
dom_uuid dom_uuid
), ),
state="e", state="e",
) )
self.zkhandler.write(
[ if self.zkhandler.read(("domain.state", dom_uuid)) in ["start"]:
(("domain.state", dom_uuid), "shutdown"), self.zkhandler.write(
(("domain.meta.autostart", dom_uuid), "True"), [
] (("domain.state", dom_uuid), "shutdown"),
) (("domain.meta.autostart", dom_uuid), "True"),
]
)
else: else:
self.logger.out( self.logger.out(
'Migrating VM "{}" to node "{}"'.format(dom_uuid, target_node), 'Migrating VM "{}" to node "{}"'.format(dom_uuid, target_node),