From: Loic Dachary Date: Tue, 7 Oct 2014 16:40:54 +0000 (+0200) Subject: tests: helper to run unit / function tests in docker X-Git-Tag: v0.90~66^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ecccb397698a36c13db402f0c78b3d17516211b1;p=ceph.git tests: helper to run unit / function tests in docker For instance test/docker-test.sh --os-type ubuntu --os-version 14.04 \ test/ceph-disk.sh runs test/ceph-disk.sh in a ubuntu 14.04 docker container. Once the container is populated and ceph compiled, running a test script roughly requires entering the container and running make TESTS=tests/foo.sh check * docker build ceph-ubuntu-14.04 using ubuntu.dockerfile as a Dockerfile * it will run apt-get install ceph compilation / run dependencies * git clone the-local-clone ceph-ubuntu-14.04 * docker run ceph-ubuntu-14.04 make -j4 in the ceph-ubuntu-14.04 clone * docker run test/ceph-disk.sh test/docker-test.sh is the command line interface for test/docker-test-helper.sh which can be invoked from shell scripts. test/ubuntu.dockerfile and test/ubuntu.dockerfile are regular Dockerfiles which allow substitution of environment variables. Signed-off-by: Loic Dachary --- diff --git a/src/test/centos.dockerfile b/src/test/centos.dockerfile new file mode 100644 index 000000000000..3e872ac0dd8c --- /dev/null +++ b/src/test/centos.dockerfile @@ -0,0 +1,43 @@ +# +# Copyright (C) 2014 Red Hat +# +# Author: Loic Dachary +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Library Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# 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 Library Public License for more details. +# +# Environment variables are substituted via envsubst(1) +# +# user_id=$(id -u) +# os_version= the desired REPOSITORY TAG +# +FROM centos:%%os_version%% + +RUN useradd -M --uid %%user_id%% %%USER%% +# http://jperrin.github.io/centos/2014/09/25/centos-docker-and-systemd/ +RUN yum -y swap -- remove fakesystemd -- install systemd systemd-libs +RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done) +RUN rm -f /lib/systemd/system/multi-user.target.wants/* +RUN rm -f /etc/systemd/system/*.wants/* +RUN rm -f /lib/systemd/system/local-fs.target.wants/* +RUN rm -f /lib/systemd/system/sockets.target.wants/*udev* +RUN rm -f /lib/systemd/system/sockets.target.wants/*initctl* +RUN rm -f /lib/systemd/system/basic.target.wants/* +RUN rm -f /lib/systemd/system/anaconda.target.wants/* +RUN yum install -y redhat-lsb-core +# build dependencies from spec.in +RUN yum install -y wget +RUN wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-2.noarch.rpm +RUN rpm -ivh epel-release-7-2.noarch.rpm +RUN yum install -y make gcc-c++ libtool boost-devel bzip2-devel libedit-devel perl gdbm pkgconfig python python-nose python-argparse libaio-devel libcurl-devel libxml2-devel libuuid-devel libblkid-devel libudev-devel leveldb-devel xfsprogs-devel yasm snappy-devel sharutils gperftools-devel google-perftools-devel mozilla-nss-devel keyutils-devel libatomic-ops-devel fdupes nss-devel keyutils-libs-devel libatomic_ops-devel gperftools-devel fuse-devel libexpat-devel FastCGI-devel expat-devel fcgi-devel lttng-ust-devel libbabeltrace-devel java-devel java-devel junit4 +# development tools +RUN yum install -y ccache valgrind gdb git +# make check dependencies +RUN yum install -y python-virtualenv gdisk kpartx diff --git a/src/test/docker-test-helper.sh b/src/test/docker-test-helper.sh new file mode 100755 index 000000000000..6daab47200e4 --- /dev/null +++ b/src/test/docker-test-helper.sh @@ -0,0 +1,371 @@ +#!/bin/bash +# +# Copyright (C) 2014 Red Hat +# +# Author: Loic Dachary +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Library Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# 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 Library Public License for more details. +# +function get_image_name() { + local os_type=$1 + local os_version=$2 + + echo ceph-$os_type-$os_version +} + +function get_branch() { + git rev-parse --abbrev-ref HEAD +} + +function compile_ubuntu() { + cat < $compile + if ! $cmd --workdir $downstream $user $image bash $compile ; then + status=1 + fi + rm $compile + else + if ! $cmd --workdir $downstream/src $user $dev $image "$@" ; then + status=1 + fi + fi + return $status +} + +declare -A OS_TYPE2VERSIONS=([ubuntu]="12.04 14.04" [centos]="centos6 centos7") + +function self_in_docker() { + local script=$1 + shift + + if test $# -gt 0 ; then + eval OS_TYPE2VERSIONS="$@" + fi +} + +function remove_all() { + local os_type=$1 + local os_version=$2 + local image=$(get_image_name $os_type $os_version) + + docker rm $image + docker rmi $image +} + +function usage() { + cat < /dev/null 2>&1 ; then + echo "docker not available: $0" + return 0 + fi + + local temp + temp=$(getopt -o scdht:v:u:o:a: --long remove-all,verbose,shell,compile,dev,help,os-type:,os-version:,user:,opts:,all: -n $0 -- "$@") || return 1 + + eval set -- "$temp" + + local os_type=ubuntu + local os_version=14.04 + local all + local remove=false + local shell=false + local compile=false + local dev=false + local user=$USER + local opts + while true ; do + case "$1" in + --remove-all) + remove=true + shift + ;; + --verbose) + set -xe + PS4='${FUNCNAME[0]}: $LINENO: ' + shift + ;; + -s|--shell) + shell=true + shift + ;; + -c|--compile) + compile=true + shift + ;; + -d|--dev) + dev=true + shift + ;; + -h|--help) + usage + return 0 + ;; + -t|--os-type) + os_type=$2 + shift 2 + ;; + -v|--os-version) + os_version=$2 + shift 2 + ;; + -u|--user) + user="$2" + shift 2 + ;; + -o|--opts) + opts="$2" + shift 2 + ;; + -a|--all) + all="$2" + shift 2 + ;; + --) + shift + break + ;; + *) + echo "unexpected argument $1" + return 1 + ;; + esac + done + + if test -z "$all" ; then + all="([$os_type]=\"$os_version\")" + fi + + declare -A os_type2versions + eval os_type2versions="$all" + + for os_type in ${!os_type2versions[@]} ; do + for os_version in ${os_type2versions[$os_type]} ; do + if $remove ; then + remove_all $os_type $os_version || return 1 + elif $shell ; then + run_in_docker $os_type $os_version $dev $user "$opts" bash || return 1 + elif $compile ; then + run_in_docker $os_type $os_version $dev $user "$opts" compile || return 1 + else + run_in_docker $os_type $os_version $dev $user "$opts" "$@" || return 1 + fi + done + done +} diff --git a/src/test/docker-test.sh b/src/test/docker-test.sh new file mode 100755 index 000000000000..d0319fe84db7 --- /dev/null +++ b/src/test/docker-test.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# +# Copyright (C) 2014 Red Hat +# +# Author: Loic Dachary +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Library Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# 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 Library Public License for more details. +# +source test/docker-test-helper.sh + +main_docker "$@" diff --git a/src/test/ubuntu.dockerfile b/src/test/ubuntu.dockerfile new file mode 100644 index 000000000000..294da7c00065 --- /dev/null +++ b/src/test/ubuntu.dockerfile @@ -0,0 +1,30 @@ +# +# Copyright (C) 2014 Red Hat +# +# Author: Loic Dachary +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Library Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# 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 Library Public License for more details. +# +# Environment variables are substituted via envsubst(1) +# +# user_id=$(id -u) +# os_version= the desired REPOSITORY TAG +# +FROM ubuntu:%%os_version%% + +RUN useradd -M --uid %%user_id%% %%USER%% +RUN apt-get update +# build dependencies +RUN apt-get install -y autoconf automake autotools-dev libbz2-dev debhelper default-jdk git javahelper junit4 libaio-dev libatomic-ops-dev libbabeltrace-ctf-dev libbabeltrace-dev libblkid-dev libboost-dev libboost-program-options-dev libboost-system-dev libboost-thread-dev libcurl4-gnutls-dev libedit-dev libexpat1-dev libfcgi-dev libfuse-dev libgoogle-perftools-dev libkeyutils-dev libleveldb-dev libnss3-dev libsnappy-dev liblttng-ust-dev libtool libudev-dev libxml2-dev pkg-config python python-argparse python-nose uuid-dev uuid-runtime xfslibs-dev yasm +# development tools +RUN apt-get install -y ccache valgrind gdb +# make check dependencies +RUN apt-get install -y python-virtualenv gdisk kpartx