[virt-tools-list] [virt-bootstrap] [PATCH v5 03/11] DockerSource: Fix formula of download progress

Radostin Stoyanov rstoyanov1 at gmail.com
Mon Jul 24 08:14:03 UTC 2017


When downloading image with multiple layers, the download progress
value of every following layer should not start from 0.

If we have 10 layers, downloading each of them should increase the
total download progress by 10%.

Assuming that the download and extraction are 50/50 of the total work.

Then, downloading each of 10 layers will increase the progress value
with 5% of the total work.

When all layers are downloaded the progress value should be 50%.

However, with the current formula the progress value of each layer
starts from 0%.
(E.g. when downloading 2nd layer of 10 the download progress starts
from 0% instead of 5%.)

This bug can be seen when downloading images with multiple layers of
large size.

Example:
    virt-bootstrap docker://rails /tmp/foo --status-only
---
 src/virtBootstrap/sources.py | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/virtBootstrap/sources.py b/src/virtBootstrap/sources.py
index 8800d72..898993d 100644
--- a/src/virtBootstrap/sources.py
+++ b/src/virtBootstrap/sources.py
@@ -225,7 +225,15 @@ class DockerSource(object):
         total size of image layer.
 
         Calculate percentage and update the progress of virt-bootstrap.
+
+        @param current_l: Number of currently downloaded layer
+        @param total_l: Total number of layers
+        @param line_split: A list with format:
+                [<d_size>, <d_format>, '/', <t_size>, <t_format>, <progress>]
+            Example:
+                ['5.92', 'MB', '/', '44.96', 'MB', '[===>-----------------]']
         """
+
         if not (len(line_split) > 4 and isinstance(line_split, list)):
             return
 
@@ -237,9 +245,13 @@ class DockerSource(object):
             total_size = utils.size_to_bytes(t_size, t_format)
             if downloaded_size and total_size:
                 try:
-                    self.progress(value=(50
-                                         * downloaded_size / total_size
-                                         * float(current_l)/total_l))
+                    frac = float(1) / total_l
+                    downloaded = float(downloaded_size) / total_size
+                    layer_frac = float(max(0, current_l - 1)) / total_l
+
+                    progress = 50 * (layer_frac + (frac * downloaded))
+
+                    self.progress(value=progress)
                 except Exception:
                     pass  # Ignore failures
 
-- 
2.9.4




More information about the virt-tools-list mailing list