[Libguestfs] [PATCH] v2v: rhv-upload-plugin - improve wait logic after finalize (RHBZ#1680361)

Daniel Erez
2019-03-17T12:07:41Z

After invoking transfer_service.finalize, check operation
status by examining ImageTransferPhase and DiskStatus.
This is done instead of failing after a predefined timeout
regardless the status.

* not verified *

Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1680361
---
 v2v/rhv-upload-plugin.py | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
index 2a950c5ed..873c11ce1 100644
--- a/v2v/rhv-upload-plugin.py
+++ b/v2v/rhv-upload-plugin.py
@@ -523,14 +523,30 @@ def close(h):
         # waiting for the transfer object to cease to exist, which
         # falls through to the exception case and then we can
         # continue.
-        endt = time.time() + timeout
+        start = time.time()
         try:
             while True:
                 time.sleep(1)
-                tmp = transfer_service.get()
-                if time.time() > endt:
-                    raise RuntimeError("timed out waiting for transfer
"
-                                       "to finalize")
+                transfer = transfer_service.get()
+
+                if transfer is None:
+                    disk_service = h['disk_service']
+                    disk = disk_service.get()
+                    if disk.status == types.DiskStatus.OK:
+                        continue
+
+                if transfer.phase == types.ImageTransferPhase.FINISHED_SUCCESS:
+                    debug("finalized after %s seconds", time.time() -
start)
+                    break
+
+                if transfer.phase =types.ImageTransferPhase.FINALIZING_SUCCESS:
+                    if time.time() > start + timeout:
+                        raise RuntimeError("timed out waiting for transfer
"
+                                           "to finalize")
+                    continue
+
+                raise RuntimeError("Unexpected transfer phase while
finalizing "
+                                   "upload %r" % transfer.phase)
         except sdk.NotFoundError:
             pass

--