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

Richard W.M. Jones rjones at redhat.com
Thu Nov 21 11:42:46 UTC 2019


On Thu, Nov 21, 2019 at 01:32:20PM +0200, Nir Soffer wrote:
> 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.

1.41.8 is already out the door, but don't worry we've got plenty of
integers left so this can go out in the next minor release :-)

I've pushed it now, thanks.

Rich.

> > 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
> >

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top




More information about the Libguestfs mailing list