[Libguestfs] [v2v PATCH 2/2] rhv-upload: Check that rhv-disk-uuid is not already taken (RHBZ#1789279)

Pino Toscano ptoscano at redhat.com
Mon Jan 27 11:01:48 UTC 2020


On Thursday, 23 January 2020 23:12:23 CET Martin Kletzander wrote:
> This makes the code fail with a sensible error message instead of cryptic error
> from ovirtsdk.
> 
> Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
> ---
>  v2v/rhv-upload-plugin.py | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
> index d3e6260e97f4..edb2699214c2 100644
> --- a/v2v/rhv-upload-plugin.py
> +++ b/v2v/rhv-upload-plugin.py
> @@ -26,6 +26,9 @@ import ssl
>  import sys
>  import time
>  
> +import nbdkit
> +import errno
> +
>  from http.client import HTTPSConnection, HTTPConnection
>  from urllib.parse import urlparse
>  
> @@ -461,6 +464,15 @@ def create_disk(connection):
>      system_service = connection.system_service()
>      disks_service = system_service.disks_service()
>  
> +    uuid = params.get('rhv_disk_uuid')
> +    if uuid is not None:

'is not None' can be avoided. (Yes, there are few occurrences of that,
should be changed too IMHO.)

> +        try:
> +            disks_service.disk_service(uuid).get()
> +            nbdkit.set_error(errno.EINVAL)

Maybe EEXIST rather than EINVAL?

> +            raise ValueError("Disk with the specified UUID already exists")

Print also the UUID, so it is easier to debug a failure even without
the virt-v2v command line.

With the above fixes, LGTM.

-- 
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20200127/3a6328e2/attachment.sig>


More information about the Libguestfs mailing list