mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone
Blob Blame History Raw
From 244157fcea33dad2c99ca4b740b5483ed36e4238 Mon Sep 17 00:00:00 2001
From: Pino Toscano <ptoscano@redhat.com>
Date: Wed, 29 Nov 2017 15:29:57 +0100
Subject: [PATCH] builder: use the template arch when caching all templates

When caching all the templates, use the architecture of each template,
instead of the architecture passed as --arch (or the host architecture,
as default).  This way, the right destination filename will be used.

Fixes commit b1cf6246f3c80762cf27dbdb24168589a34daf00.

Thanks to: Erik Skultety.

(cherry picked from commit b34f457cf2dd66626abf743c90881bfe6532ec9b)
---
 builder/Makefile.am                   |  2 +
 builder/builder.ml                    |  4 +-
 builder/test-virt-builder-cacheall.sh | 88 +++++++++++++++++++++++++++++++++++
 3 files changed, 92 insertions(+), 2 deletions(-)
 create mode 100755 builder/test-virt-builder-cacheall.sh

diff --git a/builder/Makefile.am b/builder/Makefile.am
index 2bbf1247a..c260a327f 100644
--- a/builder/Makefile.am
+++ b/builder/Makefile.am
@@ -28,6 +28,7 @@ EXTRA_DIST = \
 	test-simplestreams/streams/v1/index.json \
 	test-simplestreams/streams/v1/net.cirros-cloud_released_download.json \
 	test-virt-builder.sh \
+	test-virt-builder-cacheall.sh \
 	test-virt-builder-docs.sh \
 	test-virt-builder-list.sh \
 	test-virt-builder-list-simplestreams.sh \
@@ -236,6 +237,7 @@ yajl_tests_LINK = \
 	  $(yajl_tests_THEOBJECTS) -o $@
 
 TESTS = \
+	test-virt-builder-cacheall.sh \
 	test-virt-builder-docs.sh \
 	test-virt-builder-list.sh \
 	test-virt-index-validate.sh \
diff --git a/builder/builder.ml b/builder/builder.ml
index 213fd56a1..ce99e0339 100644
--- a/builder/builder.ml
+++ b/builder/builder.ml
@@ -251,8 +251,8 @@ let main () =
         List.iter (
           fun (name,
                { Index.revision = revision; file_uri = file_uri;
-                 proxy = proxy }) ->
-            let template = name, cmdline.arch, revision in
+                 proxy = proxy; arch = arch }) ->
+            let template = name, arch, revision in
             message (f_"Downloading: %s") file_uri;
             let progress_bar = not (quiet ()) in
             ignore (Downloader.download downloader ~template ~progress_bar
diff --git a/builder/test-virt-builder-cacheall.sh b/builder/test-virt-builder-cacheall.sh
new file mode 100755
index 000000000..c80d9ecd2
--- /dev/null
+++ b/builder/test-virt-builder-cacheall.sh
@@ -0,0 +1,88 @@
+#!/bin/bash -
+# libguestfs virt-builder test script
+# Copyright (C) 2017 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+set -e
+
+$TEST_FUNCTIONS
+skip_if_skipped
+
+tmpdir="$(mktemp -d)"
+echo "tmpdir= $tmpdir"
+reposdir="$tmpdir/virt-builder/repos.d"
+repodir="$tmpdir/repo"
+indexfile="$repodir/index"
+cachedir="$tmpdir/cache"
+
+mkdir -p "$reposdir"
+mkdir -p "$repodir"
+
+# Create some fake images.
+img1_path="$repodir/img1.raw"
+img1_size=10485760  # 10G
+qemu-img create -f raw "$img1_path" $img1_size
+img1_csum=`do_sha256 "$img1_path"`
+
+img2_path="$repodir/img2.qcow2"
+img2_size=5242880  # 5G
+qemu-img create -f qcow2 "$img2_path" $img2_size
+img2_csum=`do_sha256 "$img2_path"`
+
+# Create an index for the images.
+cat > "$indexfile" <<EOF
+[img1]
+name=img1
+file=$(basename "$img1_path")
+arch=x86_64
+size=$img1_size
+checksum[sha512]=$img1_csum
+revision=1
+
+[img2]
+name=img2
+file=$(basename "$img2_path")
+arch=aarch64
+size=$img2_size
+checksum[sha512]=$img2_csum
+revision=3
+EOF
+
+# Create the repository.
+cat > "$reposdir/repo1.conf" <<EOF
+[repo1]
+uri=$indexfile
+EOF
+
+export XDG_CONFIG_HOME=
+export XDG_CONFIG_DIRS="$tmpdir"
+export XDG_CACHE_HOME="$cachedir"
+
+short_list=$($VG virt-builder --no-check-signature --no-cache --list)
+
+if [ "$short_list" != "img1                     x86_64     img1
+img2                     aarch64    img2" ]; then
+    echo "$0: unexpected --list output:"
+    echo "$short_list"
+    exit 1
+fi
+
+$VG virt-builder --no-check-signature --cache-all-templates
+ls -lh "$cachedir/virt-builder"
+test -f "$cachedir/virt-builder/img1.x86_64.1"
+test -f "$cachedir/virt-builder/img2.aarch64.3"
+
+rm -rf "$tmpdir"
-- 
2.14.3