CA-182595 VM.hard_shutdown: use subtask for cancelling
CA-182595 VM.hard_shutdown: use subtask for cancelling

Also same for VM.hard_reboot.

When Message_forwarding.VM.hard_shutdown cancels other tasks such as
clean_shutdown, now it uses a fresh subtask for each cancellation,
instead of doing the cancellation more directly.

This fixes a bug: if a clean_shutdown task was in progress on a VM on
a slave, then VM.hard_shutdown invoked via "xe vm-shutdown --force"
would fail after cancelling the clean_shutdown. This was because when
the call to the slave (to cancel the clean_shutdown) completes, it
marks the task running it as completed successfully. Since this task
was the main task for the hard_shutdown, the waiter in cli_operations
noticed and destroyed the task, logging out the corresponding xapi
session and telling xe that the command had succeeded. Therefore when
Message_forwarding.VM.hard_shutdown went on to its next step and
tried to tell the slave to shut down the VM, it was using an expired
xapi session so it failed.

Therefore using a new subtask for the cancellation fixes the bug.

The same problem was not observed for "xe vm-reboot --force" because
in Cli_operations.vm_reboot makes a straightforward synchronous call,
whereas vm_shutdown makes an async call and passes the task to the
waiter function.  Nonetheless, the task was still being marked
prematurely as completed, so this commit makes the same change in
Message_forwarding.VM.hard_reboot as in the corresponding shutdown.

Signed-off-by: Thomas Sanders <c547603d2dd860735c4f0c043b1348f5c48c02f8@citrix.com>

rafalmiel/xen-api,rafalmiel/xen-api,Frezzle/xen-api,salvocambria/xen-api,simonjbeaumont/xen-api,euanh/xen-api,agimofcarmen/xen-api,djs55/xen-api,robertbreker/xen-api,guard163/xen-api,thomassa/xen-api,Frezzle/xen-api,euanh/xen-api,rafalmiel/xen-api,djs55/xen-api,guard163/xen-api,agimofcarmen/xen-api,srowe/xen-api,euanh/xen-api,agimofcarmen/xen-api,Frezzle/xen-api,salvocambria/xen-api,guard163/xen-api,thomassa/xen-api,jjd27/xen-api,euanh/xen-api,anoobs/xen-api,guard163/xen-api,jjd27/xen-api,Frezzle/xen-api,agimofcarmen/xen-api,anoobs/xen-api,djs55/xen-api,anoobs/xen-api,guard163/xen-api,jjd27/xen-api,agimofcarmen/xen-api,robertbreker/xen-api,anoobs/xen-api,rafalmiel/xen-api,euanh/xen-api,anoobs/xen-api,simonjbeaumont/xen-api,robertbreker/xen-api,srowe/xen-api,djs55/xen-api,simonjbeaumont/xen-api,vasilenkomike/xen-api,thomassa/xen-api,guard163/xen-api,vasilenkomike/xen-api,rafalmiel/xen-api,salvocambria/xen-api,Frezzle/xen-api,vasilenkomike/xen-api,jjd27/xen-api,vasilenkomike/xen-api,robertbreker/xen-api,vasilenkomike/xen-api,jjd27/xen-api,jjd27/xen-api,srowe/xen-api,simonjbeaumont/xen-api,vasilenkomike/xen-api,thomassa/xen-api,salvocambria/xen-api,euanh/xen-api,robertbreker/xen-api,simonjbeaumont/xen-api,thomassa/xen-api,djs55/xen-api,rafalmiel/xen-api,djs55/xen-api,salvocambria/xen-api,srowe/xen-api,thomassa/xen-api,robertbreker/xen-api,agimofcarmen/xen-api,simonjbeaumont/xen-api,salvocambria/xen-api,anoobs/xen-api,srowe/xen-api