Skip to content
Snippets Groups Projects
Commit c597c26a authored by Nikolay Stanchev's avatar Nikolay Stanchev
Browse files

Merged integration into clmcservice

parents 6e055509 8b9012a5
No related branches found
No related tags found
No related merge requests found
......@@ -13,4 +13,5 @@ ubuntu-xenial-16.04-cloudimg-console.log
*$py.class
**/.pytest_cache/
build/
reporc
......@@ -28,10 +28,11 @@ build:tests:
only:
- schedules
script:
- cd src/test
- python setup.py sdist --dist-dir=../../build
- cd ../../src/service
- python setup.py sdist --dist-dir=../../build
- echo $CI_PROJECT_DIR
- cd $CI_PROJECT_DIR/src/test
- python setup.py sdist --dist-dir=$CI_PROJECT_DIR/build
- cd $CI_PROJECT_DIR/src/service
- python setup.py sdist --dist-dir=$CI_PROJECT_DIR/build
artifacts:
paths:
- build/clmctest-SNAPSHOT.tar.gz
......@@ -44,18 +45,19 @@ test:all:
- schedules
dependencies:
- build:tests
script:
# - echo "REPO_USER=${REPO_USER}" > reporc
# - echo "REPO_PASS=${REPO_PASS}" >> reporc
- vagrant --fixture=scripts -- up
- vagrant --fixture=scripts -- ssh test-runner -- -tt "pip3 install /vagrant/build/clmctest-SNAPSHOT.tar.gz"
- vagrant --fixture=scripts -- ssh test-runner -- -tt "pytest -s --pyargs clmctest.scripts"
- vagrant --fixture=monitoring -- up
- vagrant --fixture=monitoring -- ssh test-runner -- -tt "pip3 install /vagrant/build/clmcservice-SNAPSHOT.tar.gz"
- vagrant --fixture=monitoring -- ssh test-runner -- -tt "pytest -s --pyargs clmctest.monitoring"
- vagrant --fixture=monitoring -- ssh test-runner -- -tt "pytest -s --pyargs clmcservice.tests"
- vagrant --fixture=inputs -- up
- vagrant --fixture=inputs -- ssh test-runner -- -tt "pytest -s --pyargs clmctest.inputs"
script:
- echo "REPO_USER=${REPO_USER}" > $CI_PROJECT_DIR/reporc
- echo "REPO_PASS=${REPO_PASS}" >> $CI_PROJECT_DIR/reporc
- sudo scripts/test/fixture.sh create -f src/test/clmctest/rspec.json -r $CI_PROJECT_DIR
- sudo mkdir /var/lib/lxc/test-runner/rootfs/vagrant/build
- sudo cp build/clmctest-SNAPSHOT.tar.gz /var/lib/lxc/test-runner/rootfs/vagrant/build
- sudo cp build/clmcservice-SNAPSHOT.tar.gz /var/lib/lxc/test-runner/rootfs/vagrant/build
- sudo lxc-attach -n test-runner -- pip3 install /vagrant/build/clmctest-SNAPSHOT.tar.gz
- sudo lxc-attach -n test-runner -- pip3 install /vagrant/build/clmcservice-SNAPSHOT.tar.gz
- sudo lxc-attach -n test-runner -- pytest -s --pyargs clmctest.scripts
- sudo lxc-attach -n test-runner -- pytest -s --pyargs clmcservice.tests
- sudo lxc-attach -n test-runner -- pytest -s --pyargs clmctest.inputs
- sudo lxc-attach -n test-runner -- pytest -s --pyargs clmctest.monitoring
when: on_success
clean:
......@@ -63,5 +65,5 @@ clean:
only:
- schedules
script:
- python scripts/test/deleteallvms.py
when: always
\ No newline at end of file
- sudo scripts/test/fixture.sh destroy -f src/test/clmctest/rspec.json
when: always
......@@ -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
Attach to the test-runner
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 to run the tests
`lxc-attach -n test-runner`
......@@ -96,3 +110,25 @@ The following modules are integration tests
pytest -s --pyargs clmctest.inputs
pytest -s --pyargs clmctest.monitoring
```
#### CI Testing
A vagrant VM is setup on givry in the directory `/home/mjb/flame-clmc`
The VM is started using a libvirt vagrant file through the following command:
`VAGRANT_VAGRANTFILE=Vagrantfile.libvirt vagrant up`
The VM has gitlab-runner installed::
```
VAGRANT_VAGRANTFILE=Vagrantfile.libvirt vagrant up
VAGRANT_VAGRANTFILE=Vagrantfile.libvirt vagrant ssh -- -tt "sudo /vagrant/scripts/test/install-git-runner.sh"
```
Runners can be installed on developers virtualbox VMs if necessary, in that case you can just use
```
vagrant up
vagrant ssh -- -tt "sudo /vagrant/scripts/test/install-git-runner.sh"
```
\ No newline at end of file
$lxc_script = <<-SCRIPT
apt-get update
apt-get install lxc lxc-templates wget bridge-utils jq -y
lxc-checkconfig
touch /etc/lxc/dnsmasq.conf
sed -i s/10.0.3/172.40.231/g /etc/default/lxc-net
sed -i s/#LXC_DHCP_CONFILE/LXC_DHCP_CONFILE/g /etc/default/lxc-net
service lxc-net restart
SCRIPT
Vagrant.configure("2") do |config|
config.vm.box = "yk0/ubuntu-xenial"
config.vm.provider :libvirt do |domain|
domain.memory = 8192
domain.cpus = 4
end
# Install lxc
config.vm.provision :shell, inline: $lxc_script
end
REPO_USER=itinnov.flame.integration
REPO_PASS=1tc3ntr3
\ No newline at end of file
......@@ -95,9 +95,6 @@ systemctl start chronograf
## CLMC-SERVICE
## ----------------------------------------------------------------------------------
echo "----> Configuring virtualenvwrapper"
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
......@@ -154,15 +151,33 @@ fi
echo "----> Creating CLMC web service log directory"
sudo mkdir /var/log/clmcservice
# 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
......
#!/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
#!/bin/bash
repo_root="/vagrant"
rspec_file=$repo_root"/src/test/clmctest/rspec.json"
\ No newline at end of file
#!/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
#!/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
#!/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
......@@ -21,7 +23,7 @@ for service_name in $service_names; do
# copy flame clmc files into the root container
echo "Copying files to rootfs"
container_dir="/var/lib/lxc/"${service_name}"/rootfs"
container_vagrant_dir=${container_dir}"${repo_root}"
container_vagrant_dir=${container_dir}"/vagrant"
mkdir -p ${container_vagrant_dir}
cp -f ${repo_root}/reporc "${container_vagrant_dir}"
cp -rf ${repo_root}/scripts ${container_vagrant_dir}
......@@ -41,11 +43,11 @@ for service_name in $service_names; do
influxdb_url=$(echo $SERVICE | jq -r '.influxdb_url')
database_name=$(echo $SERVICE | jq -r '.database_name')
report_period=$(echo $SERVICE | jq -r '.report_period')
cmd="${repo_root}/scripts/clmc-service/install.sh ${influxdb_url} ${database_name} ${report_period}"
lxc-attach -n ${service_name} -v REPO_ROOT=${repo_root} -- ${cmd}
cmd="/vagrant/scripts/clmc-service/install.sh ${influxdb_url} ${database_name} ${report_period}"
lxc-attach -n ${service_name} -v REPO_ROOT="/vagrant" -- ${cmd}
elif [ ${service_name} == "test-runner" ]
then
cmd=${repo_root}/src/test/clmctest/services/pytest/install.sh
cmd=/vagrant/src/test/clmctest/services/pytest/install.sh
lxc-attach -n ${service_name} -- ${cmd}
else
# get container parameters
......@@ -60,12 +62,12 @@ for service_name in $service_names; do
database_name=$(echo $SERVICE | jq -r '.database_name')
# install service function specific software
cmd=${repo_root}/src/test/clmctest/services/${sf_id}/install.sh
lxc-attach -n ${service_name} -v REPO_ROOT=${repo_root} -- ${cmd}
cmd=/vagrant/src/test/clmctest/services/${sf_id}/install.sh
lxc-attach -n ${service_name} -v REPO_ROOT="/vagrant" -- ${cmd}
# install telegraf
cmd=${repo_root}/scripts/clmc-agent/install.sh
lxc-attach -n ${service_name} -v REPO_ROOT=${repo_root} -- ${cmd}
cmd=/vagrant/scripts/clmc-agent/install.sh
lxc-attach -n ${service_name} -v REPO_ROOT="/vagrant" -- ${cmd}
# copy telegraf configuration templates
cp -f ${repo_root}/scripts/clmc-agent/telegraf.conf ${container_dir}/etc/telegraf/
......@@ -74,19 +76,101 @@ for service_name in $service_names; do
# replace telegraf template with container parameters
# @todo do we really need both scripts to do this?
cmd=${repo_root}/scripts/clmc-agent/configure_template.sh
cmd=/vagrant/scripts/clmc-agent/configure_template.sh
lxc-attach -n ${service_name} -- ${cmd}
cmd="${repo_root}/scripts/clmc-agent/configure.sh ${location} ${sfc_id} ${sfc_id_instance} ${sf_id} ${sf_id_instance} ${ipendpoint_id} ${sr_id} ${influxdb_url} ${database_name}"
cmd="/vagrant/scripts/clmc-agent/configure.sh ${location} ${sfc_id} ${sfc_id_instance} ${sf_id} ${sf_id_instance} ${ipendpoint_id} ${sr_id} ${influxdb_url} ${database_name}"
lxc-attach -n ${service_name} -- ${cmd}
# start telegraf
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
#!/bin/bash
apt-get update
wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
chmod +x /usr/local/bin/gitlab-runner
useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
echo "gitlab-runner ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
gitlab-runner start
gitlab-runner register -n --url https://gitlab.it-innovation.soton.ac.uk/ --r sN3wMQp8EiAv7znNwG5s --executor shell --locked true --name ${HOSTNAME} --description ${HOSTNAME} --run-untagged true
apt-get -y install python3 python3-pip python-influxdb
update-alternatives --install /usr/bin/python python /usr/bin/python3 10
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