Blame SOURCES/0078-builder-use-the-template-arch-when-caching-all-templ.patch

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