mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

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

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