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

Nir Soffer nsoffer at redhat.com
Thu Nov 21 11:32:20 UTC 2019


On Wed, Nov 20, 2019 at 1:19 AM Nir Soffer <nirsof at gmail.com> wrote:
>
> 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

Richard, this should be merged before you release 1.48. Without this we can
leave leftover disks if get_options() raises.

> 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