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

Adding tests for uncofigured state of the aggregator

parent 87940c3f
No related branches found
No related tags found
No related merge requests found
......@@ -59,6 +59,20 @@ class TestAggregatorAPI(object):
from clmcservice.aggregationapi.views import AggregatorConfig # nested import so that importing the class view is part of the test itself
setup_config = self.registry.get_settings()[CONF_OBJECT]
# test an error is thrown when aggregator is in unconfigured state
self.registry.get_settings()[CONF_OBJECT] = None
request = testing.DummyRequest()
error_raised = False
try:
AggregatorConfig(request).get()
except HTTPBadRequest:
error_raised = True
assert error_raised, "Error must be raised in case of a not configured aggregator."
self.registry.get_settings()[CONF_OBJECT] = setup_config
# test GET method when aggregator is configured
assert int(self.registry.get_settings()[CONF_OBJECT][AGGREGATOR_CONFIG_SECTION].get('aggregator_report_period')) == 5, "Initial report period is 5 seconds."
assert self.registry.get_settings()[CONF_OBJECT][AGGREGATOR_CONFIG_SECTION].get('aggregator_database_name') == 'CLMCMetrics', "Initial database name the aggregator uses is CLMCMetrics."
assert self.registry.get_settings()[CONF_OBJECT][AGGREGATOR_CONFIG_SECTION].get('aggregator_database_url') == "http://172.40.231.51:8086", "Initial aggregator url is http://172.40.231.51:8086"
......@@ -149,6 +163,21 @@ class TestAggregatorAPI(object):
assert not AggregatorController.is_process_running(self.registry.get_settings().get(PROCESS_ATTRIBUTE)), "Initially aggregator is not running."
assert self.registry.get_settings().get(PROCESS_ATTRIBUTE) is None, "Initially no aggregator process is running."
# test starting the aggregator when in unconfigured state
setup_config = self.registry.get_settings()[CONF_OBJECT]
self.registry.get_settings()[CONF_OBJECT] = None
request = testing.DummyRequest()
input_body = '{"action": "start"}'
request.body = input_body.encode(request.charset)
error_raised = False
try:
AggregatorController(request).put()
except HTTPBadRequest:
error_raised = True
assert error_raised, "Error must be raised in case of a not configured aggregator."
self.registry.get_settings()[CONF_OBJECT] = setup_config
# test starting the aggregation when in configured state
request = testing.DummyRequest()
input_body = '{"action": "start"}'
request.body = input_body.encode(request.charset)
......@@ -172,6 +201,21 @@ class TestAggregatorAPI(object):
assert not AggregatorController.is_process_running(self.registry.get_settings().get(PROCESS_ATTRIBUTE)), "Initially aggregator is not running."
assert self.registry.get_settings().get(PROCESS_ATTRIBUTE) is None, "Initially no aggregator process is running."
# test stopping the aggregator when in unconfigured state
setup_config = self.registry.get_settings()[CONF_OBJECT]
self.registry.get_settings()[CONF_OBJECT] = None
request = testing.DummyRequest()
input_body = '{"action": "stop"}'
request.body = input_body.encode(request.charset)
error_raised = False
try:
AggregatorController(request).put()
except HTTPBadRequest:
error_raised = True
assert error_raised, "Error must be raised in case of a not configured aggregator."
self.registry.get_settings()[CONF_OBJECT] = setup_config
# test stopping the aggregation when in configured state
# send a start request to trigger the aggregator
request = testing.DummyRequest()
input_body = '{"action": "start"}'
......@@ -212,6 +256,21 @@ class TestAggregatorAPI(object):
assert not AggregatorController.is_process_running(self.registry.get_settings().get(PROCESS_ATTRIBUTE)), "Initially aggregator is not running."
assert self.registry.get_settings().get(PROCESS_ATTRIBUTE) is None, "Initially no aggregator process is running."
# test restarting the aggregator when in unconfigured state
setup_config = self.registry.get_settings()[CONF_OBJECT]
self.registry.get_settings()[CONF_OBJECT] = None
request = testing.DummyRequest()
input_body = '{"action": "restart"}'
request.body = input_body.encode(request.charset)
error_raised = False
try:
AggregatorController(request).put()
except HTTPBadRequest:
error_raised = True
assert error_raised, "Error must be raised in case of a not configured aggregator."
self.registry.get_settings()[CONF_OBJECT] = setup_config
# test restarting the aggregation when in configured state
# test restarting the aggregator process when it is stopped
request = testing.DummyRequest()
input_body = '{"action": "restart"}'
......
......@@ -349,41 +349,3 @@ class RoundTripTimeQuery(object):
reverse_data_delay = (8/10**6) * (response_size / bandwidth) * (packet_size / (packet_size - packet_header_size))
return forward_latency + forward_data_delay + service_delay + reverse_latency + reverse_data_delay
@view_defaults(route_name='sfemc_config', renderer='json')
class SFEMCMockConfig(object):
"""
A class-based view for accessing and mutating the configuration of the aggregator.
"""
def __init__(self, request):
"""
Initialises the instance of the view with the request argument.
:param request: client's call request
"""
self.request = request
def get(self):
"""
A GET API call for endpoint configuration.
:return: A JSON response with the configuration of the aggregator.
"""
log.debug("\Getting endpoint configuration\n")
config = {"key": "hello"}
return config
def put(self):
"""
A PUT API call for the status of the aggregator.
:return: A JSON response to the PUT call - essentially with the new configured data and comment of the state of the aggregator
:raises HTTPBadRequest: if request body is not a valid JSON for the configurator
"""
log.debug("\Putting endpoint configuration\n")
import pytest
from pyramid import testing
from pyramid.httpexceptions import HTTPBadRequest
from time import sleep
from clmcservice.utilities import CONFIG_ATTRIBUTES, PROCESS_ATTRIBUTE, RUNNING_FLAG, MALFORMED_FLAG, URL_REGEX
import os
import signal
class TestSFEMCMockAPI(object):
@pytest.fixture(autouse=True)
def app_config(self):
print("app_config")
self.config = testing.setUp()
# endpoint
# sr
# sfc_i
# sf_i
self.config.add_settings({
'my_endpoint_1': {'sfc_i': 'my_sfc_i_1', 'sf_i': 'my_sf_i_1', 'sr': 'my_sr_1'},
'my_endpoint_2': {'sfc_i': 'my_sfc_i_2', 'sf_i': 'my_sf_i_2', 'sr': 'my_sr_2'}})
yield
testing.tearDown()
def test_GET_config(self):
print("Test get")
# nested import so that importing the class view is part of the test itself
from clmcservice.views import SFEMCMockConfig
request = testing.DummyRequest()
response = SFEMCMockConfig(request).get()
print("response={0}".format(response))
@pytest.mark.parametrize("input_body, output_value", [
('{"aggregator_report_period": 10, "aggregator_database_name": "CLMCMetrics", "aggregator_database_url": "http://171.40.231.51:8086"}',
{'aggregator_report_period': 10, 'aggregator_database_name': "CLMCMetrics", 'aggregator_database_url': "http://171.40.231.51:8086"}),
])
def test_PUT_config(self, input_body, output_value):
print("Test put")
\ No newline at end of file
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