diff --git a/src/context/Config.py b/src/context/Config.py index 4c53fa59bbb1c2bc27f21a55e77cc022fa1280af..473db28503e6ef2a9db36087e7c62fa8799979f7 100644 --- a/src/context/Config.py +++ b/src/context/Config.py @@ -1,10 +1,12 @@ import logging +# General settings +LOG_LEVEL = logging.WARNING + # gRPC settings GRPC_SERVICE_PORT = 1010 GRPC_MAX_WORKERS = 10 GRPC_GRACE_PERIOD = 60 -GRPC_LOG_LEVEL = logging.WARNING # HTTP settings HTTP_SERVICE_PORT = 8080 diff --git a/src/device/Config.py b/src/device/Config.py index 438f831a8314325c0c7211f2e864f619ed783842..6787413a881b4d84ed6b4ecb5e041901399a4ae6 100644 --- a/src/device/Config.py +++ b/src/device/Config.py @@ -1,10 +1,12 @@ import logging +# General settings +LOG_LEVEL = logging.WARNING + # gRPC settings GRPC_SERVICE_PORT = 2020 GRPC_MAX_WORKERS = 10 GRPC_GRACE_PERIOD = 60 -GRPC_LOG_LEVEL = logging.WARNING # Prometheus settings METRICS_PORT = 9192 diff --git a/src/device/proto/context_pb2.py b/src/device/proto/context_pb2.py index 99b6c9defbafb9989bedbb800a5e1ee66c15385b..a41b1de47f4df97a6e90b42a02fab7556feafd34 100644 --- a/src/device/proto/context_pb2.py +++ b/src/device/proto/context_pb2.py @@ -20,7 +20,7 @@ DESCRIPTOR = _descriptor.FileDescriptor( syntax='proto3', serialized_options=None, create_key=_descriptor._internal_create_key, - serialized_pb=b'\n\rcontext.proto\x12\x07\x63ontext\"\x07\n\x05\x45mpty\"{\n\x07\x43ontext\x12%\n\tcontextId\x18\x01 \x01(\x0b\x32\x12.context.ContextId\x12\x1f\n\x04topo\x18\x02 \x01(\x0b\x32\x11.context.Topology\x12(\n\x03\x63tl\x18\x03 \x01(\x0b\x32\x1b.context.TeraFlowController\"/\n\tContextId\x12\"\n\x0b\x63ontextUuid\x18\x01 \x01(\x0b\x32\r.context.Uuid\"m\n\x08Topology\x12#\n\x06topoId\x18\x02 \x01(\x0b\x32\x13.context.TopologyId\x12\x1f\n\x06\x64\x65vice\x18\x03 \x03(\x0b\x32\x0f.context.Device\x12\x1b\n\x04link\x18\x04 \x03(\x0b\x32\r.context.Link\"S\n\x04Link\x12 \n\x07link_id\x18\x01 \x01(\x0b\x32\x0f.context.LinkId\x12)\n\x0c\x65ndpointList\x18\x02 \x03(\x0b\x32\x13.context.EndPointId\"R\n\nTopologyId\x12%\n\tcontextId\x18\x01 \x01(\x0b\x32\x12.context.ContextId\x12\x1d\n\x06topoId\x18\x02 \x01(\x0b\x32\r.context.Uuid\"?\n\nConstraint\x12\x17\n\x0f\x63onstraint_type\x18\x01 \x01(\t\x12\x18\n\x10\x63onstraint_value\x18\x02 \x01(\t\"\xda\x01\n\x06\x44\x65vice\x12$\n\tdevice_id\x18\x01 \x01(\x0b\x32\x11.context.DeviceId\x12\x13\n\x0b\x64\x65vice_type\x18\x02 \x01(\t\x12,\n\rdevice_config\x18\x03 \x01(\x0b\x32\x15.context.DeviceConfig\x12>\n\x14\x64\x65vOperationalStatus\x18\x04 \x01(\x0e\x32 .context.DeviceOperationalStatus\x12\'\n\x0c\x65ndpointList\x18\x05 \x03(\x0b\x32\x11.context.EndPoint\"%\n\x0c\x44\x65viceConfig\x12\x15\n\rdevice_config\x18\x01 \x01(\t\"C\n\x08\x45ndPoint\x12$\n\x07port_id\x18\x01 \x01(\x0b\x32\x13.context.EndPointId\x12\x11\n\tport_type\x18\x02 \x01(\t\"t\n\nEndPointId\x12#\n\x06topoId\x18\x01 \x01(\x0b\x32\x13.context.TopologyId\x12!\n\x06\x64\x65v_id\x18\x02 \x01(\x0b\x32\x11.context.DeviceId\x12\x1e\n\x07port_id\x18\x03 \x01(\x0b\x32\r.context.Uuid\",\n\x08\x44\x65viceId\x12 \n\tdevice_id\x18\x01 \x01(\x0b\x32\r.context.Uuid\"(\n\x06LinkId\x12\x1e\n\x07link_id\x18\x01 \x01(\x0b\x32\r.context.Uuid\"\x14\n\x04Uuid\x12\x0c\n\x04uuid\x18\x01 \x01(\t\"K\n\x12TeraFlowController\x12\"\n\x06\x63tl_id\x18\x01 \x01(\x0b\x32\x12.context.ContextId\x12\x11\n\tipaddress\x18\x02 \x01(\t\"Q\n\x14\x41uthenticationResult\x12\"\n\x06\x63tl_id\x18\x01 \x01(\x0b\x32\x12.context.ContextId\x12\x15\n\rauthenticated\x18\x02 \x01(\x08*M\n\x17\x44\x65viceOperationalStatus\x12\x0e\n\nKEEP_STATE\x10\x00\x12\x15\n\x08\x44ISABLED\x10\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01\x12\x0b\n\x07\x45NABLED\x10\x01\x32\xa2\x01\n\x0e\x43ontextService\x12\x32\n\x0bGetTopology\x12\x0e.context.Empty\x1a\x11.context.Topology\"\x00\x12+\n\x07\x41\x64\x64Link\x12\r.context.Link\x1a\x0f.context.LinkId\"\x00\x12/\n\nDeleteLink\x12\x0f.context.LinkId\x1a\x0e.context.Empty\"\x00\x62\x06proto3' + serialized_pb=b'\n\rcontext.proto\x12\x07\x63ontext\"\x07\n\x05\x45mpty\"{\n\x07\x43ontext\x12%\n\tcontextId\x18\x01 \x01(\x0b\x32\x12.context.ContextId\x12\x1f\n\x04topo\x18\x02 \x01(\x0b\x32\x11.context.Topology\x12(\n\x03\x63tl\x18\x03 \x01(\x0b\x32\x1b.context.TeraFlowController\"/\n\tContextId\x12\"\n\x0b\x63ontextUuid\x18\x01 \x01(\x0b\x32\r.context.Uuid\"m\n\x08Topology\x12#\n\x06topoId\x18\x02 \x01(\x0b\x32\x13.context.TopologyId\x12\x1f\n\x06\x64\x65vice\x18\x03 \x03(\x0b\x32\x0f.context.Device\x12\x1b\n\x04link\x18\x04 \x03(\x0b\x32\r.context.Link\"S\n\x04Link\x12 \n\x07link_id\x18\x01 \x01(\x0b\x32\x0f.context.LinkId\x12)\n\x0c\x65ndpointList\x18\x02 \x03(\x0b\x32\x13.context.EndPointId\"R\n\nTopologyId\x12%\n\tcontextId\x18\x01 \x01(\x0b\x32\x12.context.ContextId\x12\x1d\n\x06topoId\x18\x02 \x01(\x0b\x32\r.context.Uuid\"?\n\nConstraint\x12\x17\n\x0f\x63onstraint_type\x18\x01 \x01(\t\x12\x18\n\x10\x63onstraint_value\x18\x02 \x01(\t\"\xda\x01\n\x06\x44\x65vice\x12$\n\tdevice_id\x18\x01 \x01(\x0b\x32\x11.context.DeviceId\x12\x13\n\x0b\x64\x65vice_type\x18\x02 \x01(\t\x12,\n\rdevice_config\x18\x03 \x01(\x0b\x32\x15.context.DeviceConfig\x12>\n\x14\x64\x65vOperationalStatus\x18\x04 \x01(\x0e\x32 .context.DeviceOperationalStatus\x12\'\n\x0c\x65ndpointList\x18\x05 \x03(\x0b\x32\x11.context.EndPoint\"%\n\x0c\x44\x65viceConfig\x12\x15\n\rdevice_config\x18\x01 \x01(\t\"C\n\x08\x45ndPoint\x12$\n\x07port_id\x18\x01 \x01(\x0b\x32\x13.context.EndPointId\x12\x11\n\tport_type\x18\x02 \x01(\t\"t\n\nEndPointId\x12#\n\x06topoId\x18\x01 \x01(\x0b\x32\x13.context.TopologyId\x12!\n\x06\x64\x65v_id\x18\x02 \x01(\x0b\x32\x11.context.DeviceId\x12\x1e\n\x07port_id\x18\x03 \x01(\x0b\x32\r.context.Uuid\",\n\x08\x44\x65viceId\x12 \n\tdevice_id\x18\x01 \x01(\x0b\x32\r.context.Uuid\"(\n\x06LinkId\x12\x1e\n\x07link_id\x18\x01 \x01(\x0b\x32\r.context.Uuid\"\x14\n\x04Uuid\x12\x0c\n\x04uuid\x18\x01 \x01(\t\"K\n\x12TeraFlowController\x12\"\n\x06\x63tl_id\x18\x01 \x01(\x0b\x32\x12.context.ContextId\x12\x11\n\tipaddress\x18\x02 \x01(\t\"Q\n\x14\x41uthenticationResult\x12\"\n\x06\x63tl_id\x18\x01 \x01(\x0b\x32\x12.context.ContextId\x12\x15\n\rauthenticated\x18\x02 \x01(\x08*N\n\x17\x44\x65viceOperationalStatus\x12\x0f\n\x0bKEEP_STATUS\x10\x00\x12\x15\n\x08\x44ISABLED\x10\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01\x12\x0b\n\x07\x45NABLED\x10\x01\x32\xa2\x01\n\x0e\x43ontextService\x12\x32\n\x0bGetTopology\x12\x0e.context.Empty\x1a\x11.context.Topology\"\x00\x12+\n\x07\x41\x64\x64Link\x12\r.context.Link\x1a\x0f.context.LinkId\"\x00\x12/\n\nDeleteLink\x12\x0f.context.LinkId\x1a\x0e.context.Empty\"\x00\x62\x06proto3' ) _DEVICEOPERATIONALSTATUS = _descriptor.EnumDescriptor( @@ -31,7 +31,7 @@ _DEVICEOPERATIONALSTATUS = _descriptor.EnumDescriptor( create_key=_descriptor._internal_create_key, values=[ _descriptor.EnumValueDescriptor( - name='KEEP_STATE', index=0, number=0, + name='KEEP_STATUS', index=0, number=0, serialized_options=None, type=None, create_key=_descriptor._internal_create_key), @@ -49,12 +49,12 @@ _DEVICEOPERATIONALSTATUS = _descriptor.EnumDescriptor( containing_type=None, serialized_options=None, serialized_start=1271, - serialized_end=1348, + serialized_end=1349, ) _sym_db.RegisterEnumDescriptor(_DEVICEOPERATIONALSTATUS) DeviceOperationalStatus = enum_type_wrapper.EnumTypeWrapper(_DEVICEOPERATIONALSTATUS) -KEEP_STATE = 0 +KEEP_STATUS = 0 DISABLED = -1 ENABLED = 1 @@ -839,8 +839,8 @@ _CONTEXTSERVICE = _descriptor.ServiceDescriptor( index=0, serialized_options=None, create_key=_descriptor._internal_create_key, - serialized_start=1351, - serialized_end=1513, + serialized_start=1352, + serialized_end=1514, methods=[ _descriptor.MethodDescriptor( name='GetTopology', diff --git a/src/device/service/DeviceService.py b/src/device/service/DeviceService.py index 11cc13d47b249760c20d1e7bf26fc65e7160ce1b..29fdc97ce1ba5c8d7266ecdac340dce3e3670425 100644 --- a/src/device/service/DeviceService.py +++ b/src/device/service/DeviceService.py @@ -6,14 +6,14 @@ from grpc_health.v1.health_pb2 import HealthCheckResponse from grpc_health.v1.health_pb2_grpc import add_HealthServicer_to_server from device.proto.device_pb2_grpc import add_DeviceServiceServicer_to_server from device.service.DeviceServiceServicerImpl import DeviceServiceServicerImpl -from device.Config import SERVICE_PORT, MAX_WORKERS, GRACE_PERIOD +from device.Config import GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD BIND_ADDRESS = '0.0.0.0' LOGGER = logging.getLogger(__name__) class DeviceService: - def __init__(self, database, address=BIND_ADDRESS, port=SERVICE_PORT, max_workers=MAX_WORKERS, - grace_period=GRACE_PERIOD): + def __init__(self, database, address=BIND_ADDRESS, port=GRPC_SERVICE_PORT, max_workers=GRPC_MAX_WORKERS, + grace_period=GRPC_GRACE_PERIOD): self.database = database self.address = address self.port = port diff --git a/src/device/service/__main__.py b/src/device/service/__main__.py index 8ec270586140ef35c10fa5d5ea112ec4322c5c4c..ae7db591c5c39836e0e1a5c62039060eb6651434 100644 --- a/src/device/service/__main__.py +++ b/src/device/service/__main__.py @@ -2,7 +2,7 @@ import logging, os, signal, sys, threading from prometheus_client import start_http_server from common.database.Factory import get_database from device.service.DeviceService import DeviceService -from device.Config import SERVICE_PORT, MAX_WORKERS, GRACE_PERIOD, LOG_LEVEL, METRICS_PORT +from device.Config import GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD, LOG_LEVEL, METRICS_PORT terminate = threading.Event() logger = None @@ -15,9 +15,9 @@ def signal_handler(signal, frame): def main(): global terminate, logger - service_port = os.environ.get('DEVICESERVICE_SERVICE_PORT_GRPC', SERVICE_PORT) - max_workers = os.environ.get('MAX_WORKERS', MAX_WORKERS ) - grace_period = os.environ.get('GRACE_PERIOD', GRACE_PERIOD) + service_port = os.environ.get('DEVICESERVICE_SERVICE_PORT_GRPC', GRPC_SERVICE_PORT) + max_workers = os.environ.get('MAX_WORKERS', GRPC_MAX_WORKERS ) + grace_period = os.environ.get('GRACE_PERIOD', GRPC_GRACE_PERIOD) log_level = os.environ.get('LOG_LEVEL', LOG_LEVEL ) metrics_port = os.environ.get('METRICS_PORT', METRICS_PORT) diff --git a/src/device/tests/test_unitary.py b/src/device/tests/test_unitary.py index de7539274352b5b2b1e0397f54cedd2e6e24fbc9..c5c281a98cd77ed56a7279f611231c27b13f6b3c 100644 --- a/src/device/tests/test_unitary.py +++ b/src/device/tests/test_unitary.py @@ -6,7 +6,7 @@ from common.tests.Assertions import validate_device_id, validate_empty from device.client.DeviceClient import DeviceClient from device.proto.context_pb2 import Device, DeviceId from device.service.DeviceService import DeviceService -from device.Config import SERVICE_PORT, MAX_WORKERS, GRACE_PERIOD +from device.Config import GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) @@ -46,14 +46,15 @@ DEVICE = { @pytest.fixture(scope='session') def service(): database = get_database(engine=DatabaseEngineEnum.INMEMORY, filepath='data/topo_nsfnet.json') - _service = DeviceService(database, port=SERVICE_PORT, max_workers=MAX_WORKERS, grace_period=GRACE_PERIOD) + _service = DeviceService( + database, port=GRPC_SERVICE_PORT, max_workers=GRPC_MAX_WORKERS, grace_period=GRPC_GRACE_PERIOD) _service.start() yield _service _service.stop() @pytest.fixture(scope='session') def client(service): - _client = DeviceClient(address='127.0.0.1', port=SERVICE_PORT) + _client = DeviceClient(address='127.0.0.1', port=GRPC_SERVICE_PORT) yield _client _client.close()