2016-12-03 02:07:08 +03:00
dn = $( cd $( dirname $0 ) && pwd )
test_tmpdir = $( mktemp -d /var/tmp/rpm-ostree-compose-test.XXXXXX)
touch ${ test_tmpdir } /.test
trap _cleanup_tmpdir EXIT
cd ${ test_tmpdir }
2018-01-09 23:38:09 +03:00
. ${ dn } /../common/libtest.sh
2016-12-03 02:07:08 +03:00
2018-05-31 23:31:22 +03:00
export repo = $( pwd ) /repo
export repobuild = $( pwd ) /repo-build
2016-12-03 02:07:08 +03:00
pyeditjson( ) {
cat >editjson.py <<EOF
import sys,json
jd = json.load( sys.stdin)
${ 1 }
json.dump( jd,sys.stdout)
EOF
2019-05-08 17:15:48 +03:00
python3 ./editjson.py && rm -f ./editjson.py
2016-12-03 02:07:08 +03:00
}
pysetjsonmember( ) {
pyeditjson "jd['" $1 " '] = $2 " < ${ treefile } > ${ treefile } .new && mv ${ treefile } { .new,}
}
2016-12-09 01:31:20 +03:00
pyappendjsonmember( ) {
pyeditjson "jd['" $1 " '] += $2 " < ${ treefile } > ${ treefile } .new && mv ${ treefile } { .new,}
}
2016-12-03 02:07:08 +03:00
prepare_compose_test( ) {
name = $1
shift
2018-09-13 19:59:28 +03:00
filetype = ${ 1 :- json }
2017-11-30 22:32:49 +03:00
ostree --repo= ${ repo } init --mode= archive
2017-12-01 19:06:11 +03:00
echo 'fsync=false' >> ${ repo } /config
2017-11-30 22:32:49 +03:00
ostree --repo= ${ repobuild } init --mode= bare-user
2017-12-01 19:06:11 +03:00
echo 'fsync=false' >> ${ repobuild } /config
2017-11-30 22:32:49 +03:00
mkdir -p ${ test_compose_datadir } /cache
2016-12-03 02:07:08 +03:00
cp -r ${ dn } /../composedata .
2017-11-30 22:32:49 +03:00
# We use the local RPM package cache
rm -f composedata/*.repo
cat > composedata/fedora-local.repo <<EOF
[ fedora-local]
2019-03-23 21:41:27 +03:00
baseurl = ${ test_compose_datadir } /fedora-local
2017-11-30 22:32:49 +03:00
enabled = 1
gpgcheck = 0
EOF
2016-12-03 02:07:08 +03:00
export treefile = composedata/fedora-${ name } .json
2018-10-09 18:23:52 +03:00
export treeref = fedora/stable/x86_64/${ name }
pyeditjson 'jd["ref"] = "' ${ treeref } '"' < composedata/fedora-base.json > ${ treefile }
2017-11-30 22:32:49 +03:00
pysetjsonmember "repos" '["fedora-local"]' ${ treefile }
2016-12-03 02:07:08 +03:00
# FIXME extract from json
2018-09-13 19:59:28 +03:00
if [ " ${ filetype } " = "yaml" ] ; then
2019-05-08 17:15:48 +03:00
python3 <<EOF
2018-09-13 19:59:28 +03:00
import json, yaml, sys
ifn = " ${ treefile } "
ofn = ifn.replace( '.json' , '.yaml' )
jd = json.load( open( ifn) )
with open( ofn, "w" ) as f:
2018-09-29 17:32:28 +03:00
yaml.safe_dump( jd, f)
2018-09-13 19:59:28 +03:00
EOF
export treefile = composedata/fedora-${ name } .yaml
fi
2016-12-03 02:07:08 +03:00
}
2018-10-09 18:23:52 +03:00
composejson = $( pwd ) /compose.json
2018-10-21 18:59:35 +03:00
compose_workdir = ${ test_tmpdir } /workdir
compose_base_argv = " --workdir ${ compose_workdir } --repo ${ repobuild } --write-composejson-to ${ composejson } "
2016-12-03 02:07:08 +03:00
runcompose( ) {
2018-07-31 16:55:31 +03:00
echo " $( date) : starting compose "
2018-10-21 18:59:35 +03:00
# The workdir will be cleaned up (or not) with the overall test dir
rm ${ compose_workdir } -rf
mkdir ${ test_tmpdir } /workdir
env RPMOSTREE_PRESERVE_TMPDIR = 1 rpm-ostree compose tree ${ compose_base_argv } ${ treefile } " $@ "
2018-10-09 18:23:52 +03:00
commit = $( jq -r '.["ostree-commit"]' < " ${ composejson } " )
ostree --repo= ${ repo } pull-local ${ repobuild } " ${ treeref :- ${ commit } } "
2018-07-31 16:55:31 +03:00
echo " $( date) : finished compose "
2016-12-03 02:07:08 +03:00
}
prepare_run_compose( ) {
prepare_compose_test $1
runcompose
}