virt-v2v/0006-o-rhv-upload-Output-outside-of-the-with-block.patch

44 lines
1.6 KiB
Diff
Raw Normal View History

From 0ea92cc02949f3e829744e6e62d861dfd8ff5607 Mon Sep 17 00:00:00 2001
From: Nir Soffer <nsoffer@redhat.com>
Date: Fri, 5 Apr 2024 23:50:27 +0300
Subject: [PATCH] -o rhv-upload: Output outside of the with block
We write the json inside a with block, so what actually happen is:
1. Computing the values
2. Dumping the json to stdout
3. Closing the connection
If some code in sdk.Connection.close() write something to stdout, it
will corrupt our json output. Avoid this by moving the output out of the
with block.
This will not prevent bad code to write something before the json. We
need to log bad json in the Ocaml code to reveal such issue.
---
output/rhv-upload-transfer.py | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/output/rhv-upload-transfer.py b/output/rhv-upload-transfer.py
index 7530f73e..349e0f59 100644
--- a/output/rhv-upload-transfer.py
+++ b/output/rhv-upload-transfer.py
@@ -285,10 +285,10 @@ with closing(connection):
transfer = create_transfer(connection, disk, host)
destination_url = get_transfer_url(transfer)
- # Send the destination URL, transfer ID, and host flag back to OCaml code.
- results = {
- "transfer_id": transfer.id,
- "destination_url": destination_url,
- "is_ovirt_host": host is not None,
- }
- json.dump(results, sys.stdout)
+# Send the destination URL, transfer ID, and host flag back to OCaml code.
+results = {
+ "transfer_id": transfer.id,
+ "destination_url": destination_url,
+ "is_ovirt_host": host is not None,
+}
+json.dump(results, sys.stdout)