qemu: Use wait_for replace hardcode sleep time.

Re-organize the code and add error.conext() support.

Signed-off-by: Feng Yang <fyang@redhat.com>