diff --git a/README.md b/README.md index 405b567128d1d969c767cc7691953bb93e6448cd..e68c2d8df72b0447c647df903283331402679848 100644 --- a/README.md +++ b/README.md @@ -59,16 +59,30 @@ SSH into the VM `vagrant ssh` -Create the services needed for integration tests +The containers are controlled using a script called /vagrant/scripts/test/fixtures.sh + +``` +Usage: fixturs.sh create|start|stop|destroy [-f config_file] [-r repo_root] [-c service_name]" +``` + +To create all the services needed for integration tests ``` sudo su -/vagrant/scripts/test/conts-create.sh +/vagrant/scripts/test/fixtures.sh create -f /vagrant/src/test/clmctest/rspec.json ``` -All of the containers created are defined in the file `/vagrant/src/test/clmctest/rspec.json` +The containers created are defined an rspec.json file, there's an example here `/vagrant/src/test/clmctest/rspec.json` + +The `fixtures.sh` script defaults to look for a rspec.json in the current directory, you can specify a specific rspec.json file using the -f option + +To create|start|stop|destroy specific services use the -c option e.g. + +``` +/vagrant/scripts/test/fixtures.sh create -f /vagrant/src/test/clmctest/rspec.json -c clmc-service +``` -Attach to the test-runner +Attach to the test-runner to run the tests `lxc-attach -n test-runner` diff --git a/scripts/clmc-service/install.sh b/scripts/clmc-service/install.sh index 94ff9b5b6021ee52b4ccf34e0eb5735d9021e32a..2c25e7212b31ba3ce8615f60acce0c220d06b31c 100755 --- a/scripts/clmc-service/install.sh +++ b/scripts/clmc-service/install.sh @@ -95,9 +95,6 @@ systemctl start chronograf ## CLMC-SERVICE ## ---------------------------------------------------------------------------------- - - - echo "----> Configuring virtualenvwrapper" export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh @@ -150,15 +147,33 @@ if [ $? -ne 0 ] ; then exit 1 fi -# start the service -echo "----> Starting CLMC web service" -nohup pserve production.ini > /dev/null 2>&1 & -if [ $? -ne 0 ] ; then - echo "Failed: starting clmc-webservice" - exit 1 -else - echo "CLMC service started." -fi +# Install minioclmc as systemctl service +# ----------------------------------------------------------------------- +mkdir -p /opt/flame/clmc +start_script_file="/opt/flame/clmc/start.sh" +echo "#!/bin/bash" > $start_script_file +echo "export WORKON_HOME=${HOME}/.virtualenvs" >> $start_script_file +echo "source /usr/local/bin/virtualenvwrapper.sh" >> $start_script_file +echo "workon CLMC" >> $start_script_file +echo "pserve ${REPO_ROOT}/src/service/production.ini > /dev/null 2>&1 &" >> $start_script_file + +chmod 755 $start_script_file + +file="/lib/systemd/system/flameclmc.service" +echo "[Unit]" > $file +echo "Description=flameclmc" >> $file +echo "After=network.target" >> $file +echo "" >> $file +echo "[Service]" >> $file +echo "Type=forking" >> $file +echo "ExecStart=${start_script_file}" >> $file +echo "" >> $file +echo "[Install]" >> $file +echo "WantedBy=multi-user.target" >> $file + +systemctl daemon-reload +systemctl enable flameclmc.service +systemctl start flameclmc.service # wait for the clmc service to start while ! nc -z localhost 9080 diff --git a/scripts/test/conts-destroy.sh b/scripts/test/conts-destroy.sh deleted file mode 100755 index 456816dc54ba3bc6960f9dc417a01532cd1100ca..0000000000000000000000000000000000000000 --- a/scripts/test/conts-destroy.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -set -eu -o pipefail -cd `dirname $0` - -source conts-env.sh - -service_names=$(jq -r '.[].name' ${rspec_file}) -for service_name in $service_names; do - if lxc-info -n ${service_name}; then - echo "Stopping container: ${service_name}" - lxc-stop -n ${service_name} - echo "Destroying container: ${service_name}" - lxc-destroy -n ${service_name} - ip=$(jq -r --arg NAME ${service_name} '.[] | select(.name==$NAME) | .ip_address' ${rspec_file}) - sed -i "/dhcp-host=${service_name},/d" /etc/lxc/dnsmasq.conf - fi -done diff --git a/scripts/test/conts-env.sh b/scripts/test/conts-env.sh deleted file mode 100755 index 742d54779cb3a2434cb70b07ef1dff8ceb461f92..0000000000000000000000000000000000000000 --- a/scripts/test/conts-env.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -repo_root="/vagrant" -rspec_file=$repo_root"/src/test/clmctest/rspec.json" \ No newline at end of file diff --git a/scripts/test/conts-start.sh b/scripts/test/conts-start.sh deleted file mode 100755 index 2af56c1a6f3ee7a301bdefd6f9e4fe1ce7487e1e..0000000000000000000000000000000000000000 --- a/scripts/test/conts-start.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -set -eu -o pipefail -cd `dirname $0` - -source conts-env.sh - -service_names=$(jq -r '.[].name' ${rspec_file}) -for service_name in $service_names; do - if lxc-info -n ${service_name}; then - echo "Starting container: ${service_name}" - lxc-start -n ${service_name} - fi -done diff --git a/scripts/test/conts-stop.sh b/scripts/test/conts-stop.sh deleted file mode 100755 index a64786939ffdbfa2a7916da356d69b3a197c749f..0000000000000000000000000000000000000000 --- a/scripts/test/conts-stop.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -set -eu -o pipefail -cd `dirname $0` - -source conts-env.sh - -service_names=$(jq -r '.[].name' ${rspec_file}) -for service_name in $service_names; do - if lxc-info -n ${service_name}; then - echo "Stopping container: ${service_name}" - lxc-stop -n ${service_name} - fi -done \ No newline at end of file diff --git a/scripts/test/conts-create.sh b/scripts/test/fixture.sh old mode 100755 new mode 100644 similarity index 61% rename from scripts/test/conts-create.sh rename to scripts/test/fixture.sh index 637d8ba519666e16c9681a2d96903fe3914ec1e9..acc239eefaf17d63ae09d62131ead09043eb1325 --- a/scripts/test/conts-create.sh +++ b/scripts/test/fixture.sh @@ -1,16 +1,18 @@ #!/bin/bash -set -eu -o pipefail -cd `dirname $0` -source conts-env.sh +usage() { + echo "Usage: $0 create|start|stop|destroy [-f config_file] [-r repo_root] [-c service_name]" 1>&2 + exit 1 +} -# iterate through each service required for integration testing -service_names=$(jq -r '.[].name' ${rspec_file}) -for service_name in $service_names; do +create() { + service_name=$1 + config_file=$2 + repo_root=$3 if ! lxc-info -n ${service_name}; then # create a container with a static ip address echo "Creating container: ${service_name}" - SERVICE=$(jq --arg NAME ${service_name} '.[] | select(.name==$NAME)' ${rspec_file}) + SERVICE=$(jq --arg NAME ${service_name} '.[] | select(.name==$NAME)' ${config_file}) echo $SERVICE ip=$(echo $SERVICE | jq -r '.ip_address') echo "dhcp-host=${service_name},${ip}" >> /etc/lxc/dnsmasq.conf @@ -83,10 +85,92 @@ for service_name in $service_names; do lxc-attach -n ${service_name} -- service telegraf restart fi fi +} + +start() { + service_name=$1 + if lxc-info -n ${service_name}; then + echo "Starting container: ${service_name}" + lxc-start -n ${service_name} + fi +} + +stop() { + service_name=$1 + if lxc-info -n ${service_name}; then + echo "Stopping container: ${service_name}" + lxc-stop -n ${service_name} + fi +} + +destroy() { + service_name=$1 + config_file=$2 + if lxc-info -n ${service_name}; then + echo "Stopping container: ${service_name}" + lxc-stop -n ${service_name} + echo "Destroying container: ${service_name}" + lxc-destroy -n ${service_name} + ip=$(jq -r --arg NAME ${service_name} '.[] | select(.name==$NAME) | .ip_address' ${config_file}) + sed -i "/dhcp-host=${service_name},/d" /etc/lxc/dnsmasq.conf + fi +} + +# inc option index by 1 as first argument is the command and not parsed by getopts +if [ $# -gt 1 ]; then + OPTIND=$((OPTIND+1)) +fi + +repo_root="/vagrant" +config_file="rspec.json" + +# collect the optional arguments +while getopts "hf:r:c:" opt; do + case $opt in + h) usage; exit ;; + f) config_file=${OPTARG} ;; + r) repo_root=${OPTARG} ;; + c) container=${OPTARG} ;; + \?) usage ;; + esac done -#./conts-stop.sh +# check configuration file exists +if [ ! -f ${config_file} ]; then + echo "Configuration file does not exist: ${config_file}" >&2 + usage + exit 1 +fi -#service lxc-net restart +# check repo root directory exists +if [ ! -d ${repo_root} ]; then + echo "Repo root directory does not exist: ${repo_root}" >&2 + usage + exit 1 +fi -#./conts-start.sh \ No newline at end of file +# iterate of list of services in configuration file +command=$1 +service_names=$(jq -r '.[].name' ${config_file}) +for service_name in $service_names; do + # if all or specific container + if [ -z ${container} ] || [ ${container} == ${service_name} ]; then + case "${command}" in + create) + create ${service_name} ${config_file} ${repo_root} + ;; + start) + start ${service_name} ${config_file} ${repo_root} + ;; + stop) + stop ${service_name} ${config_file} ${repo_root} + ;; + destroy) + destroy ${service_name} ${config_file} ${repo_root} + ;; + *) + usage + ;; + esac + fi +done