On Wed, Apr 13, 2022 at 09:32:14PM +0300, Nir Soffer wrote:
> +# Wait for the import job to finish
> +endt = time.time() + timeout
Since we use python 3, it is better to use time.monotonic()
which is affected by system time changes.
Interesting - we use time.time() quite a lot at the moment.
How about the following patch? It passes tests for me locally (so
only against the test harness, not real RHV).
Rich.
diff --git a/output/rhv-upload-finalize.py b/output/rhv-upload-finalize.py
index 4d1dcfb2f4..1221e766ac 100644
--- a/output/rhv-upload-finalize.py
+++ b/output/rhv-upload-finalize.py
@@ -73,7 +73,7 @@ def finalize_transfer(connection, transfer_id, disk_id):
.image_transfers_service()
.image_transfer_service(transfer_id))
- start = time.time()
+ start = time.monotonic()
transfer_service.finalize()
@@ -125,14 +125,14 @@ def finalize_transfer(connection, transfer_id, disk_id):
raise RuntimeError(
"transfer %s was paused by system" % (transfer.id,))
- if time.time() > start + timeout:
+ if time.monotonic() > start + timeout:
raise RuntimeError(
"timed out waiting for transfer %s to finalize, "
"transfer is %s"
% (transfer.id, transfer.phase))
debug("transfer %s finalized in %.3f seconds"
- % (transfer_id, time.time() - start))
+ % (transfer_id, time.monotonic() - start))
# Parameters are passed in via a JSON doc from the OCaml code.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
libguestfs lets you edit virtual machines. Supports shell scripting,
bindings from many languages.
http://libguestfs.org