From 3709d6d70add83644ba4f012225be959770d4011 Mon Sep 17 00:00:00 2001 From: MJB <mjb@it-innovation.soton.ac.uk> Date: Mon, 26 Mar 2018 20:42:06 +0100 Subject: [PATCH] optimising speed of tests so they reuse VMs --- .gitlab-ci.yml | 46 +++++++++----------------- clmctest/inputs/conftest.py | 11 ++++-- clmctest/inputs/rspec.yml | 8 ++--- clmctest/monitoring/conftest.py | 8 +++-- clmctest/monitoring/test_simresults.py | 6 ++-- clmctest/scripts/rspec.yml | 2 +- 6 files changed, 37 insertions(+), 44 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 852c415..2cfe47b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,41 +1,25 @@ stages: - build - - test:scripts - - test:monitoring - - test:inputs + - test + +build:tests: + stage: build + script: + - python setup.py sdist --dist-dir=build -build: - - stage: build - - python setup.py sdist --dist-dir=build - -test:scripts: - stage: test:scripts +test: + stage: test script: - vagrant --fixture=scripts -- up - vagrant --fixture=scripts -- ssh test-runner -- -tt "cd /vagrant && pytest clmctest/scripts/" - after_script: - - vagrant --fixture=scripts -- destroy --force - when: on_success - -test:monitoring: - stage: test:monitoring - script: - vagrant --fixture=monitoring -- up - - vagrant --fixture=monitoring -- ssh test-runner -- -tt "cd /vagrant && pytest clmctest/monitoring/" - after_script: - - vagrant --fixture=monitoring -- destroy --force - when: on_success - -test:inputs: - stage: test:inputs - script: + - vagrant --fixture=monitoring -- ssh test-runner -- -tt "cd /vagrant && pytest clmctest/monitoring/" - vagrant --fixture=inputs -- up - - vagrant --fixture=inputs -- ssh test-runner -- -tt "cd /vagrant && pytest clmctest/inputs/" + - vagrant --fixture=inputs -- ssh test-runner -- -tt "cd /vagrant && pytest clmctest/inputs/" after_script: - - vagrant --fixture=inputs -- destroy --force - when: on_success - - - - + - vagrant --fixture=inputs -- destroy --force + - vagrant --fixture=monitoring -- destroy --force + - vagrant --fixture=scripts -- destroy --force + when: on_success + \ No newline at end of file diff --git a/clmctest/inputs/conftest.py b/clmctest/inputs/conftest.py index 0a1be8f..a70a257 100644 --- a/clmctest/inputs/conftest.py +++ b/clmctest/inputs/conftest.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 import pytest +import time import yaml import pkg_resources from influxdb import InfluxDBClient @@ -24,11 +25,17 @@ def telegraf_agent_config(request): @pytest.fixture(params=[{'database': 'CLMCMetrics'}], scope='module') def influxdb(telegraf_agent_config, request): """ - Creates an Influx DB client for the CLMC metrics database + Creates an Influx DB client for the CLMC metrics database with an empty database :param telegraf_agent_config: the fixture returning the yaml configuration :param request: access the parameters of the fixture :return: the created Influx DB client """ + + db = InfluxDBClient(host=telegraf_agent_config['hosts'][0]['ip_address'], port=8086, database=request.param['database'], timeout=10) + db.drop_database(request.param['database']) - return InfluxDBClient(host=telegraf_agent_config['hosts'][0]['ip_address'], port=8086, database=request.param['database'], timeout=10) + # wait 10 seconds for the 1st measurement to arrive from agents before returning + time.sleep(15) + + return db diff --git a/clmctest/inputs/rspec.yml b/clmctest/inputs/rspec.yml index b64c146..a7ace28 100644 --- a/clmctest/inputs/rspec.yml +++ b/clmctest/inputs/rspec.yml @@ -35,7 +35,7 @@ hosts: service_name: "nginx" forward_ports: - guest: 80 - host: 8082 + host: 8882 ip_address: "203.0.113.102" location: "DC1" sfc_id: "MS_Template_1" @@ -52,7 +52,7 @@ hosts: service_name: "mongo" forward_ports: - guest: 80 - host: 8083 + host: 8883 ip_address: "203.0.113.103" location: "DC1" sfc_id: "MS_Template_1" @@ -69,7 +69,7 @@ hosts: service_name: "ffmpeg" forward_ports: - guest: 80 - host: 8084 + host: 8884 ip_address: "203.0.113.104" location: "DC1" sfc_id: "MS_Template_1" @@ -86,7 +86,7 @@ hosts: service_name: "host" forward_ports: - guest: 80 - host: 8085 + host: 8885 ip_address: "203.0.113.105" location: "DC1" sfc_id: "MS_Template_1" diff --git a/clmctest/monitoring/conftest.py b/clmctest/monitoring/conftest.py index 828b68c..0396152 100644 --- a/clmctest/monitoring/conftest.py +++ b/clmctest/monitoring/conftest.py @@ -23,7 +23,7 @@ def streaming_sim_config(): @pytest.fixture(params=[{'database': 'CLMCMetrics'}], scope='module') -def get_db_client(streaming_sim_config, request): +def influxdb(streaming_sim_config, request): """ Creates an Influx DB client for the CLMC metrics database @@ -32,5 +32,7 @@ def get_db_client(streaming_sim_config, request): :return: the created Influx DB client """ - return InfluxDBClient(host=streaming_sim_config['hosts'][0]['ip_address'], port=8086, database=request.param['database'], timeout=10) - + db = InfluxDBClient(host=streaming_sim_config['hosts'][0]['ip_address'], port=8086, database=request.param['database'], timeout=10) + db.drop_database(request.param['database']) + + return db diff --git a/clmctest/monitoring/test_simresults.py b/clmctest/monitoring/test_simresults.py index 7940fc3..6940560 100644 --- a/clmctest/monitoring/test_simresults.py +++ b/clmctest/monitoring/test_simresults.py @@ -21,13 +21,13 @@ class TestSimulation(object): ('SELECT count(*) FROM "CLMCMetrics"."autogen"."vm_res_alloc"', {"time": "1970-01-01T00:00:00Z", "count_cpu": 12, "count_memory": 12, "count_storage": 12}) ]) - def test_simulation(self, query, expected_result, get_db_client, run_simulation_fixture): + def test_simulation(self, query, expected_result, influxdb, run_simulation_fixture): """ This is the entry point of the test. This method will be found and executed when the module is ran using pytest :param query: the query to execute (value obtained from the pytest parameter decorator) :param expected_result: the result expected from executing the query (value obtained from the pytest parameter decorator) - :param get_db_client the import db client fixture - imported from contest.py + :param influxdb the import db client fixture - imported from contest.py :param run_simulation_fixture: the imported fixture to use to generate the testing data - the return value of the fixture is not needed in this case """ @@ -36,7 +36,7 @@ class TestSimulation(object): print("\n") # prints a blank line for formatting purposes # the raise_errors=False argument is given so that we could actually test that the DB didn't return any errors instead of raising an exception - query_result = get_db_client.query(query, raise_errors=False) + query_result = influxdb.query(query, raise_errors=False) # test the error attribute of the result is None, that is no error is returned from executing the DB query assert query_result.error is None, "An error was encountered while executing query {0}.".format(query) diff --git a/clmctest/scripts/rspec.yml b/clmctest/scripts/rspec.yml index 17f1d31..0de15c5 100644 --- a/clmctest/scripts/rspec.yml +++ b/clmctest/scripts/rspec.yml @@ -3,5 +3,5 @@ hosts: cpus: 1 memory: 2048 disk: "10GB" - ip_address: "200.0.113.150" + ip_address: "203.0.113.150" \ No newline at end of file -- GitLab