adds integration tests to docker setup for traffic_ops
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/0e95708c Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/0e95708c Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/0e95708c Branch: refs/heads/master Commit: 0e95708c73806aaad9743c69cf072130ea397684 Parents: 291cf29 Author: Dan Kirkwood <[email protected]> Authored: Thu Jul 13 16:17:46 2017 -0600 Committer: Jeremy Mitchell <[email protected]> Committed: Fri Jul 14 08:24:04 2017 -0600 ---------------------------------------------------------------------- traffic_ops/app/bin/tests/Dockerfile-test | 71 ++++++++++++++++++++++ traffic_ops/app/bin/tests/Dockerfile-unittest | 66 -------------------- traffic_ops/app/bin/tests/docker-compose.yml | 21 ++++++- traffic_ops/app/bin/tests/runtests.sh | 33 +++++----- 4 files changed, 105 insertions(+), 86 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/0e95708c/traffic_ops/app/bin/tests/Dockerfile-test ---------------------------------------------------------------------- diff --git a/traffic_ops/app/bin/tests/Dockerfile-test b/traffic_ops/app/bin/tests/Dockerfile-test new file mode 100644 index 0000000..10018da --- /dev/null +++ b/traffic_ops/app/bin/tests/Dockerfile-test @@ -0,0 +1,71 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +FROM centos:7 +MAINTAINER Dan Kirkwood <[email protected]> + +RUN yum -y install \ + https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm + +RUN yum -y install \ + cpanminus \ + expat-devel \ + gcc-c++ \ + libcurl \ + libcurl-devel \ + libidn-devel \ + libpcap-devel \ + mkisofs \ + nmap-ncat \ + openssl-devel \ + perl \ + perl-App-cpanminus \ + perl-DBD-Pg \ + perl-DBI \ + perl-Digest-SHA1 \ + perl-JSON \ + perl-TermReadKey \ + perl-Test-CPAN-Meta \ + perl-WWW-Curl \ + perl-core \ + perl-libwww-perl \ + postgresql96 \ + postgresql96-devel && \ + yum clean all + +RUN cpanm -n Carton + +ADD install/bin/install_goose.sh / +RUN /install_goose.sh + +ADD app /opt/traffic_ops/app +WORKDIR /opt/traffic_ops/app +RUN POSTGRES_HOME=/usr/pgsql-9.6 carton + +RUN rm -rf /root/.cpan* + +ADD app/bin/tests/runtests.sh / +ARG TESTDIR +ARG TESTENV +ENV TESTDIR=$TESTDIR +ENV TESTENV=$TESTENV +ARG DBHOST +ARG DBPORT +ENV DBHOST=$DBHOST +ENV DBPORT=$DBPORT + +ENTRYPOINT /runtests.sh $DBHOST $DBPORT +CMD $TESTENV $TESTDIR + +# +# vi:syntax=Dockerfile http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/0e95708c/traffic_ops/app/bin/tests/Dockerfile-unittest ---------------------------------------------------------------------- diff --git a/traffic_ops/app/bin/tests/Dockerfile-unittest b/traffic_ops/app/bin/tests/Dockerfile-unittest deleted file mode 100644 index 0333b0d..0000000 --- a/traffic_ops/app/bin/tests/Dockerfile-unittest +++ /dev/null @@ -1,66 +0,0 @@ -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -FROM centos:7 -MAINTAINER Dan Kirkwood <[email protected]> - -RUN yum -y install \ - https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm - -RUN yum -y install \ - cpanminus \ - expat-devel \ - gcc-c++ \ - libcurl \ - libcurl-devel \ - libidn-devel \ - libpcap-devel \ - mkisofs \ - nmap-ncat \ - openssl-devel \ - perl \ - perl-App-cpanminus \ - perl-DBD-Pg \ - perl-DBI \ - perl-Digest-SHA1 \ - perl-JSON \ - perl-TermReadKey \ - perl-Test-CPAN-Meta \ - perl-WWW-Curl \ - perl-core \ - perl-libwww-perl \ - postgresql96 \ - postgresql96-devel && \ - yum clean all - -RUN curl -o - https://www.kernel.org/pub/software/scm/git/git-2.12.2.tar.gz | tar xzvf - -C /tmp && \ - cd /tmp/git-2.12.2/ && \ - make -i prefix=/usr install && \ - rm -rf /tmp/git-2.12.2 - -RUN cpanm -n Carton - -ADD install/bin/install_goose.sh / -RUN /install_goose.sh - -ADD app /opt/traffic_ops/app -WORKDIR /opt/traffic_ops/app -RUN POSTGRES_HOME=/usr/pgsql-9.6 carton - -RUN rm -rf /root/.cpan* - -ADD app/bin/tests/runtests.sh / -CMD [ "/runtests.sh", "/opt/traffic_ops/app/t", "test", "db", "5432" ] - -# -# vi:syntax=Dockerfile http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/0e95708c/traffic_ops/app/bin/tests/docker-compose.yml ---------------------------------------------------------------------- diff --git a/traffic_ops/app/bin/tests/docker-compose.yml b/traffic_ops/app/bin/tests/docker-compose.yml index f464144..ac8239b 100644 --- a/traffic_ops/app/bin/tests/docker-compose.yml +++ b/traffic_ops/app/bin/tests/docker-compose.yml @@ -27,7 +27,26 @@ services: unit: build: context: ../../.. - dockerfile: app/bin/tests/Dockerfile-unittest + dockerfile: app/bin/tests/Dockerfile-test + args: + TESTENV: test + TESTDIR: /opt/traffic_ops/app/t + DBHOST: db + DBPORT: 5432 + links: + - db + volumes: + - traffic_ops:/opt/traffic_ops + + integration: + build: + context: ../../.. + dockerfile: app/bin/tests/Dockerfile-test + args: + TESTENV: integration + TESTDIR: /opt/traffic_ops/app/t_integration + DBHOST: db + DBPORT: 5432 links: - db volumes: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/0e95708c/traffic_ops/app/bin/tests/runtests.sh ---------------------------------------------------------------------- diff --git a/traffic_ops/app/bin/tests/runtests.sh b/traffic_ops/app/bin/tests/runtests.sh index 8a27f88..1e0329d 100755 --- a/traffic_ops/app/bin/tests/runtests.sh +++ b/traffic_ops/app/bin/tests/runtests.sh @@ -17,14 +17,10 @@ # set up db based on given conf file set -x -testdir=$1 -dbenv=$2 -dbhost=$3 -dbport=${4:-5432} export PERL5LIB=/opt/traffic_ops/app/lib:/opt/traffic_ops/app/local/lib/perl5 usage() { - echo "Usage: $(basename $0) <test dir> <dbenv> <host> <port>" + echo "Usage: $(basename $0) <test dir> <test env> <host> <port>" echo " e.g. $(basename $0) ./t test db 5432" } @@ -36,41 +32,40 @@ finish() { trap finish EXIT -dbconf=/opt/traffic_ops/app/conf/$dbenv/database.conf +dbconf=/opt/traffic_ops/app/conf/$TESTENV/database.conf if [[ ! -f $dbconf ]]; then usage msg="$dbconf should be a file" exit 1 fi -if [[ ! -d $testdir ]]; then +if [[ ! -d $TESTDIR ]]; then usage - msg="$testdir should be a directory" + msg="$TESTDIR should be a directory" exit 1 fi -while ! nc $dbhost $dbport </dev/null; do # &>/dev/null; do - dig $dbhost +short - echo "waiting for $dbhost:$dbport" +while ! nc $DBHOST $DBPORT </dev/null; do # &>/dev/null; do + echo "waiting for $DBHOST:$DBPORT" sleep 3 done # get dbname, user, password from database.conf; update it with hostname of db container -read dbname user pw <<<$(python -c "import json; d=json.load(open('$dbconf')); d['hostname']='$dbhost'; d['port']='$dbport'; json.dump(d, open('$dbconf', 'w')); print d['dbname'],d['user'],d['password']") || exit $? +read dbname user pw <<<$(python -c "import json; d=json.load(open('$dbconf')); d['hostname']='$DBHOST'; d['port']='$DBPORT'; json.dump(d, open('$dbconf', 'w')); print d['dbname'],d['user'],d['password']") || exit $? # update dbconf.yml -sed -E -i "s/host=[^ ]+/host=$dbhost/" /opt/traffic_ops/app/db/dbconf.yml +sed -E -i "s/host=[^ ]+/host=$DBHOST/" /opt/traffic_ops/app/db/dbconf.yml # create user if doesn't exist -st=$(psql -h$dbhost -p$dbport -Upostgres -tAc "SELECT 1 from pg_roles WHERE rolname='$user'") || exit $? +st=$(psql -h$DBHOST -p$DBPORT -Upostgres -tAc "SELECT 1 from pg_roles WHERE rolname='$user'") || exit $? if [[ $st != 1 ]]; then - psql -h$dbhost -Upostgres -etAc "CREATE USER $user with LOGIN ENCRYPTED PASSWORD '$pw'" || exit $? + psql -h$DBHOST -Upostgres -etAc "CREATE USER $user with LOGIN ENCRYPTED PASSWORD '$pw'" || exit $? fi -st=$(psql -h$dbhost -p$dbport -Upostgres -tAc "SELECT 1 FROM pg_database WHERE datname='$dbname'") || exit $? +st=$(psql -h$DBHOST -p$DBPORT -Upostgres -tAc "SELECT 1 FROM pg_database WHERE datname='$dbname'") || exit $? if [[ $st != 1 ]]; then - createdb -h$dbhost -p$dbport -Upostgres -e --owner $user $dbname || exit $? + createdb -h$DBHOST -p$DBPORT -Upostgres -e --owner $user $dbname || exit $? fi cd /opt/traffic_ops/app @@ -87,6 +82,6 @@ export GOPATH=/opt/traffic_ops/go PATH=$PATH:$GOPATH/bin:$GOROOT/bin export PGOPTIONS='--client-min-messages=warning' -./db/admin.pl --env=test reset +./db/admin.pl --env=$TESTENV reset -prove -qrp $testdir +prove -qrp $TESTDIR
