mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0013-v2v-rhv-upload-plugin-improve-wait-logic-after-final.patch

4ebc84
From 93e40ab489cdfd7df2cb12de07183e7df6c6c36c Mon Sep 17 00:00:00 2001
4ebc84
From: Daniel Erez <derez@redhat.com>
4ebc84
Date: Mon, 18 Mar 2019 18:51:26 +0200
4ebc84
Subject: [PATCH] v2v: rhv-upload-plugin - improve wait logic after finalize
4ebc84
 (RHBZ#1680361)
4ebc84
4ebc84
After invoking transfer_service.finalize, check operation status by
4ebc84
examining DiskStatus.  This is done instead of failing after a
4ebc84
predefined timeout regardless the status.
4ebc84
4ebc84
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1680361
4ebc84
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
4ebc84
Tested-by: Ilanit Stein <istein@redhat.com>
4ebc84
(cherry picked from commit eeabb3fdc7756887b53106f455a7b54309130637)
4ebc84
---
4ebc84
 v2v/rhv-upload-plugin.py | 19 +++++++++++++------
4ebc84
 1 file changed, 13 insertions(+), 6 deletions(-)
4ebc84
4ebc84
diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
4ebc84
index 2a950c5ed..4d61a089b 100644
4ebc84
--- a/v2v/rhv-upload-plugin.py
4ebc84
+++ b/v2v/rhv-upload-plugin.py
4ebc84
@@ -523,16 +523,23 @@ def close(h):
4ebc84
         # waiting for the transfer object to cease to exist, which
4ebc84
         # falls through to the exception case and then we can
4ebc84
         # continue.
4ebc84
-        endt = time.time() + timeout
4ebc84
+        disk_id = disk.id
4ebc84
+        start = time.time()
4ebc84
         try:
4ebc84
             while True:
4ebc84
                 time.sleep(1)
4ebc84
-                tmp = transfer_service.get()
4ebc84
-                if time.time() > endt:
4ebc84
-                    raise RuntimeError("timed out waiting for transfer "
4ebc84
-                                       "to finalize")
4ebc84
+                disk_service = h['disk_service']
4ebc84
+                disk = disk_service.get()
4ebc84
+                if disk.status == types.DiskStatus.LOCKED:
4ebc84
+                    if time.time() > start + timeout:
4ebc84
+                        raise RuntimeError("timed out waiting for transfer "
4ebc84
+                                           "to finalize")
4ebc84
+                    continue
4ebc84
+                if disk.status == types.DiskStatus.OK:
4ebc84
+                    debug("finalized after %s seconds" % (time.time() - start))
4ebc84
+                    break
4ebc84
         except sdk.NotFoundError:
4ebc84
-            pass
4ebc84
+            raise RuntimeError("transfer failed: disk %s not found" % disk_id)
4ebc84
 
4ebc84
         # Write the disk ID file.  Only do this on successful completion.
4ebc84
         with builtins.open(params['diskid_file'], 'w') as fp:
4ebc84
-- 
4ebc84
2.21.0
4ebc84