dangogh closed pull request #2408: Refactored the API Tests to run in a Docker 
container
URL: https://github.com/apache/trafficcontrol/pull/2408
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/traffic_ops/testing/api/docker/Dockerfile 
b/traffic_ops/testing/api/docker/Dockerfile
new file mode 100644
index 000000000..7d5952fdc
--- /dev/null
+++ b/traffic_ops/testing/api/docker/Dockerfile
@@ -0,0 +1,53 @@
+#
+# 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 golang:1.10.1
+MAINTAINER Dewayne Richardson <dewr...@apache.org>
+
+RUN pwd
+ARG DB_NAME
+ARG DB_SERVER
+ARG DB_PORT
+ARG DB_USER
+ARG DB_PASSWORD
+
+ENV DB_NAME=$DB_SERVER
+ENV DB_SERVER=$DB_SERVER
+ENV DB_PORT=$DB_PORT
+ENV DB_USER=$DB_SERVER
+ENV DB_PASSWORD=$DB_PASSWORD
+
+ARG SRC_DIR=/go/src
+ARG TC_DIR=$SRC_DIR/github.com/apache/incubator-trafficcontrol
+ARG TESTING_DIR=$TC_DIR/traffic_ops/testing
+ARG TESTING_API_DIR=$TESTING_DIR/api
+ 
+#COPY --from=trafficops-perl /opt/traffic_ops/app/bin/traffic_ops_golang 
/opt/traffic_ops/app/bin/traffic_ops_golang
+#COPY --from=trafficops-perl /usr/local/go /usr/local/go
+
+WORKDIR $TC_DIR
+
+# Add the lib/go-tc dir
+ADD lib lib
+
+# Add the dependent dirs (without the cruft)
+ADD traffic_ops/traffic_ops_golang traffic_ops/traffic_ops_golang
+ADD traffic_ops/vendor traffic_ops/vendor
+ADD traffic_ops/testing/api traffic_ops/testing/api
+ADD traffic_ops/client traffic_ops/client
+
+#ADD conf .
+WORKDIR $TESTING_API_DIR/v13
+CMD ../docker/run_api_tests.sh
+
+# vi:syntax=Dockerfile
diff --git a/traffic_ops/testing/api/docker/Dockerfile-to-base 
b/traffic_ops/testing/api/docker/Dockerfile-to-base
deleted file mode 100644
index 7718efa0c..000000000
--- a/traffic_ops/testing/api/docker/Dockerfile-to-base
+++ /dev/null
@@ -1,74 +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.2.1511
-FROM centos:7
-MAINTAINER Dan Kirkwood <dang...@apache.org>
-
-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 \
-        epel-release \
-        vim \
-        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 \
-        perl-Crypt-ScryptKDF \
-        postgresql96 \
-        postgresql96-devel && \
-        yum clean all
-
-RUN cpanm -n Carton
-
-ARG TO_DIR=traffic_ops
-ARG API_DOCKER_DIR=traffic_ops/testing/api/docker
-
-ARG TO_RPM=traffic_ops-2.2.0-7398.7bb32b09.el7.x86_64.rpm
-ADD $API_DOCKER_DIR/$TO_RPM /
-WORKDIR /
-RUN yum -y install $TO_RPM
-
-ADD $TO_DIR/install/bin/install_goose.sh /
-ADD $TO_DIR/install/bin/install_go.sh /
-RUN /install_go.sh
-RUN /install_goose.sh
-
-
-#ADD $API_DOCKER_DIR/local /opt/traffic_ops/app
-WORKDIR /opt/traffic_ops/app
-
-RUN POSTGRES_HOME=/usr/pgsql-9.6 carton
-
-CMD bash -c 'echo "Completed"'
-#CMD bash -c 'mv -v local /'
-
-#EXPOSE 60443
diff --git a/traffic_ops/testing/api/docker/Dockerfile-to-test 
b/traffic_ops/testing/api/docker/Dockerfile-to-test
deleted file mode 100644
index 63d359717..000000000
--- a/traffic_ops/testing/api/docker/Dockerfile-to-test
+++ /dev/null
@@ -1,48 +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.2.1511
-FROM docker_to_base:latest
-MAINTAINER Dewayne Richardson <dewr...@apache.org>
-
-ARG TO_DIR=traffic_ops
-ARG TESTENV=$TESTENV
-ARG API_DOCKER_DIR=traffic_ops/testing/api/docker
-# ignore this if it fails
-#RUN rm -rf /root/.cpan* 2>/dev/null || true
-
-ARG TESTDIR
-ARG TESTENV
-ENV TESTDIR=$TESTDIR
-ENV TESTENV=$TESTENV
-ARG DBHOST
-ARG DBPORT
-ENV DBHOST=$DBHOST
-ENV DBPORT=$DBPORT
-#ADD $API_DOCKER_DIR/run_traffic_ops.sh /opt/traffic_ops/app
-
-ARG TO_RPM=traffic_ops-2.2.0-7398.7bb32b09.el7.x86_64.rpm
-ADD $API_DOCKER_DIR/$TO_RPM /
-ADD $API_DOCKER_DIR/run_traffic_ops.sh /
-#WORKDIR /
-#RUN yum -y install $TO_RPM
-
-#ADD $API_DOCKER_DIR/local /opt/traffic_ops/app
-WORKDIR /opt/traffic_ops/app
-
-ENV PERL5LIB="/opt/traffic_ops/app/lib:/opt/traffic_ops/app/local/lib/perl5"
-
-RUN POSTGRES_HOME=/usr/pgsql-9.6 carton
-CMD /run_traffic_ops.sh
-
-#EXPOSE 60443
diff --git a/traffic_ops/testing/api/docker/README.md 
b/traffic_ops/testing/api/docker/README.md
index ca9576bf3..98e135115 100644
--- a/traffic_ops/testing/api/docker/README.md
+++ b/traffic_ops/testing/api/docker/README.md
@@ -24,5 +24,4 @@ environment variables. By default the docker-compose.yml will 
look for it's defa
 
 When necessary the environment variables can be overridden via the command 
line docker-compose option as well like this:
 
-  $ docker-compose run -e TODB_HOSTNAME=your_traffic_ops_db_hostname -e 
TO_URL=https://your_traffic_ops_ip:8443 api_tests
-
+  $ docker-compose up --build 
diff --git a/traffic_ops/testing/api/docker/docker-compose.yml 
b/traffic_ops/testing/api/docker/docker-compose.yml
index daa8b2460..7f39e20b8 100644
--- a/traffic_ops/testing/api/docker/docker-compose.yml
+++ b/traffic_ops/testing/api/docker/docker-compose.yml
@@ -14,50 +14,25 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+#../../../../infrastructure/cdn-in-a-box/traffic_ops/
+#infrastructure/cdn-in-a-box/traffic_ops/
+
 ---
-version: '2'
+version: '3'
 
-volumes:
-  incubator-trafficcontrol:
-  traffic_ops:
-  conf:
+networks:
+  default:
+    external:
+      name: traffic_ops_tcnet
 
 services:
-  db:
-    image: postgres:9.6.6
-
-  to_base:
-    build:
-      context: ../../../..
-      dockerfile: traffic_ops/testing/api/docker/Dockerfile-to-base
-    volumes:
-      - traffic_ops:/opt/traffic_ops
-    links:
-      - db
-
-  to_test:
-    build:
-      context: ../../../..
-      dockerfile: traffic_ops/testing/api/docker/Dockerfile-to-test
-      args:
-        TESTENV: test
-        DBHOST: db
-        DBPORT: 5432
-    links:
-      - db
-
-  api_tests:
+  trafficops_api_tests:
+    image: trafficops-api-tests
     build:
       context: ../../../..
-      dockerfile: traffic_ops/testing/api/docker/Dockerfile-api-tests
+      dockerfile: traffic_ops/testing/api/docker/Dockerfile
       args:
-        DBHOST: db
-        DBPORT: 5432
+        DB_SERVER: db
+        DB_PORT: 5432
     env_file:
       - traffic-ops-test.env
-    volumes:
-      - incubator-trafficcontrol:/incubator-trafficcontrol
-      - conf:/conf
-    links:
-      - db
-      - to_test
diff --git a/traffic_ops/testing/api/docker/run_api_tests.sh 
b/traffic_ops/testing/api/docker/run_api_tests.sh
index 7dd661351..d6159b35a 100755
--- a/traffic_ops/testing/api/docker/run_api_tests.sh
+++ b/traffic_ops/testing/api/docker/run_api_tests.sh
@@ -24,8 +24,10 @@
 source /etc/environment
 
 start() {
-   cd /opt/traffic_ops/testing/api
-   go get -u golang.org/x/net/publicsuffix && go test -v 
-cfg=conf/traffic-ops-test.conf
+   export PATH=/usr/local/go/bin:/opt/traffic_ops/go/bin:$PATH
+   export GOPATH=/go
+   go get -u golang.org/x/net/publicsuffix golang.org/x/crypto/scrypt
+   TODB_HOSTNAME=db TODB_NAME=traffic_ops TO_URL=https://trafficops go test -v 
-cfg=../conf/traffic-ops-test.conf
 }
 
 
@@ -42,11 +44,4 @@ finish() {
         [[ -n $msg ]] && echo $msg
 }
 
-trap finish EXIT
-
-while ! nc $DBHOST $DBPORT </dev/null; do # &>/dev/null; do
-        echo "waiting for $DBHOST:$DBPORT"
-        sleep 3
-done
-
 start
diff --git a/traffic_ops/testing/api/docker/run_traffic_ops.sh 
b/traffic_ops/testing/api/docker/run_traffic_ops.sh
deleted file mode 100755
index ba2672645..000000000
--- a/traffic_ops/testing/api/docker/run_traffic_ops.sh
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/usr/bin/env bash
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you 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.
-
-# Script for running the Dockerfile for Traffic Ops.
-# The Dockerfile sets up a Docker image which can be used for any new Traffic 
Ops container;
-# This script, which should be run when the container is run (it's the 
ENTRYPOINT), will configure the container.
-#
-source /etc/environment
-
-set -x
-export PERL5LIB=/opt/traffic_ops/app/lib:/opt/traffic_ops/app/local/lib/perl5
-
-usage() {
-        echo "Usage: $(basename $0) <test dir> <test env> <host> <port>"
-        echo "  e.g. $(basename $0) ./t test db 5432"
-}
-
-finish() {
-        local st=$?
-        [[ $st -ne 0 ]] && echo "Exiting with status $st"
-        [[ -n $msg ]] && echo $msg
-}
-
-trap finish EXIT
-
-dbconf=/opt/traffic_ops/app/conf/$TESTENV/database.conf
-if [[ ! -f $dbconf ]]; then
-        usage
-        msg="$dbconf should be a file"
-        exit 1
-fi
-
-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 $?
-
-# update dbconf.yml
-sed -E -i "s/host=[^ ]+/host=$DBHOST/" /opt/traffic_ops/app/db/dbconf.yml
-
-# create Postgres Role if doesn't exist
-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 $?
-fi
-
-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 $?
-fi
-
-#echo "/opt/traffic_ops/app/db/dbconf.yml"
-#cat /opt/traffic_ops/app/db/dbconf.yml
-
-#echo "/opt/traffic_ops/app/conf/$TESTENV/database.conf"
-#cat "/opt/traffic_ops/app/conf/$TESTENV/database.conf"
-
-export GOROOT=/usr/local/go
-export GOPATH=/opt/traffic_ops/go
-PATH=$PATH:$GOPATH/bin:$GOROOT/bin
-
-export PGOPTIONS='--client-min-messages=warning'
-echo "PERL5LIB: $PERL5LIB"
-export USER=root
-
-cd /opt/traffic_ops/app
-./db/admin.pl --env=$TESTENV reset
diff --git a/traffic_ops/testing/api/docker/traffic-ops-test.env 
b/traffic_ops/testing/api/docker/traffic-ops-test.env
index ef1f0de1e..bdd5c7b16 100644
--- a/traffic_ops/testing/api/docker/traffic-ops-test.env
+++ b/traffic_ops/testing/api/docker/traffic-ops-test.env
@@ -18,9 +18,7 @@ TO_URL=https://localhost:8443
 TO_USER=admin
 TO_USER_PASSWORD=twelve
 SSL_INSECURE=true
-TODB_NAME=to_test
-TODB_USER=traffic_ops
-TODB_HOSTNAME=localhost
-TODB_PASSWORD=twelve
-TODB_PORT=5432
-SESSION_TIMEOUT_IN_SECS=10
+DB_NAME=traffic_ops
+DB_USER=traffic_ops
+DB_PASSWORD=twelve
+DB_PORT=5432


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to