From c69b67fadd20591ee9195a111aad66cefbb2ee32 Mon Sep 17 00:00:00 2001 From: Simon Crowle <sgc@it-innovation.soton.ac.uk> Date: Thu, 22 Mar 2018 16:02:27 +0000 Subject: [PATCH] Adds simple media component service state test * Creates an measurement table called mediaComponentConfig * Simulates 'stopped' and 'running' states for Apache endpoints in simulator * Creates a pytest case in which configuration state changes are queried --- test/streaming-sim/LineProtocolGenerator.py | 13 ++++++ test/streaming-sim/StreamingSim.py | 51 +++++++++++++++++++++ test/streaming-sim/test_MC_Config.py | 38 +++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 test/streaming-sim/test_MC_Config.py diff --git a/test/streaming-sim/LineProtocolGenerator.py b/test/streaming-sim/LineProtocolGenerator.py index 1b19c3c..a420b6b 100644 --- a/test/streaming-sim/LineProtocolGenerator.py +++ b/test/streaming-sim/LineProtocolGenerator.py @@ -94,6 +94,19 @@ def _getNSTime(time): return timestamp +def generate_mc_serviceConfig( mcLabel, sStop, asStop, sStart, asStart, time ): + result = [{ "measurement" : "mediaComponentConfig", + "tags" : { "mediaComp" : mcLabel }, + "fields" : + { "serviceStopped" : sStop, + "avgServiceStopped" : asStop, + "serviceStarted" : sStart, + "avgServiceStarted" : asStart + }, + "time" : _getNSTime(time) }] + + return result + # DEPRECATED # ____________________________________________________________________________ diff --git a/test/streaming-sim/StreamingSim.py b/test/streaming-sim/StreamingSim.py index cb66ccb..4ddde6c 100644 --- a/test/streaming-sim/StreamingSim.py +++ b/test/streaming-sim/StreamingSim.py @@ -223,6 +223,8 @@ class Sim(object): return delay_time +## PYTEST FIXTURES START +## ------------------------------------------------------------------------------------------------------ @pytest.fixture(scope='module') def run_simulation_fixture(streaming_sim_config): @@ -254,6 +256,55 @@ def run_simulation_fixture(streaming_sim_config): import time time.sleep(10) +### Media Component Configuration fixtures +""" +Line Protocol report format: + +mediaComponentConfig <global tags>,<mediaComp> <configState1=milliseconds>,<configState2=milliseconds> time +""" + +@pytest.fixture(scope='module') +def reportMC_ServiceState(streaming_sim_config): + """ + Report to determine whether the simulated streaming servers on the endpoints is running. + """ + + # IPEndpoint 1 scenario + # 10 second period: Stopped --> started --> stopped --> started + # Stopped state: 1000 + 500 = 1500 [avg = 750] + # Started state: 3000 + 5500 = 8500 [avg = 4250] + + epURL = streaming_sim_config['hosts'][1]['ip_address'] + idbc = InfluxDBClient( host=epURL, port=8186, database=INFLUX_DB_NAME, timeout=10 ) + + idbc.write_points( lp.generate_mc_serviceConfig( "apache", 1500, 750, 8500, 4250, 0) ) + + # IPEndpoint 2 scenario + # 10 second period: Stopped --> started --> stopped --> started + # Stopped state: 250 + 250 = 500 [avg = 250] + # Started state: 3500 + 6000 = 9500 [avg = 4750] + + epURL = streaming_sim_config['hosts'][2]['ip_address'] + idbc = InfluxDBClient( host=epURL, port=8186, database=INFLUX_DB_NAME, timeout=10 ) + + idbc.write_points( lp.generate_mc_serviceConfig( "apache", 250, 250, 9500, 4750, 0) ) + +@pytest.fixture(scope='module') +def reportMC_ConfigFileState(streaming_sim_config): + """ + Report to determine whether the simulated streaming servers configuration on the endpoints is correct + """ + +@pytest.fixture(scope='module') +def reportMC_APIStatus(streaming_sim_config): + """ + Report to determine whether the simulated streaming servers API status call returns good + """ + + +## ------------------------------------------------------------------------------------------------------ +## PYTEST FIXTURES END + def run_simulation(generate=True): """ diff --git a/test/streaming-sim/test_MC_Config.py b/test/streaming-sim/test_MC_Config.py new file mode 100644 index 0000000..4497be6 --- /dev/null +++ b/test/streaming-sim/test_MC_Config.py @@ -0,0 +1,38 @@ +#!/usr/bin/python3 + +import pytest +from StreamingSim import reportMC_ServiceState + +class TestMediaComponentConfig( object ): + """ + Test class to check the reported output of a media component's configuration test + as it is reported to the CLMC + """ + + # For data sent to INFLUX, see reportMC_ServiceState function in StreamingSim.py + + @pytest.mark.parametrize( "query, expectedResult", [ + ('SELECT "serviceStopped", "avgServiceStopped", "serviceStarted", "avgServiceStarted" FROM "CLMCMetrics"."autogen"."mediaComponentConfig" WHERE ipendpoint=\'adaptive_streaming_I1_apache1\'', + {"time" : "1970-01-01T00:00:00Z", "serviceStopped" : 1500, "avgServiceStopped" : 750, "serviceStarted" : 8500, "avgServiceStarted" : 4250}), + ('SELECT "serviceStopped", "avgServiceStopped", "serviceStarted", "avgServiceStarted" FROM "CLMCMetrics"."autogen"."mediaComponentConfig" WHERE ipendpoint=\'adaptive_streaming_I1_apache2\'', + {"time" : "1970-01-01T00:00:00Z", "serviceStopped" : 250, "avgServiceStopped" : 250, "serviceStarted" : 9500, "avgServiceStarted" : 4750}) + ]) + + def test_serviceStateReport( self, query, expectedResult, get_db_client, reportMC_ServiceState ): + """ + :param query: the LineProtocol query to search for MC service state report + :param expectedResult: the JSON result obtained from the query + :param get_db_client: fixture from conftest.py returning INFLUX query client + :param reportMC_ServiceState: the fixture that makes the service state report + """ + print( "\n" ) # White space for output + + # Query for result and report problems with query if necessary + queryResult = get_db_client.query( query, raise_errors = False ) + assert queryResult.error is None, "An error occurred executing query {0}." + + # Get result and evaluate + actualResult = next( queryResult.get_points() ) + + assert expectedResult == actualResult, "FAIL" #self.outputComparison( expectedResult, actualResult ) + print ("Media Component service state test succeeded: {0}".format( query )) -- GitLab