[lxc-devel] [lxd/master] Always use fingerprint for image export filename

sean-jc on Github lxc-bot at linuxcontainers.org
Thu Aug 11 17:30:41 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 1147 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160811/0562be5a/attachment.bin>
-------------- next part --------------
From e586e05d1757575cf92487fcdf76ab9880ed753e Mon Sep 17 00:00:00 2001
From: Sean Christopherson <sean.j.christopherson at intel.com>
Date: Thu, 11 Aug 2016 08:16:47 -0700
Subject: [PATCH] Always use fingerprint for image export filename

The metadata tarball may use a different compression algorithim
than the rootfs tarball, e.g. rootfs may be a squashfs file system.
Using the file name from the metadata tarball as the base file name
for image exports can result in an incorrect file extension for the
rootfs, e.g. .tar.xz instead of .squashfs.

Signed-off-by: Sean Christopherson <sean.j.christopherson at intel.com>
---
 lxd/images.go        | 12 +++++-------
 test/suites/basic.sh | 19 +++++++------------
 2 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/lxd/images.go b/lxd/images.go
index d05cdc7..d271b49 100644
--- a/lxd/images.go
+++ b/lxd/images.go
@@ -1363,16 +1363,14 @@ func imageExport(d *Daemon, r *http.Request) Response {
 		return SmartError(err)
 	}
 
-	filename := imgInfo.Filename
 	imagePath := shared.VarPath("images", imgInfo.Fingerprint)
 	rootfsPath := imagePath + ".rootfs"
-	if filename == "" {
-		_, ext, err := detectCompression(imagePath)
-		if err != nil {
-			ext = ""
-		}
-		filename = fmt.Sprintf("%s%s", fingerprint, ext)
+
+	_, ext, err := detectCompression(imagePath)
+	if err != nil {
+		ext = ""
 	}
+	filename := fmt.Sprintf("%s%s", fingerprint, ext)
 
 	if shared.PathExists(rootfsPath) {
 		files := make([]fileResponseEntry, 2)
diff --git a/test/suites/basic.sh b/test/suites/basic.sh
index dcbfe21..9589fc3 100644
--- a/test/suites/basic.sh
+++ b/test/suites/basic.sh
@@ -7,12 +7,7 @@ test_basic_usage() {
   # Test image export
   sum=$(lxc image info testimage | grep ^Fingerprint | cut -d' ' -f2)
   lxc image export testimage "${LXD_DIR}/"
-  if [ -e "${LXD_TEST_IMAGE:-}" ]; then
-    name=$(basename "${LXD_TEST_IMAGE}")
-  else
-    name=${sum}.tar.xz
-  fi
-  [ "${sum}" = "$(sha256sum "${LXD_DIR}/${name}" | cut -d' ' -f1)" ]
+  [ "${sum}" = "$(sha256sum "${LXD_DIR}/${sum}.tar.xz" | cut -d' ' -f1)" ]
   
   # Test an alias with slashes
   lxc image show "${sum}"
@@ -44,14 +39,14 @@ test_basic_usage() {
   my_curl -f -X GET "https://${LXD_ADDR}/1.0/containers"
 
   # Re-import the image
-  mv "${LXD_DIR}/${name}" "${LXD_DIR}/testimage.tar.xz"
+  mv "${LXD_DIR}/${sum}.tar.xz" "${LXD_DIR}/testimage.tar.xz"
   lxc image import "${LXD_DIR}/testimage.tar.xz" --alias testimage
   rm "${LXD_DIR}/testimage.tar.xz"
 
   # Test filename for image export
   lxc image export testimage "${LXD_DIR}/"
-  [ "${sum}" = "$(sha256sum "${LXD_DIR}/testimage.tar.xz" | cut -d' ' -f1)" ]
-  rm "${LXD_DIR}/testimage.tar.xz"
+  [ "${sum}" = "$(sha256sum "${LXD_DIR}/${sum}.tar.xz" | cut -d' ' -f1)" ]
+  rm "${LXD_DIR}/${sum}.tar.xz"
 
   # Test custom filename for image export
   lxc image export testimage "${LXD_DIR}/foo"
@@ -78,11 +73,11 @@ test_basic_usage() {
   deps/import-busybox --split --filename --alias splitimage
 
   lxc image export splitimage "${LXD_DIR}"
-  [ "${sum}" = "$(cat "${LXD_DIR}/meta-busybox.tar.xz" "${LXD_DIR}/busybox.tar.xz" | sha256sum | cut -d' ' -f1)" ]
+  [ "${sum}" = "$(cat "${LXD_DIR}/meta-${sum}.tar.xz" "${LXD_DIR}/${sum}.tar.xz" | sha256sum | cut -d' ' -f1)" ]
   
   # Delete the split image and exported files
-  rm "${LXD_DIR}/busybox.tar.xz"
-  rm "${LXD_DIR}/meta-busybox.tar.xz"
+  rm "${LXD_DIR}/${sum}.tar.xz"
+  rm "${LXD_DIR}/meta-${sum}.tar.xz"
   lxc image delete splitimage
 
 


More information about the lxc-devel mailing list