WIP - Do not Merge - Create test for rpm builds

Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
This commit is contained in:
TomSweeneyRedHat 2017-09-18 12:43:40 -04:00
parent 5e3c53c172
commit ce81f00a8b

58
test/rpm.bats Normal file
View file

@ -0,0 +1,58 @@
#!/usr/bin/env bats
load helpers
@test "rpm-build" {
if ! which runc ; then
skip
fi
# Build a container to use for building the binaries.
image=fedora:26
cid=$(buildah --debug=false from --pull --signature-policy ${TESTSDIR}/policy.json $image)
root=$(buildah --debug=false mount $cid)
commit=$(git log --format=%H -n 1)
shortcommit=$(echo ${commit} | cut -c-7)
mkdir -p ${root}/rpmbuild/{SOURCES,SPECS}
# Build the tarball.
(cd ..; git archive --format tar.gz --prefix=crio-${commit}/ ${commit}) > ${root}/rpmbuild/SOURCES/crio-${shortcommit}.tar.gz
# Update the .spec file with the commit ID.
sed s:REPLACEWITHCOMMITID:${commit}:g ${TESTSDIR}/../contrib/rpm/crio.spec > ${root}/rpmbuild/SPECS/crio.spec
# Install build dependencies and build binary packages.
buildah --debug=false run $cid -- dnf -y install 'dnf-command(builddep)' rpm-build
buildah --debug=false run $cid -- dnf -y builddep --spec rpmbuild/SPECS/crio.spec
buildah --debug=false run $cid -- rpmbuild --define "_topdir /rpmbuild" -ba /rpmbuild/SPECS/crio.spec
# Build a second new container.
cid2=$(buildah --debug=false from --pull --signature-policy ${TESTSDIR}/policy.json fedora:26)
root2=$(buildah --debug=false mount $cid2)
# Copy the binary packages from the first container to the second one, and build a list of
# their filenames relative to the root of the second container.
rpms=
mkdir -p ${root2}/packages
for rpm in ${root}/rpmbuild/RPMS/*/*.rpm ; do
cp $rpm ${root2}/packages/
rpms="$rpms "/packages/$(basename $rpm)
done
# Install the binary packages into the second container.
buildah --debug=false run $cid2 -- dnf -y install $rpms
# Run the binary package and compare its self-identified version to the one we tried to build.
id=$(buildah --debug=false run $cid2 -- kpod version | awk '/^Git Commit:/ { print $NF }')
bv=$(buildah --debug=false run $cid2 -- kpod version | awk '/^Version:/ { print $NF }')
rv=$(buildah --debug=false run $cid2 -- rpm -q --queryformat '%{version}' kpod)
echo "short commit: $shortcommit"
echo "id: $id"
echo "kpod version: $bv"
echo "kpod rpm version: $rv"
test $shortcommit = $id
test $bv = $rv
# Clean up.
buildah --debug=false rm $cid $cid2
}