Skip to content
Snippets Groups Projects
Commit c69b67fa authored by Simon Crowle's avatar Simon Crowle
Browse files

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
parent 7bfdf2df
No related branches found
No related tags found
No related merge requests found
......@@ -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
# ____________________________________________________________________________
......
......@@ -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):
"""
......
#!/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 ))
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