Blame SOURCES/0046-rhv-upload-Fix-waiting-for-transfer.patch

46b2f6
From d132157c9e0b6b990cd989662f5499644508de97 Mon Sep 17 00:00:00 2001
46b2f6
From: Nir Soffer <nsoffer@redhat.com>
46b2f6
Date: Thu, 28 Nov 2019 20:36:32 +0200
46b2f6
Subject: [PATCH] rhv-upload: Fix waiting for transfer
46b2f6
46b2f6
We were not considering failures while initializing the transfer. In
46b2f6
this case the transfer phase can change to PAUSED_SYSTEM or
46b2f6
FINISHED_FAILURE, and transfer_url will be None, which failed the
46b2f6
upload with a misleading error:
46b2f6
46b2f6
    RuntimeError: direct upload to host not supported, requires
46b2f6
    ovirt-engine >= 4.2 and only works when virt-v2v is run within the
46b2f6
    oVirt/RHV environment, eg. on an oVirt node
46b2f6
46b2f6
Change the wait loop to consider all cases:
46b2f6
- Transfer failed and was removed
46b2f6
- Transfer failed and will be removed soon
46b2f6
- Transfer paused by the system (cancel required)
46b2f6
- Unexpected transfer phase (cancel required)
46b2f6
- Timeout waiting for TRANSFERRING state (cancel required)
46b2f6
46b2f6
Reported-by: Xiaodai Wang
46b2f6
46b2f6
(cherry picked from commit 40e1844827e4d096b1919a2159f9effc41915a73
46b2f6
in virt-v2v)
46b2f6
---
46b2f6
 v2v/rhv-upload-plugin.py | 41 +++++++++++++++++++++++++++++++---------
46b2f6
 1 file changed, 32 insertions(+), 9 deletions(-)
46b2f6
46b2f6
diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
46b2f6
index 9b83d1cfa..14d4e37fb 100644
46b2f6
--- a/v2v/rhv-upload-plugin.py
46b2f6
+++ b/v2v/rhv-upload-plugin.py
46b2f6
@@ -185,20 +185,43 @@ def open(readonly):
46b2f6
     # Get a reference to the created transfer service.
46b2f6
     transfer_service = transfers_service.image_transfer_service(transfer.id)
46b2f6
 
46b2f6
-    # After adding a new transfer for the disk, the transfer's status
46b2f6
-    # will be INITIALIZING.  Wait until the init phase is over. The
46b2f6
-    # actual transfer can start when its status is "Transferring".
46b2f6
+    # Wait until transfer's phase change from INITIALIZING to TRANSFERRING. On
46b2f6
+    # errors transfer's phase can change to PAUSED_SYSTEM or FINISHED_FAILURE.
46b2f6
+    # If the transfer was paused, we need to cancel it to remove the disk,
46b2f6
+    # otherwise the system will remove the disk and transfer shortly after.
46b2f6
+
46b2f6
     endt = time.time() + timeout
46b2f6
     while True:
46b2f6
-        transfer = transfer_service.get()
46b2f6
-        if transfer.phase != types.ImageTransferPhase.INITIALIZING:
46b2f6
+        time.sleep(1)
46b2f6
+        try:
46b2f6
+            transfer = transfer_service.get()
46b2f6
+        except sdk.NotFoundError:
46b2f6
+            # The system has removed the disk and the transfer.
46b2f6
+            raise RuntimeError("transfer %s was removed" % transfer.id)
46b2f6
+
46b2f6
+        if transfer.phase == types.ImageTransferPhase.FINISHED_FAILURE:
46b2f6
+            # The system will remove the disk and the transfer soon.
46b2f6
+            raise RuntimeError(
46b2f6
+                "transfer %s has failed" % transfer.id)
46b2f6
+
46b2f6
+        if transfer.phase == types.ImageTransferPhase.PAUSED_SYSTEM:
46b2f6
+            transfer_service.cancel()
46b2f6
+            raise RuntimeError(
46b2f6
+                "transfer %s was paused by system" % transfer.id)
46b2f6
+
46b2f6
+        if transfer.phase == types.ImageTransferPhase.TRANSFERRING:
46b2f6
             break
46b2f6
-        if time.time() > endt:
46b2f6
+
46b2f6
+        if transfer.phase != types.ImageTransferPhase.INITIALIZING:
46b2f6
+            transfer_service.cancel()
46b2f6
             raise RuntimeError(
46b2f6
-                "timed out waiting for transfer %s status != INITIALIZING"
46b2f6
-                % transfer.id)
46b2f6
+                "unexpected transfer %s phase %s"
46b2f6
+                % (transfer.id, transfer.phase))
46b2f6
 
46b2f6
-        time.sleep(1)
46b2f6
+        if time.time() > endt:
46b2f6
+            transfer_service.cancel()
46b2f6
+            raise RuntimeError(
46b2f6
+                "timed out waiting for transfer %s" % transfer.id)
46b2f6
 
46b2f6
     # Now we have permission to start the transfer.
46b2f6
     if params['rhv_direct']:
46b2f6
-- 
b155d0
2.26.2
46b2f6