mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

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

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