Skip to content
Snippets Groups Projects
Commit d127464f authored by MJB's avatar MJB
Browse files

adding gitlab ci

parent 3f12f497
No related branches found
No related tags found
No related merge requests found
stages:
- test
test_scripts:
stage: test
script:
- vagrant --fixture=scripts" -- up
- vagrant --fixture=scripts" -- ssh -- "cd /vagrant && pytest test/scripts/"
- vagrant --fixture=scripts" -- destroy --force
when: manual
...@@ -104,7 +104,7 @@ Vagrant.configure("2") do |config| ...@@ -104,7 +104,7 @@ Vagrant.configure("2") do |config|
instance_config.vm.provision :shell, inline: "cp /vagrant/test/services/#{host["service_name"]}/telegraf_#{host["service_name"]}.conf /etc/telegraf/telegraf.d/" instance_config.vm.provision :shell, inline: "cp /vagrant/test/services/#{host["service_name"]}/telegraf_#{host["service_name"]}.conf /etc/telegraf/telegraf.d/"
# CLMC agent general and output configuration # CLMC agent general and output configuration
instance_config.vm.provision :shell, :path => "scripts/clmc-agent/write_config.sh" instance_config.vm.provision :shell, :path => "scripts/clmc-agent/configure_template.sh"
instance_config.vm.provision :shell, :path => "scripts/clmc-agent/configure.sh", :args => "#{host["location"]} #{host["sfc_id"]} #{host["sfc_id_instance"]} #{host["sf_id"]} #{host["sf_id_instance"]} #{host["ipendpoint_id"]} #{host["influxdb_url"]} #{host["database_name"]}" instance_config.vm.provision :shell, :path => "scripts/clmc-agent/configure.sh", :args => "#{host["location"]} #{host["sfc_id"]} #{host["sfc_id_instance"]} #{host["sf_id"]} #{host["sf_id_instance"]} #{host["ipendpoint_id"]} #{host["influxdb_url"]} #{host["database_name"]}"
......
#!/bin/bash
#/////////////////////////////////////////////////////////////////////////
#//
#// (c) University of Southampton IT Innovation Centre, 2017
#//
#// Copyright in this software belongs to University of Southampton
#// IT Innovation Centre of Gamma House, Enterprise Road,
#// Chilworth Science Park, Southampton, SO16 7NS, UK.
#//
#// This software may not be used, sold, licensed, transferred, copied
#// or reproduced in whole or in part in any manner or form or in or
#// on any media by any person other than in accordance with the terms
#// of the Licence Agreement supplied with the software, or otherwise
#// without the prior written consent of the copyright owners.
#//
#// This software is distributed WITHOUT ANY WARRANTY, without even the
#// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
#// PURPOSE, except where stated in the Licence Agreement supplied with
#// the software.
#//
#// Created By : Michael Boniface
#// Created Date : 19/03/2018
#// Created for Project : FLAME
#//
#/////////////////////////////////////////////////////////////////////////
TELEGRAF_CONF_DIR="/etc/telegraf"
TELEGRAF_CONF_FILE=$TELEGRAF_CONF_DIR"/telegraf.conf"
TELEGRAF_INCLUDE_CONF_DIR=$TELEGRAF_CONF_DIR"/telegraf.d"
TELEGRAF_OUTPUT_CONF_FILE=$TELEGRAF_INCLUDE_CONF_DIR"/telegraf_output.conf"
echo "Checking Telegraf installation"
# Check the target telegraf directory exists
if [ ! -d "$TELEGRAF_CONF_DIR" ]; then
echo "Error: Telegraf conf directory does not exist on target machine. Check that telegraf is installed "$TELEGRAF_CONF_DIR
exit 1
fi
# Check the target telegraf directory exists
if [ ! -d $TELEGRAF_INCLUDE_CONF_DIR ]; then
echo "Error: Telegraf conf include directory does not exist on target machine. Check that telegraf is installed "$TELEGRAF_INCLUDE_CONF_DIR
exit 1
fi
# Copy configuration
echo "Telegraf general config file: " $TELEGRAF_CONF_FILE
(cat <<'EOF'
[global_tags]
location="$LOCATION"
sfc="$SFC_ID"
sfc_i="$SFC_ID_INSTANCE"
sf="$SF_ID"
sf_i="$SF_ID_INSTANCE"
ipendpoint="$IP_ENDPOINT_ID"
[agent]
interval = "10s"
round_interval = true
metric_buffer_limit = 1000
flush_buffer_when_full = true
collection_jitter = "0s"
flush_interval = "10s"
flush_jitter = "0s"
debug = false
quiet = false
logfile = "/var/log/telegraf/telegraf.log"
hostname = ""
EOF
) > $TELEGRAF_CONF_FILE
echo "Telegraf output config file: " $TELEGRAF_OUTPUT_CONF_FILE
(cat <<'EOF'
[[outputs.influxdb]]
urls = ["$INFLUXDB_URL"]
database = "$DATABASE_NAME"
precision = "s"
timeout = "5s"
EOF
) > $TELEGRAF_OUTPUT_CONF_FILE
...@@ -4,6 +4,8 @@ import pytest ...@@ -4,6 +4,8 @@ import pytest
import subprocess import subprocess
def test_write_telegraf_conf(): def test_write_telegraf_conf():
# test telegraf monitoring configuration
TELEGRAF_CONF_DIR="/etc/telegraf" TELEGRAF_CONF_DIR="/etc/telegraf"
LOCATION="DC1" LOCATION="DC1"
SFC_ID="media_service_A" SFC_ID="media_service_A"
...@@ -15,38 +17,40 @@ def test_write_telegraf_conf(): ...@@ -15,38 +17,40 @@ def test_write_telegraf_conf():
DATABASE_NAME="experimentation_database" DATABASE_NAME="experimentation_database"
try: try:
# run with no telegraf conf directory # run write config template script with no telegraf conf directory
(out, err, code) = run_command('sudo /vagrant/scripts/clmc-agent/write_config.sh') cmd = 'sudo /vagrant/scripts/clmc-agent/configure_template.sh'
(out, err, code) = run_command(cmd)
assert code == 1, "Failed to catch error of no telegraf configuration directory : " + str(code) + ", cmd=" + cmd assert code == 1, "Failed to catch error of no telegraf configuration directory : " + str(code) + ", cmd=" + cmd
# mk telegraf conf directory # mk telegraf conf directory
run_command("sudo mkdir -p /etc/telegraf") run_command("sudo mkdir -p /etc/telegraf")
# run with no telegraf.d directory # run write config template script with no telegraf.d directory
(out, err, code) = run_command('sudo /vagrant/scripts/clmc-agent/write_config.sh') (out, err, code) = run_command(cmd)
assert code == 1, "Failed to catch error of no telegraf include directory : " + str(code) + ", cmd=" + cmd assert code == 1, "Failed to catch error of no telegraf include directory : " + str(code) + ", cmd=" + cmd
# mk telegraf.d directory # mk telegraf.d directory
run_command("sudo mkdir -p /etc/telegraf/telegraf.d") run_command("sudo mkdir -p /etc/telegraf/telegraf.d")
# write configuration to file # run write config template script and check that the script has exited correctly
(out, err, code) = run_command('sudo /vagrant/scripts/clmc-agent/write_config.sh') (out, err, code) = run_command(cmd)
assert code == 0, "Failed to write configuration files : " + str(code) + ", cmd=" + cmd assert code == 0, "Failed to write configuration files : " + str(code) + ", cmd=" + cmd
# run with incorrect arguments # run template relacement script with incorrect arguments
cmd = 'sudo /vagrant/scripts/clmc-agent/configure.sh' cmd = 'sudo /vagrant/scripts/clmc-agent/configure.sh'
(out, err, code) = run_command(cmd) (out, err, code) = run_command(cmd)
assert code == 1, "Failed to return error on incorrect arguments : " + str(code) + ", cmd=" + cmd assert code == 1, "Failed to return error on incorrect arguments : " + str(code) + ", cmd=" + cmd
# run template relacement script with all arguments
cmd = 'sudo /vagrant/scripts/clmc-agent/configure.sh ' + LOCATION + ' ' + SFC_ID + ' ' + SFC_ID_INSTANCE + ' ' + SF_ID + ' ' + SF_ID_INSTANCE + ' ' + IP_ENDPOINT_ID + ' ' + INFLUXDB_URL + ' ' + DATABASE_NAME cmd = 'sudo /vagrant/scripts/clmc-agent/configure.sh ' + LOCATION + ' ' + SFC_ID + ' ' + SFC_ID_INSTANCE + ' ' + SF_ID + ' ' + SF_ID_INSTANCE + ' ' + IP_ENDPOINT_ID + ' ' + INFLUXDB_URL + ' ' + DATABASE_NAME
# run everything setup
(out, err, code) = run_command(cmd) (out, err, code) = run_command(cmd)
assert code == 0, "Configure command returned error, output=" + str(out) + ", cmd=" + cmd assert code == 0, "Configure command returned error, output=" + str(out) + ", cmd=" + cmd
try: # check that replacement was correct in telegraf.conf
TELEGRAF_GENERAL_CONF_FILE = TELEGRAF_CONF_DIR + "/telegraf.d/telegraf_output.conf" try:
TELEGRAF_GENERAL_CONF_FILE = TELEGRAF_CONF_DIR + "/telegraf.conf"
with open(TELEGRAF_GENERAL_CONF_FILE) as general_conf: with open(TELEGRAF_GENERAL_CONF_FILE) as general_conf:
lines = general_conf.read() lines = general_conf.read()
assert lines.find(LOCATION), "Cannot find location" assert lines.find(LOCATION), "Cannot find location"
assert lines.find(SFC_ID), "Cannot find sfc_id" assert lines.find(SFC_ID), "Cannot find sfc_id"
assert lines.find(SFC_ID_INSTANCE), "Cannot find sfc_id_instance" assert lines.find(SFC_ID_INSTANCE), "Cannot find sfc_id_instance"
...@@ -56,8 +60,9 @@ def test_write_telegraf_conf(): ...@@ -56,8 +60,9 @@ def test_write_telegraf_conf():
except FileNotFoundError: except FileNotFoundError:
assert False, "Telegraf general conf file not found, " + TELEGRAF_GENERAL_CONF_FILE assert False, "Telegraf general conf file not found, " + TELEGRAF_GENERAL_CONF_FILE
# check that replacement was correct in telegraf_output.conf
try: try:
TELEGRAF_OUTPUT_CONF_FILE = TELEGRAF_CONF_DIR + "/telegraf.conf" TELEGRAF_OUTPUT_CONF_FILE = TELEGRAF_CONF_DIR + "/telegraf.d/telegraf_output.conf"
with open(TELEGRAF_OUTPUT_CONF_FILE) as output_conf: with open(TELEGRAF_OUTPUT_CONF_FILE) as output_conf:
lines = output_conf.read() lines = output_conf.read()
assert lines.find(INFLUXDB_URL), "Cannot find influx_db" assert lines.find(INFLUXDB_URL), "Cannot find influx_db"
...@@ -67,7 +72,7 @@ def test_write_telegraf_conf(): ...@@ -67,7 +72,7 @@ def test_write_telegraf_conf():
finally: finally:
# clean up telegraf after test # clean up telegraf after test
#run_command("sudo rm -rf /etc/telegraf") run_command("sudo rm -rf /etc/telegraf")
print ("finally") print ("finally")
# wrapper for executing commands on the cli, returning (std_out, std_error, process_return_code) # wrapper for executing commands on the cli, returning (std_out, std_error, process_return_code)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment