Skip to content
Snippets Groups Projects
Commit 52c998da authored by Stephen C Phillips's avatar Stephen C Phillips
Browse files

Ensure that the fixture script fails if any part of the installation or tests fail.

parent 8eb66c56
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@
// © University of Southampton IT Innovation Centre, 2017
//
// Copyright in this software belongs to University of Southampton
// IT Innovation Centre of Gamma House, Enterprise Road,
// 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
......@@ -28,7 +28,7 @@
#### Authors
|Authors|Organisation|
|Authors|Organisation|
|-|-|
|[Michael Boniface](mailto:mjb@it-innovation.soton.ac.uk)|[University of Southampton, IT Innovation Centre](http://www.it-innovation.soton.ac.uk)|
|[Simon Crowle](mailto:sgc@it-innovation.soton.ac.uk)|[University of Southampton, IT Innovation Centre](http://www.it-innovation.soton.ac.uk)|
......@@ -37,7 +37,7 @@
#### Documentation
Implementation documentation and discussion can be found in the docs directory.
Implementation documentation and discussion can be found in the docs directory.
#### Testing
......@@ -46,69 +46,76 @@ Testing is implemented using pytest using the following convention:
* The testing environment is Vagrant/Virtualbox for a base VM with LXC is installed for specific containers.
* Tests are written in python using pytest
* Related tests are stored in a python module `src/test/clmctest/<testmodule>` to create a suite of tests. All tests are stored in files test_*.py, there can be many tests per file, and many files per module
* Tests are executed against a set of LXC containers described in `src/test/clmctest/rspec.json`.
* Tests are executed against a set of LXC containers described in `src/test/clmctest/rspec.json`.
* Tests are executed from the test-runner container on the VM using install python modules
Here's the instructions
Create a single VM with LXC installed and configured with lxcbr0 configured for the network 172.40.231.0/24
`vagrant up`
This will create a single VM with LXC installed and configured with lxcbr0 configured for the network 172.40.231.0/24
```shell
vagrant up
```
SSH into the VM
SSH into the VM:
`vagrant ssh`
```shell
vagrant ssh
```
The containers are controlled using a script called /vagrant/scripts/test/fixtures.sh
The containers are controlled using a script called `/vagrant/scripts/test/fixtures.sh`
```
Usage: fixture.sh create|start|stop|destroy [-f config_file] [-r repo_root] [-c container_name|all]"
```shell
Usage: fixture.sh create|start|stop|destroy [-f config_file] [-r repo_root] [-c container_name|all]
```
To create all the services needed for integration tests
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.
```
sudo su
/vagrant/scripts/test/fixture.sh create -f /vagrant/src/test/clmctest/rspec.json -c all
To create|start|stop|destroy specific services use the `-c` option e.g.
```shell
/vagrant/scripts/test/fixture.sh create -f /vagrant/src/test/clmctest/rspec.json -c clmc-service
```
The containers created are defined an rspec.json file, there's an example here `/vagrant/src/test/clmctest/rspec.json`
The installation of several of the services depend on accessing the Nexus binary repository (for the custom Telegraf agent). To do this, a username and password for the repository must be specified in a `reporc` file in the user's home directory, e.g.
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
```shell
REPO_USER=itinnov.flame.integration
REPO_PASS=xxxxxxx
```
To create|start|stop|destroy specific services use the -c option e.g.
Create all the services needed for integration tests:
```shell
sudo su
/vagrant/scripts/test/fixture.sh create -f /vagrant/src/test/clmctest/rspec.json -c all
```
/vagrant/scripts/test/fixture.sh create -f /vagrant/src/test/clmctest/rspec.json -c clmc-service
```
As part of the clmc-service installation, the service's unit tests have been run. The fixture script will fail if any individual service installation fails to install (or fails its tests).
Attach to the test-runner to run the tests
`lxc-attach -n test-runner`
```shell
lxc-attach -n test-runner
```
Here we need to define a make file but for now the commands are manual
Build and install the CLMC test Python module:
```
```shell
cd /vagrant/src/test
python setup.py sdist --dist-dir=../../build
cd ../../src/service
python setup.py sdist --dist-dir=../../build
pip3 install /vagrant/build/clmctest-SNAPSHOT.tar.gz
pip3 install /vagrant/build/clmcservice-SNAPSHOT.tar.gz
```
The following modules are unit tests
The following module is unit tests:
```
```shell
pytest -s --pyargs clmctest.scripts
pytest -s --pyargs clmcservice.tests
```
The following modules are integration tests
The following modules are integration tests:
```
```shell
pytest -s --pyargs clmctest.inputs
pytest -s --pyargs clmctest.monitoring
pytest -s --pyargs clmctest.monitoring
```
#### CI Testing
......@@ -119,16 +126,18 @@ 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::
The VM has gitlab-runner installed:
```
```shell
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
Runners can be installed on a developer's virtualbox VM if necessary, in that case you can just use:
```
```shell
vagrant up
vagrant ssh -- -tt "sudo /vagrant/scripts/test/install-git-runner.sh"
```
\ No newline at end of file
```
N.B. libvirt takes the VM name from the name of the folder containing the vagrantfile. To make sure that libvirt doesn't try to reuse an existing VM machine name, checkout the flame-clmc project into an alternative directory name such as `flame-clmc-username`.
\ No newline at end of file
......@@ -3,7 +3,7 @@
# Get command line parameters
if [ "$#" -ne 3 ]; then
echo "Error: illegal number of arguments: "$#
echo "Usage: install.sh INFLUX_URL DATABASE_NAME REPORT_PERIOD"
echo "Usage: install-clmc-service.sh INFLUX_URL DATABASE_NAME REPORT_PERIOD"
exit 1
fi
......
......@@ -25,7 +25,14 @@
#/////////////////////////////////////////////////////////////////////////
# Force fail on command fail (off for now as virtualenvwrapper install fails)
# set -euo pipefail
set -euo pipefail
# Get command line parameters
if [ "$#" -ne 3 ]; then
echo "Error: illegal number of arguments: "$#
echo "Usage: install.sh INFLUX_URL DATABASE_NAME REPORT_PERIOD"
exit 1
fi
# Ensure everything runs in directory of the parent script
cd `dirname $0`
......
......@@ -44,17 +44,25 @@ create() {
# provision software into each container
echo "Provisioning: ${service_name}"
if [ ${service_name} == "clmc-service" ]
then
if [ ${service_name} == "clmc-service" ]; then
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="/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
exit_code=$?
if [ $exit_code != 0 ]; then
echo "clmc-service installation failed with exit code ${exit_code}"
exit 1
fi
elif [ ${service_name} == "test-runner" ]; then
cmd=/vagrant/src/test/clmctest/services/pytest/install.sh
lxc-attach -n ${service_name} -- ${cmd}
exit_code=$?
if [ $exit_code != 0 ]; then
echo "test-runner installation failed with exit code ${exit_code}"
exit 1
fi
else
# get container parameters
location=$(echo $SERVICE | jq -r '.location')
......@@ -70,11 +78,22 @@ create() {
# install service function specific software
cmd=/vagrant/src/test/clmctest/services/${sf_id}/install.sh
lxc-attach -n ${service_name} -v REPO_ROOT="/vagrant" -- ${cmd}
exit_code=$?
if [ $exit_code != 0 ]; then
echo "${sf_id} installation failed with exit code ${exit_code}"
exit 1
fi
# install telegraf
cmd=/vagrant/scripts/clmc-agent/install.sh
lxc-attach -n ${service_name} -v REPO_ROOT="/vagrant" -- ${cmd}
# check that telegraf installed (it may not have if the reporc file was not present or Nexus server was down)
if lxc-attach -n ${service_name} -- ls /etc/telegraf |& grep 'ls: cannot access'; then
echo "Telegraf agent failed to install (check reporc?)"
exit 1
fi
# stop telegraf before changing the configs
lxc-attach -n ${service_name} -- service telegraf stop
......@@ -220,6 +239,6 @@ done
echo "------>Create iptables summary"
echo -e "\n\n------>Create iptables summary"
iptables -t nat -L -n -v
iptables-save > /etc/iptables/rules.v4
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment