[Libguestfs] [PATCH 1/2] rhv-upload: Extract cancel_transfer() function

Nir Soffer nirsof at gmail.com
Tue Nov 19 23:19:32 UTC 2019


Extract a cancel_transfer() function, so we can cancel a transfer in
plugin handlers without keeping the transfer_service around.

Fixes a NameError when starting a transfer fails:

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/var/tmp/rhvupload.Vw0CIU/rhv-upload-plugin.py", line 97, in open
        transfer_service.cancel()
    NameError: name 'transfer_service' is not defined

Thanks: Martin Kletzander
---
 v2v/rhv-upload-plugin.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
index a2d09458..b9b9e967 100644
--- a/v2v/rhv-upload-plugin.py
+++ b/v2v/rhv-upload-plugin.py
@@ -93,7 +93,7 @@ def open(readonly):
         options = get_options(http, destination_url)
         http = optimize_http(http, host, options)
     except:
-        transfer_service.cancel()
+        cancel_transfer(connection, transfer)
         raise
 
     debug("imageio features: flush=%(can_flush)r trim=%(can_trim)r "
@@ -531,6 +531,16 @@ def create_transfer(connection, disk, host):
 
     return transfer
 
+def cancel_transfer(connection, transfer):
+    """
+    Cancel a transfer, removing the transfer disk.
+    """
+    debug("canceling transfer %s" % transfer.id)
+    transfer_service = (connection.system_service()
+                            .image_transfers_service()
+                            .image_transfer_service(transfer.id))
+    transfer_service.cancel()
+
 # oVirt imageio operations
 
 def parse_transfer_url(transfer):
-- 
2.21.0





More information about the Libguestfs mailing list