Skip to content
Snippets Groups Projects
Commit ae0398a5 authored by Francisco-Javier Moreno-Muro's avatar Francisco-Javier Moreno-Muro
Browse files

Clean code

parent 6ae69eb2
No related branches found
No related tags found
2 merge requests!54Release 2.0.0,!18Added new KPI Sample Types
...@@ -24,11 +24,12 @@ class AlarmManager(): ...@@ -24,11 +24,12 @@ class AlarmManager():
start_date = datetime.utcfromtimestamp(start_timestamp).isoformat() start_date = datetime.utcfromtimestamp(start_timestamp).isoformat()
end_date = datetime.utcfromtimestamp(end_timestamp).isoformat() end_date = datetime.utcfromtimestamp(end_timestamp).isoformat()
self.scheduler.add_job(self.metrics_db.get_alarm_data, job = self.scheduler.add_job(self.metrics_db.get_alarm_data,
args=(alarm_queue,kpi_id, kpiMinValue, kpiMaxValue, inRange, includeMinValue, includeMaxValue, subscription_frequency_ms), args=(alarm_queue,kpi_id, kpiMinValue, kpiMaxValue, inRange, includeMinValue, includeMaxValue, subscription_frequency_ms),
trigger='interval', seconds=(subscription_frequency_ms/1000), start_date=start_date, trigger='interval', seconds=(subscription_frequency_ms/1000), start_date=start_date,
end_date=end_date,timezone=pytz.utc, id=str(alarm_id)) end_date=end_date,timezone=pytz.utc, id=str(alarm_id))
LOGGER.debug(f"Alarm job {alarm_id} succesfully created") LOGGER.debug(f"Alarm job {alarm_id} succesfully created")
job.remove()
def delete_alarm(self, alarm_id): def delete_alarm(self, alarm_id):
try: try:
......
...@@ -42,10 +42,11 @@ class SubscriptionManager(): ...@@ -42,10 +42,11 @@ class SubscriptionManager():
if end_timestamp: if end_timestamp:
end_date = datetime.utcfromtimestamp(end_timestamp).isoformat() end_date = datetime.utcfromtimestamp(end_timestamp).isoformat()
self.scheduler.add_job(self.metrics_db.get_subscription_data, args=(subs_queue,kpi_id, sampling_interval_s), job = self.scheduler.add_job(self.metrics_db.get_subscription_data, args=(subs_queue,kpi_id, sampling_interval_s),
trigger='interval', seconds=sampling_interval_s, start_date=start_date, trigger='interval', seconds=sampling_interval_s, start_date=start_date,
end_date=end_date, timezone=pytz.utc, id=str(subscription_id)) end_date=end_date, timezone=pytz.utc, id=str(subscription_id))
LOGGER.debug(f"Subscrition job {subscription_id} succesfully created") LOGGER.debug(f"Subscrition job {subscription_id} succesfully created")
job.remove()
def delete_subscription(self, subscription_id): def delete_subscription(self, subscription_id):
self.scheduler.remove_job(subscription_id) self.scheduler.remove_job(subscription_id)
......
...@@ -22,6 +22,7 @@ from typing import Tuple ...@@ -22,6 +22,7 @@ from typing import Tuple
from apscheduler.executors.pool import ProcessPoolExecutor from apscheduler.executors.pool import ProcessPoolExecutor
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.schedulers.base import STATE_STOPPED
from grpc._channel import _MultiThreadedRendezvous from grpc._channel import _MultiThreadedRendezvous
from common.Constants import ServiceNameEnum from common.Constants import ServiceNameEnum
...@@ -299,6 +300,8 @@ def test_set_kpi_subscription(monitoring_client,metrics_db,subs_scheduler): # py ...@@ -299,6 +300,8 @@ def test_set_kpi_subscription(monitoring_client,metrics_db,subs_scheduler): # py
for item in response: for item in response:
LOGGER.debug(item) LOGGER.debug(item)
assert isinstance(item, SubsResponse) assert isinstance(item, SubsResponse)
if (subs_scheduler.state != STATE_STOPPED):
subs_scheduler.shutdown()
# Test case that makes use of client fixture to test server's GetSubsDescriptor method # Test case that makes use of client fixture to test server's GetSubsDescriptor method
def test_get_subs_descriptor(monitoring_client): def test_get_subs_descriptor(monitoring_client):
...@@ -364,6 +367,9 @@ def test_get_alarm_response_stream(monitoring_client,subs_scheduler): ...@@ -364,6 +367,9 @@ def test_get_alarm_response_stream(monitoring_client,subs_scheduler):
LOGGER.debug(item) LOGGER.debug(item)
assert isinstance(item,AlarmResponse) assert isinstance(item,AlarmResponse)
if(subs_scheduler.state != STATE_STOPPED):
subs_scheduler.shutdown()
# Test case that makes use of client fixture to test server's DeleteAlarm method # Test case that makes use of client fixture to test server's DeleteAlarm method
def test_delete_alarm(monitoring_client): def test_delete_alarm(monitoring_client):
LOGGER.warning('test_delete_alarm') LOGGER.warning('test_delete_alarm')
...@@ -390,7 +396,6 @@ def test_get_stream_kpi(monitoring_client): # pylint: disable=redefined-outer-na ...@@ -390,7 +396,6 @@ def test_get_stream_kpi(monitoring_client): # pylint: disable=redefined-outer-na
# LOGGER.debug(response) # LOGGER.debug(response)
# assert isinstance(response, Kpi) # assert isinstance(response, Kpi)
def test_managementdb_tools_insert_kpi(management_db): # pylint: disable=redefined-outer-name def test_managementdb_tools_insert_kpi(management_db): # pylint: disable=redefined-outer-name
LOGGER.warning('test_managementdb_tools_insert_kpi begin') LOGGER.warning('test_managementdb_tools_insert_kpi begin')
_create_kpi_request = create_kpi_request() _create_kpi_request = create_kpi_request()
......
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