Blob Blame History Raw
From 3702eed072ae7b2d52398a3c9b1c1feb04ffdce3 Mon Sep 17 00:00:00 2001
From: Cole Robinson <crobinso@redhat.com>
Date: Wed, 14 Dec 2022 12:57:10 -0500
Subject: [PATCH] progress: Fix showing correct final total

Reproducer:
Reproducer:
./virt-install --connect test:///default \
               --location tests/data/fakemedia/fake-f26-netinst.iso

Before:
Starting install...
Retrieving 'vmlinuz'                            |    0 B  00:00:00 ...
Retrieving 'initrd.img'                         |    0 B  00:00:00 ...

After:
Starting install...
Retrieving 'vmlinuz'                            |    9 B  00:00:00 ...
Retrieving 'initrd.img'                         |    9 B  00:00:00 ...

progress.end() currently only reports the total amount of bytes
that were last written to the UI. It should report the total amount
that's been passed to update().

Reported-by: Toshiki Sonoda <sonoda.toshiki@fujitsu.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
(cherry picked from commit 4114fa1aa827b836d3a1d11c2ac2d367c9bb0463)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2156247

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
---
 tests/data/meter/meter1.txt | 2 +-
 tests/data/meter/meter2.txt | 2 +-
 tests/data/meter/meter3.txt | 2 +-
 tests/data/meter/meter5.txt | 2 +-
 tests/data/meter/meter6.txt | 2 +-
 tests/test_misc.py          | 4 +++-
 virtinst/_progresspriv.py   | 4 ++--
 7 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/tests/data/meter/meter1.txt b/tests/data/meter/meter1.txt
index a3f7c7d2f..7e154c972 100644
--- a/tests/data/meter/meter1.txt
+++ b/tests/data/meter/meter1.txt
@@ -9,4 +9,4 @@ Meter text test            20% [===              ]  413 B/s | 2.0 kB  00:19 ETA
 
 Meter text test            40% [======-          ]  731 B/s | 3.9 kB  00:08 ETA 
 
-Meter text test                                             | 3.9 kB  00:04 ... 
+Meter text test                                             | 4.4 kB  00:04 ... 
diff --git a/tests/data/meter/meter2.txt b/tests/data/meter/meter2.txt
index 93e93dc31..7ccc31636 100644
--- a/tests/data/meter/meter2.txt
+++ b/tests/data/meter/meter2.txt
@@ -9,4 +9,4 @@ Meter text test                               20% [=======
 
 Meter text test                               40% [==============                     ]  731 B/s | 3.9 kB  00:00:08 ETA 
 
-Meter text test                                                                                  | 3.9 kB  00:00:04 ... 
+Meter text test                                                                                  | 4.4 kB  00:00:04 ... 
diff --git a/tests/data/meter/meter3.txt b/tests/data/meter/meter3.txt
index 474e40f74..6f66608fe 100644
--- a/tests/data/meter/meter3.txt
+++ b/tests/data/meter/meter3.txt
@@ -4,4 +4,4 @@ Meter text test                                      67 B/s |  200 B  00:02
 Meter text test                                     413 B/s | 2.0 kB  00:03     
 Meter text test                                     731 B/s | 3.9 kB  00:04     
 
-Meter text test                                             | 3.9 kB  00:04     
+Meter text test                                             | 4.4 kB  00:04     
diff --git a/tests/data/meter/meter5.txt b/tests/data/meter/meter5.txt
index 1d232a5de..7142a9718 100644
--- a/tests/data/meter/meter5.txt
+++ b/tests/data/meter/meter5.txt
@@ -9,4 +9,4 @@ Meter text test           1000% [================]  413 B/s | 2.0 kB  --:-- ETA
 
 Meter text test           2000% [================]  731 B/s | 3.9 kB  --:-- ETA 
 
-Meter text test                                             | 3.9 kB  00:04 !!! 
+Meter text test                                             | 4.4 kB  00:04 !!! 
diff --git a/tests/data/meter/meter6.txt b/tests/data/meter/meter6.txt
index 07d99bfd8..dd5d3d47b 100644
--- a/tests/data/meter/meter6.txt
+++ b/tests/data/meter/meter6.txt
@@ -9,4 +9,4 @@ Meter text test            100% [================]  413 B/s | 2.0 kB  --:-- ETA
 
 Meter text test            100% [================]  731 B/s | 3.9 kB  --:-- ETA 
 
-Meter text test                                             | 3.9 kB  00:04     
+Meter text test                                             | 4.4 kB  00:04     
diff --git a/tests/test_misc.py b/tests/test_misc.py
index aa610f4df..20f5a626b 100644
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -178,7 +178,9 @@ def test_misc_meter():
             m.update(2000)
         with unittest.mock.patch("time.time", return_value=5.0):
             m.update(4000)
-        with unittest.mock.patch("time.time", return_value=6.0):
+        with unittest.mock.patch("time.time", return_value=5.1):
+            m.update(4500)
+        with unittest.mock.patch("time.time", return_value=5.5):
             m.end()
 
     # Basic output testing
diff --git a/virtinst/_progresspriv.py b/virtinst/_progresspriv.py
index 5a31a18cc..a035c9c43 100644
--- a/virtinst/_progresspriv.py
+++ b/virtinst/_progresspriv.py
@@ -112,10 +112,10 @@ class BaseMeter:
         assert type(amount_read) is int
 
         now = time.time()
+        self.last_amount_read = amount_read
+        self.re.update(amount_read, now)
         if (not self.last_update_time or
                 (now >= self.last_update_time + self.update_period)):
-            self.re.update(amount_read, now)
-            self.last_amount_read = amount_read
             self.last_update_time = now
             self._do_update(amount_read)
 
-- 
2.39.0