add test harness based on docker/lxc

This commit is contained in:
Paul Morgan 2014-03-12 20:02:17 +00:00
parent bc0abf1beb
commit 361eca6195
5 changed files with 262 additions and 3 deletions

65
HACKING
View file

@ -24,6 +24,66 @@ compatible with both python 2.4 and 3.x. For example:
Tests
-----
### Docker test harness
To run all tests on all supported platforms:
yum -y install docker-io
systemctl start docker.service
systemctl enable docker.service
usermod -aG docker <your-username>
Log out and log in to refresh your secondary group.
Then run from the root of the project:
hacking/runtests.sh
If any test fails, the script exits non-zero.
To get a zero exit status, all tests must pass
or be skipped.
The above script runs a test harness based on
docker containers and takes several minutes to run
on the first build (or if you remove the images).
Expected output resembles:
-snip copious output-
=====================
Summary
/tmp/titotest-centos-5.9-python.out : OK (SKIP=1)
/tmp/titotest-centos-6.4-python.out : OK (SKIP=1)
/tmp/titotest-fedora-20-python.out : OK
/tmp/titotest-fedora-20-python3.out : OK
You can then review the output, such as:
$ grep SKIP: /tmp/titotest-*.out
/tmp/titotest-centos-5.9-python.out:... SKIP: git-annex is not available in epel-5
/tmp/titotest-centos-6.4-python.out:... SKIP: git-annex '3.20120522 ' is too old
After you run the test harness the first time,
you can optionally create and enter a container like so:
.--- remove container when done (not image)
|
| .--- interactive
| | .--- tty
| | | .---- mount current workdir into container
| | | | .---- name of image
| | | | | .-- get a shell
| | | | | |
docker run --rm -i -t -v $PWD:/home/sandbox titotest-centos-5.9 /bin/bash
Note about the sandbox: By default, the docker container is a
read-only execution environment to protect your source from changes.
If you are comfortable with LXC, you can override it to provide
an authoring environment, too.
### Workstation tests
To run all tests, install these packages:
* python-nose, python-pep8, and rpm-python
@ -34,11 +94,10 @@ To run all tests, install these packages:
Then from the root of the project:
python ./runtests.py -vv
python3 ./runtests.py -vv test/unit
python3 ./runtests.py -vv
(Run only the unit tests on python3 since GitPython does not
support python3 yet.)
### Advanced
When developing code for tito there are a couple ways you can test:

125
hacking/runtests.sh Executable file
View file

@ -0,0 +1,125 @@
#!/bin/bash
# TODO:
#
# * Add option parsing to change behavior, such as reduce verbosity
# * Add makefile with tasks, such as 'build', 'clean', etc.?
#
#
# Usage:
#
# To run all tests on all supported platforms:
#
# yum -y install docker-io
# systemctl start docker.service
# systemctl enable docker.service
# usermod -aG docker <your-username>
#
# Log out and log in to refresh your secondary group.
# Then run from the root of the project:
#
# hacking/runtests.sh
#
# If any test fails, the script exits non-zero.
# To get a zero exit status, all tests must pass
# or be skipped.
#
# The script runs a test harness based on
# docker containers and takes several minutes
# to run on the first build.
# (or if you remove the images)
#
#
# Expected output resembles:
#
# -snip copious output-
# =====================
# Summary
# /tmp/titotest-centos-5.9-python.out : OK (SKIP=1)
# /tmp/titotest-centos-6.4-python.out : OK (SKIP=1)
# /tmp/titotest-fedora-20-python.out : OK
# /tmp/titotest-fedora-20-python3.out : OK
#
# You can then review the output, such as:
#
# $ grep SKIP: /tmp/titotest-*.out
# /tmp/titotest-centos-5.9-python.out:... SKIP: git-annex is not available in epel-5
# /tmp/titotest-centos-6.4-python.out:... SKIP: git-annex '3.20120522 ' is too old
#
# After you run the test harness the first time,
# you can optionally enter a container like so:
#
# .--- remove container when done (not image)
# |
# | .--- interactive
# | | .--- tty
# | | | .---- mount current workdir into container
# | | | | .---- name of image
# | | | | | .-- get a shell
# | | | | | |
# docker run --rm -i -t -v $PWD:/home/sandbox titotest-centos-5.9 /bin/bash
distros='
titotest-centos-5.9
titotest-centos-6.4
titotest-fedora-20
'
python3_distros='
titotest-fedora-20
'
rm -f /tmp/titotest*.out &> /dev/null
summary=/tmp/titotest.out
if ! [[ -x runtests.py ]]; then
echo 'ERROR: must run from root of repo' >&2
exit 1
fi
header() {
echo
echo =====================
echo $*
}
build_image() {
name=$1
header $name
pushd hacking/$name && echo $PWD && docker build -t $name .
popd
}
run_inside_image() {
name=$1
python_cmd=$2
outfile=/tmp/${name}-${python_cmd}.out
header $name
# --rm => remove container after run
# -i => interactive
# -t => tty
# -v host:container:ro => mount host in container read-only
docker_run="docker run --rm -i -t -v $PWD:/home/sandbox:ro"
printf "%-40s: " $outfile >> $summary
$docker_run $name $python_cmd ./runtests.py -vv 2>&1 | tee $outfile
tail -1 $outfile >> $summary
}
echo "Building docker images..."
for distro in $distros; do
build_image $distro || exit 1
done
for distro in $distros; do
run_inside_image $distro python
done
for distro in $python3_distros; do
run_inside_image $distro python3
done
header 'Summary'
cat $summary
egrep '\bFAIL' $summary &> /dev/null
[[ $? -eq 0 ]] && exit 1 || exit 0

View file

@ -0,0 +1,25 @@
# https://index.docker.io/_/centos/
FROM tianon/centos:5.9
# http://jumanjiman.github.io/
MAINTAINER Paul Morgan <jumanjiman@gmail.com>
# Install dependencies.
RUN rpm -Uvh http://mirror.es.its.nyu.edu/epel/5/x86_64/epel-release-5-4.noarch.rpm
RUN yum -y install git rpm-build \
python-devel python-nose python-setuptools python-pep8 \
libxslt asciidoc tar createrepo which
# Remove yum metadata.
RUN yum clean all
RUN useradd sandbox
RUN git config --global user.email "sandbox@example.com"
RUN git config --global user.name "sandbox"
USER sandbox
VOLUME ["/home/sandbox"]
WORKDIR /home/sandbox
ENV LANG C
CMD ["/bin/bash"]

View file

@ -0,0 +1,25 @@
# https://index.docker.io/_/centos/
FROM tianon/centos:6.4
# http://jumanjiman.github.io/
MAINTAINER Paul Morgan <jumanjiman@gmail.com>
# Install dependencies.
RUN yum -y install git rpm-build python-devel python-nose \
libxslt asciidoc python-setuptools tar createrepo which
RUN rpm -Uvh http://ftp.linux.ncsu.edu/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
RUN yum -y install python-pep8 git-annex
# Remove yum metadata.
RUN yum clean all
RUN useradd sandbox
RUN git config --global user.email "sandbox@example.com"
RUN git config --global user.name "sandbox"
USER sandbox
VOLUME ["/home/sandbox"]
WORKDIR /home/sandbox
ENV LANG C
CMD ["/bin/bash"]

View file

@ -0,0 +1,25 @@
# https://index.docker.io/_/centos/
FROM mattdm/fedora:f20
# http://jumanjiman.github.io/
MAINTAINER Paul Morgan <jumanjiman@gmail.com>
# Install dependencies.
RUN yum -y install git rpm-build libxslt tar \
python-devel python-nose python-setuptools python-pep8 \
python3-devel python3-nose python3-setuptools python3-pep8 rpm-python3 \
createrepo git-annex which
# Remove yum metadata.
RUN yum clean all
RUN useradd sandbox
RUN git config --global user.email "sandbox@example.com"
RUN git config --global user.name "sandbox"
USER sandbox
VOLUME ["/home/sandbox"]
WORKDIR /home/sandbox
ENV LANG C
CMD ["/bin/bash"]