From 9ef94e4223db28f6f745d13fc4a502a4a1bb0ac6 Mon Sep 17 00:00:00 2001 From: Alexander Lutay Date: Wed, 27 Jan 2016 17:36:51 +0100 Subject: [PATCH] MT#17601 Add Dockerfile to run rate-o-mat tests Change-Id: I0ae48e3c331bb8682f3e9da2f40c58f391cb58a4 --- t/Dockerfile | 45 +++++++++++++++++++++++++++++++++++++++++++++ t/testrunner | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 t/Dockerfile create mode 100755 t/testrunner diff --git a/t/Dockerfile b/t/Dockerfile new file mode 100644 index 0000000..4eb0c88 --- /dev/null +++ b/t/Dockerfile @@ -0,0 +1,45 @@ +# DOCKER_NAME=rate-o-mat-functional-tests-jessie +FROM docker.mgm.sipwise.com/sipwise-jessie:latest + +# Important! Update this no-op ENV variable when this Dockerfile +# is updated with the current date. It will force refresh of all +# of the base images and things like `apt-get update` won't be using +# old cached versions when the Dockerfile is built. +ENV REFRESHED_AT 2016-01-27 + +# TODO - the release-trunk-jessie is too dynamic yet, though required build deps +RUN echo "deb https://deb.sipwise.com/autobuild/ release-trunk-jessie main" >>/etc/apt/sources.list + +RUN apt-get update +RUN apt-get install --assume-yes \ + libboolean-perl \ + libdata-rmap-perl \ + libdatetime-format-iso8601-perl \ + libdatetime-format-strptime-perl \ + libjson-perl \ + libtap-formatter-junit-perl \ + libtap-harness-archive-perl \ + libtext-table-perl \ + libtime-warp-perl \ + ngcp-rate-o-mat \ + mysql-client +RUN apt-get clean + +RUN echo "cd /code && ./testrunner 1.2.3.4" > /root/.bash_history + +WORKDIR /code + +################################################################################ +# Instructions for usage +# ---------------------- +# When you want to build the base image from scratch (jump to the next section if you don't want to build yourself!): +# % docker build --no-cache --tag="rate-o-mat-functional-tests-jessie" . +# % docker run --rm -i -t -v $(pwd):/code:rw rate-o-mat-functional-tests-jessie:latest bash +# +# Use the existing docker image: +# % docker pull docker.mgm.sipwise.com/rate-o-mat-functional-tests-jessie +# % docker run --rm -i -t -v $(pwd):/code:rw docker.mgm.sipwise.com/rate-o-mat-functional-tests-jessie:latest bash +# +# Inside docker: +# cd /code && ./t/testrunner $IP_OF_NGCP_SYSTEM # IP_OF_NGCP_SYSTEM can be e.g. IP of a `vagrant up ce-trunk` system (eth1) +################################################################################ diff --git a/t/testrunner b/t/testrunner new file mode 100755 index 0000000..2b4a03b --- /dev/null +++ b/t/testrunner @@ -0,0 +1,47 @@ +#!/bin/bash + +if ! [ -f /.dockerinit ]; then + echo "Not running inside docker, exiting to avoid data damage." >&2 + exit 1 +fi + +set -e +set -u + +if [ -z "${1:-}" ] ; then + echo "Usage: $0 " >&2 + echo + echo "Usage example: $0 192.168.88.162" + exit 1 +fi + +SERVER="${1}" + +MYSQL_SERVER="${SERVER}" +MYSQL_PORT="3306" +MYSQL_USER="root" +echo "Testing MySQL connection to ${MYSQL_SERVER}:${MYSQL_PORT} ..." +if ! mysql -u "${MYSQL_USER}" -h "${SERVER}" -P "${MYSQL_PORT}" -e 'select now()' >/dev/null ; then + echo "ERROR: Cannot connect to MySQL on ${MYSQL_SERVER}:${MYSQL_PORT} using user '${MYSQL_USER}', cannot continue!" >&2 + echo "HINTs:" + echo " [CE] remove 'skip_networking' from /etc/ngcp-config/templates/etc/mysql/my.cnf.tt2 && ngcpcfg apply 'Allow TCP for MySQL'" + echo " [CE/PRO] run: mysql -u root -e \"GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY PASSWORD ''; FLUSH PRIVILEGES;\"" + exit 1 +fi + +echo "################################################################################" +echo "Finished main setup, now running tests ..." + +RC=0 +results="/code/rate-o-mat-unit-test-results.pretty" + +CATALYST_SERVER="https://${SERVER}:1443" RATEOMAT_PROVISIONING_DB_HOST="${MYSQL_SERVER}" \ +RATEOMAT_BILLING_DB_HOST="${MYSQL_SERVER}" RATEOMAT_ACCOUNTING_DB_HOST="${MYSQL_SERVER}" \ +RATEOMAT_PL="/usr/sbin/rate-o-mat" prove -v --color -l -IUtils/ ./*.t | tee -a "${results}" +RC=${PIPESTATUS[0]} + +echo "Finished test execution, test execution returned with exit code ${RC}." +if [ -f "${results}" ] ; then + echo "Test results available at ${results}" +fi +echo "################################################################################"