Commit 65f210b0 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Monitoring component:

- added log verbosity in CI/CD pipeline since it gets stuck for unknown reasons
parent 780e2197
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
import threading
from queue import Queue

import grpc
import grpc, logging

from common.method_wrappers.ServiceExceptions import ServiceException
from context.client.ContextClient import ContextClient
@@ -26,6 +26,8 @@ from monitoring.client.MonitoringClient import MonitoringClient
from monitoring.service.MonitoringServiceServicerImpl import LOGGER
from common.proto import monitoring_pb2

LOGGER = logging.getLogger(__name__)

class EventsDeviceCollector:
    def __init__(self) -> None: # pylint: disable=redefined-outer-name
        self._events_queue = Queue()
@@ -46,12 +48,15 @@ class EventsDeviceCollector:
            return False

    def _collect(self, events_stream):
        LOGGER.warning('[_collect] begin')
        try:
            for event in events_stream:
                self._events_queue.put_nowait(event)
        except grpc.RpcError as e:
            if e.code() != grpc.StatusCode.CANCELLED: # pylint: disable=no-member
                LOGGER.warning('[_collect] raise')
                raise # pragma: no cover
        LOGGER.warning('[_collect] end')

    def start(self):
        try:
@@ -63,8 +68,11 @@ class EventsDeviceCollector:
        return self._events_queue.get(block=block, timeout=timeout)

    def stop(self):
        LOGGER.warning('[stop] begin')
        self._device_stream.cancel()
        LOGGER.warning('[stop] joining')
        self._device_thread.join()
        LOGGER.warning('[stop] end')

    def listen_events(self):
        try:
+18 −0
Original line number Diff line number Diff line
@@ -102,6 +102,8 @@ def context_service():
    LOGGER.info('Terminating MockContextService...')
    _service.stop()

    LOGGER.info('Terminated MockContextService...')

@pytest.fixture(scope='session')
def context_client(context_service : MockContextService): # pylint: disable=redefined-outer-name,unused-argument
    LOGGER.info('Initializing ContextClient...')
@@ -113,6 +115,8 @@ def context_client(context_service : MockContextService): # pylint: disable=rede
    LOGGER.info('Closing ContextClient...')
    _client.close()

    LOGGER.info('Closed ContextClient...')

@pytest.fixture(scope='session')
def device_service(context_service : MockContextService): # pylint: disable=redefined-outer-name,unused-argument
    LOGGER.info('Initializing DeviceService...')
@@ -128,6 +132,8 @@ def device_service(context_service : MockContextService): # pylint: disable=rede
    LOGGER.info('Terminating DeviceService...')
    _service.stop()

    LOGGER.info('Terminated DeviceService...')

@pytest.fixture(scope='session')
def device_client(device_service : DeviceService): # pylint: disable=redefined-outer-name,unused-argument
    LOGGER.info('Initializing DeviceClient...')
@@ -139,6 +145,8 @@ def device_client(device_service : DeviceService): # pylint: disable=redefined-o
    LOGGER.info('Closing DeviceClient...')
    _client.close()

    LOGGER.info('Closed DeviceClient...')

# This fixture will be requested by test cases and last during testing session
@pytest.fixture(scope='session')
def monitoring_service(
@@ -156,6 +164,8 @@ def monitoring_service(
    LOGGER.info('Terminating MonitoringService...')
    _service.stop()

    LOGGER.info('Terminated MonitoringService...')

# This fixture will be requested by test cases and last during testing session.
# The client requires the server, so client fixture has the server as dependency.
@pytest.fixture(scope='session')
@@ -170,6 +180,8 @@ def monitoring_client(monitoring_service : MonitoringService): # pylint: disable
    LOGGER.info('Closing MonitoringClient...')
    _client.close()

    LOGGER.info('Closed MonitoringClient...')

@pytest.fixture(scope='session')
def management_db():
    _management_db = ManagementDBTools.ManagementDB('monitoring.db')
@@ -536,6 +548,8 @@ def test_events_tools(
    device_client.DeleteDevice(response)
    events_collector.stop()

    LOGGER.warning('test_get_device_events end')


def test_get_device_events(
        context_client : ContextClient,                 # pylint: disable=redefined-outer-name,unused-argument
@@ -564,6 +578,8 @@ def test_get_device_events(
    device_client.DeleteDevice(response)
    events_collector.stop()

    LOGGER.warning('test_get_device_events end')

def test_listen_events(
        context_client : ContextClient,                 # pylint: disable=redefined-outer-name,unused-argument
        device_client : DeviceClient,                   # pylint: disable=redefined-outer-name
@@ -589,3 +605,5 @@ def test_listen_events(

    device_client.DeleteDevice(response)
    events_collector.stop()

    LOGGER.warning('test_listen_events end')