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

Martin Kletzander mkletzan at redhat.com
Wed Mar 11 14:54:34 UTC 2020


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/output_rhv_upload.ml   |  6 ++++++
 v2v/rhv-upload-precheck.py | 10 ++++++++++
 2 files changed, 16 insertions(+)

diff --git a/v2v/output_rhv_upload.ml b/v2v/output_rhv_upload.ml
index e833569318b3..c9fce5b95ec6 100644
--- a/v2v/output_rhv_upload.ml
+++ b/v2v/output_rhv_upload.ml
@@ -262,6 +262,12 @@ object
     error_unless_output_alloc_sparse output_alloc;
 
     (* Python code prechecks. *)
+    let json_params = match rhv_options.rhv_disk_uuids with
+    | None -> json_params
+    | Some uuids ->
+        let ids = List.map (fun uuid -> JSON.String uuid) uuids in
+        ("rhv_disk_uuids", JSON.List ids) :: json_params
+    in
     let precheck_fn = tmpdir // "v2vprecheck.json" in
     let fd = Unix.openfile precheck_fn [O_WRONLY; O_CREAT] 0o600 in
     if Python_script.run_command ~stdout_fd:fd
diff --git a/v2v/rhv-upload-precheck.py b/v2v/rhv-upload-precheck.py
index ec3fcf4e5c20..0daa485e073b 100644
--- a/v2v/rhv-upload-precheck.py
+++ b/v2v/rhv-upload-precheck.py
@@ -97,6 +97,16 @@ if cpu.architecture == types.Architecture.UNDEFINED:
     raise RuntimeError("The cluster ‘%s’ has an unknown architecture" %
                        (params['rhv_cluster']))
 
+# Find if any disk already exists with specified UUID.
+disks_service = system_service.disks_service()
+
+for uuid in params.get('rhv_disk_uuids', []):
+    try:
+        disk_service = disks_service.disk_service(uuid).get()
+        raise RuntimeError("Disk with the UUID '%s' already exists" % uuid)
+    except sdk.NotFoundError:
+        pass
+
 # Otherwise everything is OK, print a JSON with the results.
 results = {
     "rhv_storagedomain_uuid": storage_domain.id,
-- 
2.25.1




More information about the Libguestfs mailing list