libguestfs/SOURCES/0033-v2v-o-rhv-upload-chang...

54 lines
2.0 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

From bb04eba9683c4143f9b5880238f006af3b13c05c Mon Sep 17 00:00:00 2001
From: Pino Toscano <ptoscano@redhat.com>
Date: Thu, 12 Sep 2019 14:17:36 +0200
Subject: [PATCH] v2v: -o rhv-upload: change precheck script to return a JSON
This way it is possible to communicate data from the precheck script
back to virt-v2v.
For now there are no results, so the resulting JSON is discarded.
(cherry picked from commit cc6e2a7f9ea53258c2edb758e3ec9beb7baa1fc6)
---
v2v/output_rhv_upload.ml | 8 +++++++-
v2v/rhv-upload-precheck.py | 6 +++++-
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/v2v/output_rhv_upload.ml b/v2v/output_rhv_upload.ml
index adcbdf25f..fd6f2e3e6 100644
--- a/v2v/output_rhv_upload.ml
+++ b/v2v/output_rhv_upload.ml
@@ -234,8 +234,14 @@ object
error_unless_nbdkit_python_plugin_working ();
error_unless_output_alloc_sparse ();
(* Python code prechecks. *)
- if Python_script.run_command precheck_script json_params [] <> 0 then
+ 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
+ precheck_script json_params [] <> 0 then
error (f_"failed server prechecks, see earlier errors");
+ let json = JSON_parser.json_parser_tree_parse_file precheck_fn in
+ debug "precheck output parsed as: %s"
+ (JSON.string_of_doc ~fmt:JSON.Indented ["", json]);
if have_selinux then
error_unless_nbdkit_compiled_with_selinux ()
diff --git a/v2v/rhv-upload-precheck.py b/v2v/rhv-upload-precheck.py
index d6a58f0fc..de8a66c05 100644
--- a/v2v/rhv-upload-precheck.py
+++ b/v2v/rhv-upload-precheck.py
@@ -70,4 +70,8 @@ if len(clusters) == 0:
raise RuntimeError("The cluster %s does not exist" %
(params['rhv_cluster']))
-# Otherwise everything is OK, exit with no error.
+# Otherwise everything is OK, print a JSON with the results.
+results = {
+}
+
+json.dump(results, sys.stdout)
--
2.18.4