diff --git a/src/service/clmcservice/__init__.py b/src/service/clmcservice/__init__.py index a3e6c20ce747d356dab68e4b8352f47c9e5ae41b..648e1d8cfe078907bf1cb8fd0063211e2445e9df 100644 --- a/src/service/clmcservice/__init__.py +++ b/src/service/clmcservice/__init__.py @@ -23,7 +23,7 @@ """ from pyramid.config import Configurator -from clmcservice.utilities import validate_conf_file, RUNNING_FLAG, MALFORMED_FLAG, CONF_FILE_ATTRIBUTE, CONF_OBJECT, AGGREGATOR_CONFIG_SECTION +from clmcservice.aggregationapi.utilities import validate_conf_file, RUNNING_FLAG, MALFORMED_FLAG, CONF_FILE_ATTRIBUTE, CONF_OBJECT, AGGREGATOR_CONFIG_SECTION def main(global_config, **settings): @@ -41,15 +41,15 @@ def main(global_config, **settings): config = Configurator(settings=settings) config.add_route('aggregator_config', '/aggregator/config') - config.add_view('clmcservice.views.AggregatorConfig', attr='get', request_method='GET') - config.add_view('clmcservice.views.AggregatorConfig', attr='put', request_method='PUT') + config.add_view('clmcservice.aggregationapi.views.AggregatorConfig', attr='get', request_method='GET') + config.add_view('clmcservice.aggregationapi.views.AggregatorConfig', attr='put', request_method='PUT') config.add_route('aggregator_controller', '/aggregator/control') - config.add_view('clmcservice.views.AggregatorController', attr='get', request_method='GET') - config.add_view('clmcservice.views.AggregatorController', attr='put', request_method='PUT') + config.add_view('clmcservice.aggregationapi.views.AggregatorController', attr='get', request_method='GET') + config.add_view('clmcservice.aggregationapi.views.AggregatorController', attr='put', request_method='PUT') config.add_route('round_trip_time_query', '/query/round-trip-time') - config.add_view('clmcservice.views.RoundTripTimeQuery', attr='get', request_method='GET') + config.add_view('clmcservice.aggregationapi.views.RoundTripTimeQuery', attr='get', request_method='GET') config.scan() return config.make_wsgi_app() diff --git a/src/service/clmcservice/aggregation/__init__.py b/src/service/clmcservice/aggregation/__init__.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..5a34cbc4b8ea26e57638bc103d88de25fc1c6494 100644 --- a/src/service/clmcservice/aggregation/__init__.py +++ b/src/service/clmcservice/aggregation/__init__.py @@ -0,0 +1,2 @@ +__all__ = ['aggregator'] + diff --git a/src/service/clmcservice/aggregation/aggregator.py b/src/service/clmcservice/aggregation/aggregator.py index f0a00d3a311b843b1dedc8e8f93227c76843af80..8b66ce8dcc7d0138ef5fa26c1b1191ae231a82b5 100644 --- a/src/service/clmcservice/aggregation/aggregator.py +++ b/src/service/clmcservice/aggregation/aggregator.py @@ -26,7 +26,7 @@ from threading import Thread, Event from influxdb import InfluxDBClient from time import time, sleep from urllib.parse import urlparse -from clmcservice.utilities import generate_e2e_delay_report +from clmcservice.aggregationapi.utilities import generate_e2e_delay_report import getopt import logging diff --git a/src/service/clmcservice/aggregation/influx_data_interface.py b/src/service/clmcservice/aggregation/influx_data_interface.py index f375469a13502a08efbf5756866aa7b2d58f1799..c6781d0c35d7d77c68932499591e9e67968c637d 100644 --- a/src/service/clmcservice/aggregation/influx_data_interface.py +++ b/src/service/clmcservice/aggregation/influx_data_interface.py @@ -23,7 +23,7 @@ """ -from clmcservice.utilities import generate_e2e_delay_report +from clmcservice.aggregationapi.utilities import generate_e2e_delay_report """ A python module which provides auxiliary functions to mimic the behaviour of an InfluxDBClient when unit testing the aggregator. diff --git a/src/service/clmcservice/aggregationapi/__init__.py b/src/service/clmcservice/aggregationapi/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..1bbd92746ed2fd3328f9239e8bd0aed8d6492fc7 --- /dev/null +++ b/src/service/clmcservice/aggregationapi/__init__.py @@ -0,0 +1 @@ +__all__ = ['utilities', 'views'] diff --git a/src/service/clmcservice/tests.py b/src/service/clmcservice/aggregationapi/tests.py similarity index 94% rename from src/service/clmcservice/tests.py rename to src/service/clmcservice/aggregationapi/tests.py index df9fccbaab53617bb44f51407f7b04343e0bd4c9..77b4282ed599bd8716bfad2593e41d27aae0a310 100644 --- a/src/service/clmcservice/tests.py +++ b/src/service/clmcservice/aggregationapi/tests.py @@ -25,7 +25,7 @@ from pyramid import testing from pyramid.httpexceptions import HTTPBadRequest from time import sleep -from clmcservice.utilities import CONF_FILE_ATTRIBUTE, CONF_OBJECT, AGGREGATOR_CONFIG_SECTION, CONFIG_ATTRIBUTES, PROCESS_ATTRIBUTE, RUNNING_FLAG, MALFORMED_FLAG, URL_REGEX +from clmcservice.aggregationapi.utilities import CONF_FILE_ATTRIBUTE, CONF_OBJECT, AGGREGATOR_CONFIG_SECTION, CONFIG_ATTRIBUTES, PROCESS_ATTRIBUTE, RUNNING_FLAG, MALFORMED_FLAG, URL_REGEX import pytest import os import signal @@ -57,7 +57,7 @@ class TestAggregatorAPI(object): Tests the GET method for the configuration of the aggregator. """ - from clmcservice.views import AggregatorConfig # nested import so that importing the class view is part of the test itself + from clmcservice.aggregationapi.views import AggregatorConfig # nested import so that importing the class view is part of the test itself 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." @@ -102,7 +102,7 @@ class TestAggregatorAPI(object): :param output_value: the expected output value, None for expecting an Exception """ - from clmcservice.views import AggregatorConfig, AggregatorController # nested import so that importing the class view is part of the test itself + from clmcservice.aggregationapi.views import AggregatorConfig, AggregatorController # nested import so that importing the class view is part of the test itself assert not AggregatorController.is_process_running(self.registry.get_settings().get(PROCESS_ATTRIBUTE)), "Initially aggregator is not running." assert int(self.registry.get_settings()[CONF_OBJECT][AGGREGATOR_CONFIG_SECTION].get('aggregator_report_period')) == 5, "Initial report period is 5 seconds." @@ -144,7 +144,7 @@ class TestAggregatorAPI(object): Tests starting the aggregator through an API call. """ - from clmcservice.views import AggregatorController # nested import so that importing the class view is part of the test itself + from clmcservice.aggregationapi.views import AggregatorController # nested import so that importing the class view is part of the test itself 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." @@ -167,7 +167,7 @@ class TestAggregatorAPI(object): Tests stopping the aggregator through an API call. """ - from clmcservice.views import AggregatorController # nested import so that importing the class view is part of the test itself + from clmcservice.aggregationapi.views import AggregatorController # nested import so that importing the class view is part of the test itself 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." @@ -207,7 +207,7 @@ class TestAggregatorAPI(object): Tests restarting the aggregator through an API call. """ - from clmcservice.views import AggregatorController # nested import so that importing the class view is part of the test itself + from clmcservice.aggregationapi.views import AggregatorController # nested import so that importing the class view is part of the test itself 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." @@ -250,7 +250,7 @@ class TestAggregatorAPI(object): Tests sending a malformed type of action to the aggregator through an API call. """ - from clmcservice.views import AggregatorController # nested import so that importing the class view is part of the test itself + from clmcservice.aggregationapi.views import AggregatorController # nested import so that importing the class view is part of the test itself 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." @@ -273,7 +273,7 @@ class TestAggregatorAPI(object): Tests the GET method for the status of the aggregator. """ - from clmcservice.views import AggregatorController # nested import so that importing the class view is part of the test itself + from clmcservice.aggregationapi.views import AggregatorController # nested import so that importing the class view is part of the test itself 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." @@ -315,7 +315,7 @@ class TestAggregatorAPI(object): Tests the behaviour of the malformed configuration flag of the aggregator when doing a sequence of API calls. """ - from clmcservice.views import AggregatorController, AggregatorConfig # nested import so that importing the class view is part of the test itself + from clmcservice.aggregationapi.views import AggregatorController, AggregatorConfig # nested import so that importing the class view is part of the test itself assert not AggregatorController.is_process_running(self.registry.get_settings().get(PROCESS_ATTRIBUTE)), "Initially aggregator is not running." assert not self.registry.get_settings().get(MALFORMED_FLAG), "Initially aggregator is not in a malformed state" @@ -391,7 +391,7 @@ class TestAggregatorAPI(object): Tests the behaviour of the service when in unconfigured state. """ - from clmcservice.views import AggregatorConfig, AggregatorController + from clmcservice.aggregationapi.views import AggregatorConfig, AggregatorController self.registry.get_settings()[CONF_OBJECT] = None # unconfigured state - conf object is None diff --git a/src/service/clmcservice/utilities.py b/src/service/clmcservice/aggregationapi/utilities.py similarity index 100% rename from src/service/clmcservice/utilities.py rename to src/service/clmcservice/aggregationapi/utilities.py diff --git a/src/service/clmcservice/views.py b/src/service/clmcservice/aggregationapi/views.py similarity index 97% rename from src/service/clmcservice/views.py rename to src/service/clmcservice/aggregationapi/views.py index 906c1c4e84a24ffaeb2e4536480e218ab28f2d64..1e8c9dbe79af5ea07653b45162dd5219a4ed0d2d 100644 --- a/src/service/clmcservice/views.py +++ b/src/service/clmcservice/aggregationapi/views.py @@ -27,7 +27,7 @@ from pyramid.httpexceptions import HTTPBadRequest, HTTPInternalServerError from influxdb import InfluxDBClient from urllib.parse import urlparse from subprocess import Popen -from clmcservice.utilities import validate_config_content, validate_action_content, validate_round_trip_query_params, \ +from clmcservice.aggregationapi.utilities import validate_config_content, validate_action_content, validate_round_trip_query_params, \ CONF_OBJECT, CONF_FILE_ATTRIBUTE, AGGREGATOR_CONFIG_SECTION, CONFIG_ATTRIBUTES, ROUND_TRIP_ATTRIBUTES, RUNNING_FLAG, PROCESS_ATTRIBUTE, MALFORMED_FLAG, COMMENT_ATTRIBUTE, COMMENT_VALUE import os import os.path @@ -215,11 +215,10 @@ class AggregatorController(object): :return: the process object of the started aggregator script """ - dir_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'aggregation') python_interpreter = sys.executable - command = [python_interpreter, 'aggregator.py', '--period', str(config.get('aggregator_report_period')), '--database', + command = [python_interpreter, '-m', 'clmcservice.aggregation.aggregator', '--period', str(config.get('aggregator_report_period')), '--database', config.get('aggregator_database_name'), '--url', config.get('aggregator_database_url')] - process = Popen(command, cwd=dir_path) + process = Popen(command) log.info("\nStarted aggregator process with PID: {0}\n".format(process.pid)) @@ -254,6 +253,8 @@ class AggregatorController(object): @view_defaults(route_name='round_trip_time_query', renderer='json') class RoundTripTimeQuery(object): + # TODO This API endpoint has not been tested, neither has the formula used to calculate round trip time. + """ A class-based view for querying the round trip time in a given range. """ diff --git a/src/service/clmcservice/whoamiapi/__init__.py b/src/service/clmcservice/whoamiapi/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/service/clmcservice/whoamiapi/tests.py b/src/service/clmcservice/whoamiapi/tests.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/service/clmcservice/whoamiapi/views.py b/src/service/clmcservice/whoamiapi/views.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/service/setup.py b/src/service/setup.py index 802f7416861d09a25760c857e16b9898fc8c2243..385f0c9ec23f723e266f7165f4cb599197f3fcdf 100644 --- a/src/service/setup.py +++ b/src/service/setup.py @@ -56,15 +56,15 @@ tests_require = [ ] setup( - name = "clmcservice", - version = get_version("_version.py"), - author = "Michael Boniface", - author_email = "mjb@it-innovation.soton.ac.uk", - description = "FLAME CLMC Service Module", + name="clmcservice", + version=get_version("_version.py"), + author="Michael Boniface", + author_email="mjb@it-innovation.soton.ac.uk", + description="FLAME CLMC Service Module", long_description="FLAME CLMC Service", - license = "https://gitlab.it-innovation.soton.ac.uk/FLAME/flame-clmc/blob/integration/LICENSE", - keywords = "FLAME CLMC service", - url = 'https://gitlab.it-innovation.soton.ac.uk/FLAME/flame-clmc', + license="https://gitlab.it-innovation.soton.ac.uk/FLAME/flame-clmc/blob/integration/LICENSE", + keywords="FLAME CLMC service", + url='https://gitlab.it-innovation.soton.ac.uk/FLAME/flame-clmc', packages=find_packages(), include_package_data=True, install_requires=requires, diff --git a/src/test/clmctest/monitoring/test_e2eresults.py b/src/test/clmctest/monitoring/test_e2eresults.py index 746d922754716b7523494210cf5e715df4ed8680..9c957d684c677c39539c22570eb328a155a1af16 100644 --- a/src/test/clmctest/monitoring/test_e2eresults.py +++ b/src/test/clmctest/monitoring/test_e2eresults.py @@ -23,7 +23,6 @@ """ import pytest -import random import time import requests import urllib.parse