summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2012-06-14 14:25:49 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2012-06-14 14:25:49 +0000
commitdfd9cae3248b36d489f638c5b1c3c3aa6c54c050 (patch)
treec3026c8980ad8d11b4f576fe0bff89b7c72f9f49
parentf7790e2ec52b3cc3f8b58f3e447da37361ff9580 (diff)
downloadmorph-dfd9cae3248b36d489f638c5b1c3c3aa6c54c050.tar.gz
tests: fix some that expected tarball strata
This required functionality to create a tarball from a json file. This should probably be rewritten as a morph plugin and refactor it to consolidate the creation logic, so e.g. the stratum metadata is kept.
-rwxr-xr-xscripts/assemble-stratum53
-rwxr-xr-xtests/build-stratum-with-submodules.script6
-rwxr-xr-xtests/build-stratum.script6
-rwxr-xr-xtests/name-clash.script5
-rwxr-xr-xtests/stratum-overlap-keeps-directory-links.script4
-rwxr-xr-xtests/stratum-overlap-stomps-file-links.script4
6 files changed, 71 insertions, 7 deletions
diff --git a/scripts/assemble-stratum b/scripts/assemble-stratum
new file mode 100755
index 00000000..fa4a0390
--- /dev/null
+++ b/scripts/assemble-stratum
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2011-2012 Codethink Limited
+#
+# 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; version 2 of the License.
+#
+# 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.
+
+# This is a program to convert the json dump of the overlaps between artifacts
+# in a format more suited to shell programs, or human reading
+
+import json
+import tarfile
+import os
+
+import cliapp
+
+class AssembleStratum(cliapp.Application):
+
+ def add_settings(self):
+ self.settings.string(['cachedir'],
+ 'Where the cache basedir is')
+ self.settings.string(['tarformat'],
+ 'What format to write tar to',
+ default='')
+
+ def process_args(self, args):
+ chunklist = json.load(open(args[0]))
+ tarformat = 'w'
+ if self.settings['tarformat'] != "":
+ tarformat += self.settings['tarformat']
+ outfile = tarfile.open(args[1], tarformat)
+ for chunk in chunklist:
+ path = os.path.join(self.settings['cachedir'], 'artifacts', chunk)
+ chunktar = tarfile.open(path, mode='r:*')
+ for tarinfo in chunktar:
+ if tarinfo.isfile():
+ outfile.addfile(tarinfo, chunktar.extractfile(tarinfo))
+ else:
+ outfile.addfile(tarinfo)
+ chunktar.close()
+ outfile.close()
+
+AssembleStratum().run()
diff --git a/tests/build-stratum-with-submodules.script b/tests/build-stratum-with-submodules.script
index 9f226068..6dd424b2 100755
--- a/tests/build-stratum-with-submodules.script
+++ b/tests/build-stratum-with-submodules.script
@@ -65,6 +65,8 @@ EOF
# No build and verify we got a stratum.
"$SRCDIR/scripts/test-morph" build test:morphs-repo master submod-stratum.morph
-tar -tf "$DATADIR/cache/artifacts/"*.stratum.* | LC_ALL=C sort \
- | sed '/^\.\/./s:^\./::'
+"$SRCDIR/scripts/assemble-stratum" --cachedir "$DATADIR/cache" \
+ "$DATADIR/cache/artifacts/"*.stratum.* \
+ "$DATADIR/stratum.tar"
+tar -tf "$DATADIR/stratum.tar" | LC_ALL=C sort | sed '/^\.\/./s:^\./::'
diff --git a/tests/build-stratum.script b/tests/build-stratum.script
index 994c4077..d1f790ca 100755
--- a/tests/build-stratum.script
+++ b/tests/build-stratum.script
@@ -20,6 +20,8 @@
set -eu
"$SRCDIR/scripts/test-morph" build test:morphs-repo master hello-stratum.morph
-tar -tf "$DATADIR/cache/artifacts/"*.stratum.* | LC_ALL=C sort \
- | sed '/^\.\/./s:^\./::'
+"$SRCDIR/scripts/assemble-stratum" --cachedir "$DATADIR/cache" \
+ "$DATADIR/cache/artifacts/"*.stratum.* \
+ "$DATADIR/stratum.tar"
+tar -tf "$DATADIR/stratum.tar" | LC_ALL=C sort | sed '/^\.\/./s:^\./::'
diff --git a/tests/name-clash.script b/tests/name-clash.script
index 669949ed..f1c866f9 100755
--- a/tests/name-clash.script
+++ b/tests/name-clash.script
@@ -56,5 +56,8 @@ EOF
# unpack it and check the contents
INSTDIR="$DATADIR"/unpack
mkdir -p "$INSTDIR"
-tar -C "$INSTDIR" -xhf "$DATADIR/cache/artifacts/"*hello-stratum*
+"$SRCDIR/scripts/assemble-stratum" --cachedir "$DATADIR/cache" \
+ "$DATADIR/cache/artifacts/"*hello-stratum* \
+ "$DATADIR/stratum.tar"
+tar -C "$INSTDIR" -xhf "$DATADIR/stratum.tar"
test "$("$INSTDIR"/bin/hello)" = "hello, world"
diff --git a/tests/stratum-overlap-keeps-directory-links.script b/tests/stratum-overlap-keeps-directory-links.script
index a995194f..b0a8522b 100755
--- a/tests/stratum-overlap-keeps-directory-links.script
+++ b/tests/stratum-overlap-keeps-directory-links.script
@@ -27,6 +27,8 @@ mkdir -p "$extracted"
"$SRCDIR/scripts/test-morph" \
build test:morphs-repo overlap overlap-stratum.morph
for f in "$cache"/*.stratum.overlap-stratum; do
- tar -xf "$f" -C "$extracted"
+ "$SRCDIR/scripts/assemble-stratum" --cachedir "$DATADIR/cache" \
+ "$f" "$DATADIR/stratum.tar"
+ tar -xf "$DATADIR/stratum.tar" -C "$extracted"
done
test -h "$extracted/usr"
diff --git a/tests/stratum-overlap-stomps-file-links.script b/tests/stratum-overlap-stomps-file-links.script
index 0d429bbf..22271c2e 100755
--- a/tests/stratum-overlap-stomps-file-links.script
+++ b/tests/stratum-overlap-stomps-file-links.script
@@ -27,6 +27,8 @@ mkdir -p "$extracted"
"$SRCDIR/scripts/test-morph" \
build test:morphs-repo overlap overlap-stratum.morph
for f in "$cache"/*.stratum.overlap-stratum; do
- tar -xf "$f" -C "$extracted"
+ "$SRCDIR/scripts/assemble-stratum" --cachedir "$DATADIR/cache" \
+ "$f" "$DATADIR/stratum.tar"
+ tar -xf "$DATADIR/stratum.tar" -C "$extracted"
done
test -f "$extracted/bin/foo"