[Libguestfs] [PATCH v2] v2v: rhv-upload-plugin - improve wait logic after finalize (RHBZ#1680361)

Nir Soffer nsoffer at redhat.com
Sun Mar 17 14:08:44 UTC 2019


On Sun, Mar 17, 2019 at 3:51 PM Daniel Erez <derez at redhat.com> wrote:

> After invoking transfer_service.finalize, check operation
> status by examining DiskStatus.
> This is done instead of failing after a predefined timeout
> regardless the status.
>
> * not verified *
>
> Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1680361
> ---
>  v2v/rhv-upload-plugin.py | 18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
> index 2a950c5ed..6f65e034b 100644
> --- a/v2v/rhv-upload-plugin.py
> +++ b/v2v/rhv-upload-plugin.py
> @@ -523,15 +523,23 @@ def close(h):
>          # waiting for the transfer object to cease to exist, which
>          # falls through to the exception case and then we can
>          # continue.
> -        endt = time.time() + timeout
> +        disk_id = disk.id
> +        start = time.time()
>          try:
>              while True:
>                  time.sleep(1)
> -                tmp = transfer_service.get()
> -                if time.time() > endt:
> -                    raise RuntimeError("timed out waiting for transfer "
> -                                       "to finalize")
> +                disk_service = h['disk_service']
>

We can clean this a little bit by doing this outside of the loop.


> +                disk = disk_service.get()
> +                if disk.status == types.DiskStatus.LOCKED:
> +                    if time.time() > start + timeout:
> +                        raise RuntimeError("timed out waiting for
> transfer "
> +                                           "to finalize")
> +                    continue
> +                if disk.status == types.DiskStatus.OK:
> +                    debug("finalized after %s seconds", time.time() -
> start)
> +                    break
>          except sdk.NotFoundError:
> +            debug("transfer finalize failed for disk: %s", disk_id)
>

This should explain the failure:

    "transfer failed: disk %s not found"


>              pass
>

This should be a failure now.


>
>          # Write the disk ID file.  Only do this on successful completion.
> --
>

Waiting only for the disk is much nicer.

Nir
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20190317/5357d603/attachment.htm>


More information about the Libguestfs mailing list