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

Merge mediaComponentConfig into endpointConfig

parents a512bb08 c5e5e6a7
No related branches found
No related tags found
No related merge requests found
......@@ -79,7 +79,7 @@ class Sim(object):
# Simulation configuration of the media component (MC) state changes
# "MC state", [average (sec), stddev]
mc_config_delay_dist = { "starting": [5, 0.68], "stopping": [2, 0.68]}
mc_config_delay_dist = { "stopped":[1, 0.68], "starting": [5, 0.68], "running":[1, 0.68], "stopping": [2, 0.68]}
print("\nSimulation started. Generating data...")
......@@ -105,7 +105,20 @@ class Sim(object):
max_delay = max(delay_time, max_delay)
sim_time += max_delay
# move mpegdash_service endpoints state through from 'starting' to 'running'
# move mpegdash_service media component state from 'stopped' to 'starting'
max_delay = 0
for ip_endpoint in ip_endpoints:
agent_url = urllib.parse.urlparse(ip_endpoint["agent_url"])
agent_db_client = InfluxDBClient(host=agent_url.hostname, port=agent_url.port, database=self.influx_db_name, timeout=10)
delay_avg = mc_config_delay_dist['stopped'][0]
delay_std = delay_avg * mc_config_delay_dist['stopped'][1]
delay_time = self._changeMCState(agent_db_client, sim_time, "mpegdash_service_config", delay_avg, delay_std, 0.7, 'stopped', 'starting')
max_delay = max(delay_time, max_delay)
sim_time += max_delay
# move mpegdash_service media component state from 'starting' to 'running'
max_delay = 0
for ip_endpoint in ip_endpoints:
agent_url = urllib.parse.urlparse(ip_endpoint["agent_url"])
......@@ -193,7 +206,7 @@ class Sim(object):
# remove requests processed off the queue
ip_endpoint['request_queue'] -= int(requests_processed)
# update media component state (continuously 'running')
# update mpegdash_service media component state (continuously 'running')
state_stats = {}
state_stats['running'] = float(TICK_TIME)
state_stats['avg_running'] = float(TICK_TIME)
......@@ -210,11 +223,24 @@ class Sim(object):
agent_db_client = InfluxDBClient(host=agent_url.hostname, port=agent_url.port, database=self.influx_db_name, timeout=10)
delay_time = self._changeVMState(agent_db_client, sim_time, ip_endpoint, config_delay_dist['placing'][0],
config_delay_dist['unplaced'][0] * config_delay_dist['unplaced'][1], 0.25,
'placed', 'unplaced') # NOTE: Is 'placed' a transition state ?
'placed', 'unplaced')
max_delay = max(delay_time, max_delay)
sim_time += max_delay
# move mpegdash_service endpoints state through from 'running' to 'stopped'
# move mpegdash_service media component state from 'running' to 'stopping'
max_delay = 0
for ip_endpoint in ip_endpoints:
agent_url = urllib.parse.urlparse(ip_endpoint["agent_url"])
agent_db_client = InfluxDBClient(host=agent_url.hostname, port=agent_url.port, database=self.influx_db_name, timeout=10)
delay_avg = mc_config_delay_dist['running'][0]
delay_std = delay_avg * mc_config_delay_dist['running'][1]
delay_time = self._changeMCState(agent_db_client, sim_time, "mpegdash_service_config", delay_avg, delay_std, 0.7, 'running', 'stopping')
max_delay = max(delay_time, max_delay)
sim_time += max_delay
# move mpegdash_service media component state from 'stopping' to 'stopped'
max_delay = 0
for ip_endpoint in ip_endpoints:
agent_url = urllib.parse.urlparse(ip_endpoint["agent_url"])
......@@ -294,9 +320,9 @@ class Sim(object):
"""
# Calculate a randomized total time for the transition (and calculate relative ratios of time in transition and next state)
total_delay_time = random.normalvariate(mu, sigma)
transition_time = total_delay_time * trans_ratio
next_state_time = total_delay_time - transition_time
total_delay_time = max( random.normalvariate(mu, sigma), 1 ) # minimum total delay is 1 second
transition_time = total_delay_time * trans_ratio
next_state_time = total_delay_time - transition_time
mc_states = {}
......
......@@ -22,25 +22,8 @@ def streaming_sim_config():
return data_loaded
@pytest.fixture(scope="module")
def streaming_sim_params(streaming_sim_config):
"""
Uses attributes from the local streaming_sim_config and creates a dictionary of simulation parameters
"""
sim_params = {}
sim_params["INFLUX_DB_URL"] = "http://" + streaming_sim_config['hosts'][0]['ip_address'] + ":8086"
sim_params["INFLUX_DB_NAME"] = streaming_sim_config['hosts'][1]['database_name'] # Note: could this be specified in the clmc-service instead?
sim_params["AGENT1_URL"] = "http://" + streaming_sim_config['hosts'][1]['ip_address'] + ":8186"
sim_params["AGENT2_URL"] = "http://" + streaming_sim_config['hosts'][2]['ip_address'] + ":8186"
sim_params["SIMULATION_TIME_SEC"] = 60 * 60
return sim_params
@pytest.fixture(params=[{'database': 'CLMCMetrics'}], scope='module')
def get_db_client(streaming_sim_config, request):
def influx_db(streaming_sim_config, request):
"""
Creates an Influx DB client for the CLMC metrics database
......@@ -49,25 +32,22 @@ 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)
return InfluxDBClient(host=streaming_sim_config['hosts'][0]['ip_address'], port='8086', database=request.param['database'], timeout=10)
@pytest.fixture(scope='module')
def run_simulation_fixture(streaming_sim_params):
"""
A fixture, which checks if the the DB has been created, if not it runs the simulator with a 10 seconds timeout after that
"""
@pytest.fixture(scope="module")
def simulator( streaming_sim_config ):
influx_url = "http://" + streaming_sim_config['hosts'][0]['ip_address'] + ":8086"
influx_db_name = streaming_sim_config['hosts'][1]['database_name']
agent1_url = "http://" + streaming_sim_config['hosts'][1]['ip_address'] + ":8186"
agent2_url = "http://" + streaming_sim_config['hosts'][2]['ip_address'] + ":8186"
simulator = Sim( influx_url, influx_db_name, agent1_url, agent2_url )
simulator = Sim( streaming_sim_params['INFLUX_DB_URL'], streaming_sim_params['INFLUX_DB_NAME'], streaming_sim_params['AGENT1_URL'], streaming_sim_params['AGENT2_URL'])
dbs = simulator.db_client.get_list_database()
dbs = [db.get("name") for db in dbs]
# This check needed to be disabled as the CLMCMetrics database is always created when
# the test starts, irrespective of whether this is the 1st time or not
# if INFLUX_DB_NAME not in dbs:
simulator.reset()
simulator.run(streaming_sim_params['SIMULATION_TIME_SEC'])
print("10 seconds timeout is given so that the data could properly be inserted into the database.")
import time
time.sleep(10)
return simulator
\ No newline at end of file
#!/usr/bin/python3
import pytest
import time
class TestSimulation(object):
"""
A testing class used to group all the tests related to the simulation data
"""
@pytest.fixture(scope='class')
def run_simulator( self, simulator ):
simulator.run( 3600 )
print( "Waiting for INFLUX to finish receiving simulation data..." )
time.sleep( 10 ) # wait for data to finish arriving at the INFLUX database
@pytest.mark.parametrize("query, expected_result", [
('SELECT count(*) FROM "CLMCMetrics"."autogen"."cpu_usage"',
......@@ -26,26 +33,26 @@ class TestSimulation(object):
"count_avg_booted": 4, "count_connecting": 4, "count_avg_connecting": 4, "count_connected": 4, "count_avg_connected": 4, "count_cpus": 4, "count_memory": 4, "count_storage": 4}),
('SELECT count(*) FROM "CLMCMetrics"."autogen"."mpegdash_service_config" WHERE ipendpoint=\'adaptive_streaming_I1_apache1\'',
{"time": "1970-01-01T00:00:00Z", "count_avg_running": 3602, "count_avg_starting": 3602, "count_avg_stopped": 3602, "count_avg_stopping": 3602, "count_running": 3602, "count_starting": 3602, "count_stopped": 3602, "count_stopping": 3602}),
{"time" : "1970-01-01T00:00:00Z", "count_avg_running" : 3604, "count_avg_starting" : 3604, "count_avg_stopped" : 3604, "count_avg_stopping" : 3604, "count_running" : 3604, "count_starting" : 3604, "count_stopped" : 3604, "count_stopping" : 3604}),
('SELECT count(*) FROM "CLMCMetrics"."autogen"."mpegdash_service_config" WHERE ipendpoint=\'adaptive_streaming_I1_apache2\'',
{"time": "1970-01-01T00:00:00Z", "count_avg_running": 3602, "count_avg_starting": 3602, "count_avg_stopped": 3602, "count_avg_stopping": 3602, "count_running": 3602, "count_starting": 3602, "count_stopped": 3602, "count_stopping": 3602}),
{"time" : "1970-01-01T00:00:00Z", "count_avg_running" : 3604, "count_avg_starting" : 3604, "count_avg_stopped" : 3604, "count_avg_stopping" : 3604, "count_running" : 3604, "count_starting" : 3604, "count_stopped" : 3604, "count_stopping" : 3604}),
])
def test_simulation(self, query, expected_result, get_db_client, run_simulation_fixture):
def test_simulation( self, run_simulator, influx_db, query, expected_result ):
"""
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 influx_db 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
"""
# pytest automatically goes through all queries under test, declared in the parameters decorator
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 = influx_db.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)
......
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