putting a host in maintenance mode means moving all the VMs from the host to another host (effectively this is a live migration that requires the VM's host to change from the source host to the destination host).
Because of the potential concurrent execution of compute/manager->_sync_power_states, it is possible that after the migration, the state of the VM becomes SHUTOFF.
Looking at the implementation of _sync_power_states this problem can be solved by ensuring that the VM's host field is updated prior to the actual VM migration, and by reverting it to the old value if something goes wrong.
Current code in virt/xenapi/host.py was updating the VM's host field after the VM was migrated (to save one DB call in case of failures); clearly this does cause the race condition and need to be fixed.
Fix proposed to branch: master /review. openstack. org/4761
Review: https:/