[virt-tools-list] [virt-bootstrap] [PATCH 3/4] docker-source: Support blobs without .tar ext

Radostin Stoyanov rstoyanov1 at gmail.com
Sat Apr 28 22:21:03 UTC 2018


Since skopeo v0.1.29 [1] blobs are saved without the .tar extension.
This commit changes the docker-source module to handle both cases (with
or without .tar extension)

	[1] commit: projectatomic/skopeo at 43acc74
	Fix skopeo tests with changes to dir transport

	The dir transport has been changed to save the blobs without the .tar extension
	Fixes the skopeo tests failing due to this change

Signed-off-by: Radostin Stoyanov <rstoyanov1 at gmail.com>
---
 src/virtBootstrap/sources/docker_source.py | 21 +++++++++++++++++++--
 tests/docker_source.py                     |  6 +++---
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/virtBootstrap/sources/docker_source.py b/src/virtBootstrap/sources/docker_source.py
index 715e560..5b6378f 100644
--- a/src/virtBootstrap/sources/docker_source.py
+++ b/src/virtBootstrap/sources/docker_source.py
@@ -107,7 +107,7 @@ class DockerSource(object):
             self.checksums.append([sum_type, layer_sum])  # Store checksums
 
             # Layers are tar files with hashsum used as name
-            file_path = os.path.join(self.images_dir, layer_sum + '.tar')
+            file_path = os.path.join(self.images_dir, layer_sum)
             # Store 'file path' and set placeholder for 'size'
             self.layers.append([file_path, None])
 
@@ -158,6 +158,17 @@ class DockerSource(object):
             utils.copytree(dest_dir, self.images_dir)
             shutil.rmtree(dest_dir)
 
+        # Old versions of skopeo use '.tar' extension to blobs.
+        # Make sure we use the correct file name.
+        for i in range(len(self.layers)):
+            path = self.layers[i][0]
+            if not os.path.exists(path):
+                if os.path.exists(path + '.tar'):
+                    self.layers[i][0] += '.tar'
+                else:
+                    raise ValueError('Blob %s does not exist.' % path)
+
+
     def parse_output(self, proc):
         """
         Read stdout from skopeo's process asynchconosly.
@@ -258,8 +269,14 @@ class DockerSource(object):
             sum_type, sum_expected = checksum
 
             logger.debug("Checking layer: %s", path)
-            if not (os.path.exists(path)
+            if (os.path.exists(path)
                     and utils.checksum(path, sum_type, sum_expected)):
+                continue
+            if (not path.endswith('.tar')
+                    and os.path.exists(path + '.tar')
+                    and utils.checksum(path + '.tar', sum_type, sum_expected)):
+                self.layers[index][0] += '.tar'
+            else:
                 return False
         return True
 
diff --git a/tests/docker_source.py b/tests/docker_source.py
index 0521322..585b9d2 100644
--- a/tests/docker_source.py
+++ b/tests/docker_source.py
@@ -368,9 +368,9 @@ class TestDockerSource(unittest.TestCase):
         }
 
         expected_result = [
-            ['/images_path/a7050fc1.tar', None],
-            ['/images_path/c6ff40b6.tar', None],
-            ['/images_path/75c416ea.tar', None]
+            ['/images_path/a7050fc1', None],
+            ['/images_path/c6ff40b6', None],
+            ['/images_path/75c416ea', None]
         ]
 
         with mock.patch('os.path.getsize') as m_getsize:
-- 
2.14.3




More information about the virt-tools-list mailing list