Loading src/common/tests/MockServicerImpl_Context.py +25 −1 Original line number Original line Diff line number Diff line Loading @@ -14,6 +14,7 @@ import grpc, json, logging import grpc, json, logging from typing import Any, Dict, Iterator, List, Set from typing import Any, Dict, Iterator, List, Set from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME from common.proto.context_pb2 import ( from common.proto.context_pb2 import ( Connection, ConnectionEvent, ConnectionId, ConnectionIdList, ConnectionList, Connection, ConnectionEvent, ConnectionId, ConnectionIdList, ConnectionList, Context, ContextEvent, ContextId, ContextIdList, ContextList, Context, ContextEvent, ContextId, ContextIdList, ContextList, Loading @@ -22,7 +23,7 @@ from common.proto.context_pb2 import ( Link, LinkEvent, LinkId, LinkIdList, LinkList, Link, LinkEvent, LinkId, LinkIdList, LinkList, Service, ServiceEvent, ServiceFilter, ServiceId, ServiceIdList, ServiceList, Service, ServiceEvent, ServiceFilter, ServiceId, ServiceIdList, ServiceList, Slice, SliceEvent, SliceFilter, SliceId, SliceIdList, SliceList, Slice, SliceEvent, SliceFilter, SliceId, SliceIdList, SliceList, Topology, TopologyEvent, TopologyId, TopologyIdList, TopologyList) Topology, TopologyDetails, TopologyEvent, TopologyId, TopologyIdList, TopologyList) from common.proto.context_pb2_grpc import ContextServiceServicer from common.proto.context_pb2_grpc import ContextServiceServicer from common.tests.MockMessageBroker import ( from common.tests.MockMessageBroker import ( TOPIC_CONNECTION, TOPIC_CONTEXT, TOPIC_DEVICE, TOPIC_LINK, TOPIC_SERVICE, TOPIC_SLICE, TOPIC_TOPOLOGY, TOPIC_CONNECTION, TOPIC_CONTEXT, TOPIC_DEVICE, TOPIC_LINK, TOPIC_SERVICE, TOPIC_SLICE, TOPIC_TOPOLOGY, Loading Loading @@ -162,6 +163,29 @@ class MockServicerImpl_Context(ContextServiceServicer): LOGGER.info('[GetTopology] reply={:s}'.format(grpc_message_to_json_string(reply))) LOGGER.info('[GetTopology] reply={:s}'.format(grpc_message_to_json_string(reply))) return reply return reply def GetTopologyDetails(self, request : TopologyId, context : grpc.ServicerContext) -> TopologyDetails: LOGGER.info('[GetTopologyDetails] request={:s}'.format(grpc_message_to_json_string(request))) context_uuid = request.context_id.context_uuid.uuid container_name = 'topology[{:s}]'.format(str(context_uuid)) topology_uuid = request.topology_uuid.uuid _reply = get_entry(context, self.database, container_name, topology_uuid) reply = TopologyDetails() reply.topology_id.CopyFrom(_reply.topology_id) reply.name = _reply.name if context_uuid == DEFAULT_CONTEXT_NAME and topology_uuid == DEFAULT_TOPOLOGY_NAME: for device in get_entries(self.database, 'device'): reply.devices.append(device) for link in get_entries(self.database, 'link'): reply.links.append(link) else: # TODO: to be improved; Mock does not associate devices/links to topologies automatically for device_id in _reply.device_ids: device = get_entry(context, self.database, 'device', device_id.device_uuid.uuid) reply.devices.append(device) for link_id in _reply.link_ids: link = get_entry(context, self.database, 'link', link_id.link_uuid.uuid) reply.links.append(link) LOGGER.info('[GetTopologyDetails] reply={:s}'.format(grpc_message_to_json_string(reply))) return reply def SetTopology(self, request: Topology, context : grpc.ServicerContext) -> TopologyId: def SetTopology(self, request: Topology, context : grpc.ServicerContext) -> TopologyId: LOGGER.info('[SetTopology] request={:s}'.format(grpc_message_to_json_string(request))) LOGGER.info('[SetTopology] request={:s}'.format(grpc_message_to_json_string(request))) container_name = 'topology[{:s}]'.format(str(request.topology_id.context_id.context_uuid.uuid)) container_name = 'topology[{:s}]'.format(str(request.topology_id.context_id.context_uuid.uuid)) Loading src/common/tools/object_factory/Device.py +4 −9 Original line number Original line Diff line number Diff line Loading @@ -136,7 +136,7 @@ def json_device_tfs_disabled( device_uuid, DEVICE_TFS_TYPE, DEVICE_DISABLED, name=name, endpoints=endpoints, config_rules=config_rules, device_uuid, DEVICE_TFS_TYPE, DEVICE_DISABLED, name=name, endpoints=endpoints, config_rules=config_rules, drivers=drivers) drivers=drivers) def json_device_connect_rules(address : str, port : int, settings : Dict = {}): def json_device_connect_rules(address : str, port : int, settings : Dict = {}) -> List[Dict]: return [ return [ json_config_rule_set('_connect/address', address), json_config_rule_set('_connect/address', address), json_config_rule_set('_connect/port', port), json_config_rule_set('_connect/port', port), Loading @@ -144,12 +144,7 @@ def json_device_connect_rules(address : str, port : int, settings : Dict = {}): ] ] def json_device_emulated_connect_rules( def json_device_emulated_connect_rules( endpoint_descriptors : List[Tuple[str, str, List[int]]], address : str = DEVICE_EMU_ADDRESS, endpoint_descriptors : List[Dict], address : str = DEVICE_EMU_ADDRESS, port : int = DEVICE_EMU_PORT port : int = DEVICE_EMU_PORT ) -> List[Dict]: ): settings = {'endpoints': endpoint_descriptors} settings = {'endpoints': [ {'uuid': endpoint_uuid, 'type': endpoint_type, 'sample_types': sample_types} for endpoint_uuid,endpoint_type,sample_types in endpoint_descriptors ]} return json_device_connect_rules(address, port, settings=settings) return json_device_connect_rules(address, port, settings=settings) src/common/tools/object_factory/EndPoint.py +25 −10 Original line number Original line Diff line number Diff line Loading @@ -13,7 +13,20 @@ # limitations under the License. # limitations under the License. import copy import copy from typing import Dict, List, Optional, Tuple from typing import Dict, List, Optional def json_endpoint_descriptor( endpoint_uuid : str, endpoint_type : str, endpoint_name : Optional[str] = None, sample_types : List[int] = [], location : Optional[Dict] = None ) -> Dict: result = {'uuid': endpoint_uuid, 'type': endpoint_type} if endpoint_name is not None: result['name'] = endpoint_name if sample_types is not None and len(sample_types) > 0: result['sample_types'] = sample_types if location is not None and len(location) > 0: result['location'] = location return result def json_endpoint_id(device_id : Dict, endpoint_uuid : str, topology_id : Optional[Dict] = None): def json_endpoint_id(device_id : Dict, endpoint_uuid : str, topology_id : Optional[Dict] = None): result = {'device_id': copy.deepcopy(device_id), 'endpoint_uuid': {'uuid': endpoint_uuid}} result = {'device_id': copy.deepcopy(device_id), 'endpoint_uuid': {'uuid': endpoint_uuid}} Loading @@ -21,11 +34,11 @@ def json_endpoint_id(device_id : Dict, endpoint_uuid : str, topology_id : Option return result return result def json_endpoint_ids( def json_endpoint_ids( device_id : Dict, endpoint_descriptors : List[Tuple[str, str, List[int]]], topology_id : Optional[Dict] = None device_id : Dict, endpoint_descriptors : List[Dict], topology_id : Optional[Dict] = None ): ): return [ return [ json_endpoint_id(device_id, endpoint_uuid, topology_id=topology_id) json_endpoint_id(device_id, endpoint_data['uuid'], topology_id=topology_id) for endpoint_uuid, _, _ in endpoint_descriptors for endpoint_data in endpoint_descriptors ] ] def json_endpoint( def json_endpoint( Loading @@ -37,16 +50,18 @@ def json_endpoint( 'endpoint_id': json_endpoint_id(device_id, endpoint_uuid, topology_id=topology_id), 'endpoint_id': json_endpoint_id(device_id, endpoint_uuid, topology_id=topology_id), 'endpoint_type': endpoint_type, 'endpoint_type': endpoint_type, } } if len(kpi_sample_types) > 0: result['kpi_sample_types'] = copy.deepcopy(kpi_sample_types) if kpi_sample_types is not None and len(kpi_sample_types) > 0: if location: result['endpoint_location'] = copy.deepcopy(location) result['kpi_sample_types'] = copy.deepcopy(kpi_sample_types) if location is not None: result['endpoint_location'] = copy.deepcopy(location) return result return result def json_endpoints( def json_endpoints( device_id : Dict, endpoint_descriptors : List[Tuple[str, str, List[int]]], topology_id : Optional[Dict] = None device_id : Dict, endpoint_descriptors : List[Dict], topology_id : Optional[Dict] = None ): ): return [ return [ json_endpoint( json_endpoint( device_id, endpoint_uuid, endpoint_type, topology_id=topology_id, device_id, endpoint_data['uuid'], endpoint_data['type'], topology_id=topology_id, kpi_sample_types=endpoint_sample_types) kpi_sample_types=endpoint_data.get('sample_types'), location=endpoint_data.get('location')) for endpoint_uuid, endpoint_type, endpoint_sample_types in endpoint_descriptors for endpoint_data in endpoint_descriptors ] ] src/context/service/database/Constraint.py +1 −1 Original line number Original line Diff line number Diff line Loading @@ -122,7 +122,7 @@ def upsert_constraints( stmt = delete(klass) stmt = delete(klass) if service_uuid is not None: stmt = stmt.where(klass.service_uuid == service_uuid) if service_uuid is not None: stmt = stmt.where(klass.service_uuid == service_uuid) if slice_uuid is not None: stmt = stmt.where(klass.slice_uuid == slice_uuid ) if slice_uuid is not None: stmt = stmt.where(klass.slice_uuid == slice_uuid ) stmt = stmt.where(klass.constraint_uuid.in_(uuids_to_delete) stmt = stmt.where(klass.constraint_uuid.in_(uuids_to_delete)) #str_stmt = stmt.compile(dialect=postgresql.dialect(), compile_kwargs={"literal_binds": True}) #str_stmt = stmt.compile(dialect=postgresql.dialect(), compile_kwargs={"literal_binds": True}) #LOGGER.warning('delete stmt={:s}'.format(str(str_stmt))) #LOGGER.warning('delete stmt={:s}'.format(str(str_stmt))) constraint_deletes = session.execute(stmt) constraint_deletes = session.execute(stmt) Loading src/device/requirements.in +2 −2 Original line number Original line Diff line number Diff line Loading @@ -14,7 +14,7 @@ anytree==2.8.0 anytree==2.8.0 APScheduler==3.8.1 APScheduler==3.10.1 cryptography==36.0.2 cryptography==36.0.2 #fastcache==1.1.0 #fastcache==1.1.0 Jinja2==3.0.3 Jinja2==3.0.3 Loading @@ -22,7 +22,7 @@ ncclient==0.6.13 p4runtime==1.3.0 p4runtime==1.3.0 paramiko==2.9.2 paramiko==2.9.2 python-json-logger==2.0.2 python-json-logger==2.0.2 pytz==2021.3 #pytz==2021.3 #redis==4.1.2 #redis==4.1.2 requests==2.27.1 requests==2.27.1 requests-mock==1.9.3 requests-mock==1.9.3 Loading Loading
src/common/tests/MockServicerImpl_Context.py +25 −1 Original line number Original line Diff line number Diff line Loading @@ -14,6 +14,7 @@ import grpc, json, logging import grpc, json, logging from typing import Any, Dict, Iterator, List, Set from typing import Any, Dict, Iterator, List, Set from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME from common.proto.context_pb2 import ( from common.proto.context_pb2 import ( Connection, ConnectionEvent, ConnectionId, ConnectionIdList, ConnectionList, Connection, ConnectionEvent, ConnectionId, ConnectionIdList, ConnectionList, Context, ContextEvent, ContextId, ContextIdList, ContextList, Context, ContextEvent, ContextId, ContextIdList, ContextList, Loading @@ -22,7 +23,7 @@ from common.proto.context_pb2 import ( Link, LinkEvent, LinkId, LinkIdList, LinkList, Link, LinkEvent, LinkId, LinkIdList, LinkList, Service, ServiceEvent, ServiceFilter, ServiceId, ServiceIdList, ServiceList, Service, ServiceEvent, ServiceFilter, ServiceId, ServiceIdList, ServiceList, Slice, SliceEvent, SliceFilter, SliceId, SliceIdList, SliceList, Slice, SliceEvent, SliceFilter, SliceId, SliceIdList, SliceList, Topology, TopologyEvent, TopologyId, TopologyIdList, TopologyList) Topology, TopologyDetails, TopologyEvent, TopologyId, TopologyIdList, TopologyList) from common.proto.context_pb2_grpc import ContextServiceServicer from common.proto.context_pb2_grpc import ContextServiceServicer from common.tests.MockMessageBroker import ( from common.tests.MockMessageBroker import ( TOPIC_CONNECTION, TOPIC_CONTEXT, TOPIC_DEVICE, TOPIC_LINK, TOPIC_SERVICE, TOPIC_SLICE, TOPIC_TOPOLOGY, TOPIC_CONNECTION, TOPIC_CONTEXT, TOPIC_DEVICE, TOPIC_LINK, TOPIC_SERVICE, TOPIC_SLICE, TOPIC_TOPOLOGY, Loading Loading @@ -162,6 +163,29 @@ class MockServicerImpl_Context(ContextServiceServicer): LOGGER.info('[GetTopology] reply={:s}'.format(grpc_message_to_json_string(reply))) LOGGER.info('[GetTopology] reply={:s}'.format(grpc_message_to_json_string(reply))) return reply return reply def GetTopologyDetails(self, request : TopologyId, context : grpc.ServicerContext) -> TopologyDetails: LOGGER.info('[GetTopologyDetails] request={:s}'.format(grpc_message_to_json_string(request))) context_uuid = request.context_id.context_uuid.uuid container_name = 'topology[{:s}]'.format(str(context_uuid)) topology_uuid = request.topology_uuid.uuid _reply = get_entry(context, self.database, container_name, topology_uuid) reply = TopologyDetails() reply.topology_id.CopyFrom(_reply.topology_id) reply.name = _reply.name if context_uuid == DEFAULT_CONTEXT_NAME and topology_uuid == DEFAULT_TOPOLOGY_NAME: for device in get_entries(self.database, 'device'): reply.devices.append(device) for link in get_entries(self.database, 'link'): reply.links.append(link) else: # TODO: to be improved; Mock does not associate devices/links to topologies automatically for device_id in _reply.device_ids: device = get_entry(context, self.database, 'device', device_id.device_uuid.uuid) reply.devices.append(device) for link_id in _reply.link_ids: link = get_entry(context, self.database, 'link', link_id.link_uuid.uuid) reply.links.append(link) LOGGER.info('[GetTopologyDetails] reply={:s}'.format(grpc_message_to_json_string(reply))) return reply def SetTopology(self, request: Topology, context : grpc.ServicerContext) -> TopologyId: def SetTopology(self, request: Topology, context : grpc.ServicerContext) -> TopologyId: LOGGER.info('[SetTopology] request={:s}'.format(grpc_message_to_json_string(request))) LOGGER.info('[SetTopology] request={:s}'.format(grpc_message_to_json_string(request))) container_name = 'topology[{:s}]'.format(str(request.topology_id.context_id.context_uuid.uuid)) container_name = 'topology[{:s}]'.format(str(request.topology_id.context_id.context_uuid.uuid)) Loading
src/common/tools/object_factory/Device.py +4 −9 Original line number Original line Diff line number Diff line Loading @@ -136,7 +136,7 @@ def json_device_tfs_disabled( device_uuid, DEVICE_TFS_TYPE, DEVICE_DISABLED, name=name, endpoints=endpoints, config_rules=config_rules, device_uuid, DEVICE_TFS_TYPE, DEVICE_DISABLED, name=name, endpoints=endpoints, config_rules=config_rules, drivers=drivers) drivers=drivers) def json_device_connect_rules(address : str, port : int, settings : Dict = {}): def json_device_connect_rules(address : str, port : int, settings : Dict = {}) -> List[Dict]: return [ return [ json_config_rule_set('_connect/address', address), json_config_rule_set('_connect/address', address), json_config_rule_set('_connect/port', port), json_config_rule_set('_connect/port', port), Loading @@ -144,12 +144,7 @@ def json_device_connect_rules(address : str, port : int, settings : Dict = {}): ] ] def json_device_emulated_connect_rules( def json_device_emulated_connect_rules( endpoint_descriptors : List[Tuple[str, str, List[int]]], address : str = DEVICE_EMU_ADDRESS, endpoint_descriptors : List[Dict], address : str = DEVICE_EMU_ADDRESS, port : int = DEVICE_EMU_PORT port : int = DEVICE_EMU_PORT ) -> List[Dict]: ): settings = {'endpoints': endpoint_descriptors} settings = {'endpoints': [ {'uuid': endpoint_uuid, 'type': endpoint_type, 'sample_types': sample_types} for endpoint_uuid,endpoint_type,sample_types in endpoint_descriptors ]} return json_device_connect_rules(address, port, settings=settings) return json_device_connect_rules(address, port, settings=settings)
src/common/tools/object_factory/EndPoint.py +25 −10 Original line number Original line Diff line number Diff line Loading @@ -13,7 +13,20 @@ # limitations under the License. # limitations under the License. import copy import copy from typing import Dict, List, Optional, Tuple from typing import Dict, List, Optional def json_endpoint_descriptor( endpoint_uuid : str, endpoint_type : str, endpoint_name : Optional[str] = None, sample_types : List[int] = [], location : Optional[Dict] = None ) -> Dict: result = {'uuid': endpoint_uuid, 'type': endpoint_type} if endpoint_name is not None: result['name'] = endpoint_name if sample_types is not None and len(sample_types) > 0: result['sample_types'] = sample_types if location is not None and len(location) > 0: result['location'] = location return result def json_endpoint_id(device_id : Dict, endpoint_uuid : str, topology_id : Optional[Dict] = None): def json_endpoint_id(device_id : Dict, endpoint_uuid : str, topology_id : Optional[Dict] = None): result = {'device_id': copy.deepcopy(device_id), 'endpoint_uuid': {'uuid': endpoint_uuid}} result = {'device_id': copy.deepcopy(device_id), 'endpoint_uuid': {'uuid': endpoint_uuid}} Loading @@ -21,11 +34,11 @@ def json_endpoint_id(device_id : Dict, endpoint_uuid : str, topology_id : Option return result return result def json_endpoint_ids( def json_endpoint_ids( device_id : Dict, endpoint_descriptors : List[Tuple[str, str, List[int]]], topology_id : Optional[Dict] = None device_id : Dict, endpoint_descriptors : List[Dict], topology_id : Optional[Dict] = None ): ): return [ return [ json_endpoint_id(device_id, endpoint_uuid, topology_id=topology_id) json_endpoint_id(device_id, endpoint_data['uuid'], topology_id=topology_id) for endpoint_uuid, _, _ in endpoint_descriptors for endpoint_data in endpoint_descriptors ] ] def json_endpoint( def json_endpoint( Loading @@ -37,16 +50,18 @@ def json_endpoint( 'endpoint_id': json_endpoint_id(device_id, endpoint_uuid, topology_id=topology_id), 'endpoint_id': json_endpoint_id(device_id, endpoint_uuid, topology_id=topology_id), 'endpoint_type': endpoint_type, 'endpoint_type': endpoint_type, } } if len(kpi_sample_types) > 0: result['kpi_sample_types'] = copy.deepcopy(kpi_sample_types) if kpi_sample_types is not None and len(kpi_sample_types) > 0: if location: result['endpoint_location'] = copy.deepcopy(location) result['kpi_sample_types'] = copy.deepcopy(kpi_sample_types) if location is not None: result['endpoint_location'] = copy.deepcopy(location) return result return result def json_endpoints( def json_endpoints( device_id : Dict, endpoint_descriptors : List[Tuple[str, str, List[int]]], topology_id : Optional[Dict] = None device_id : Dict, endpoint_descriptors : List[Dict], topology_id : Optional[Dict] = None ): ): return [ return [ json_endpoint( json_endpoint( device_id, endpoint_uuid, endpoint_type, topology_id=topology_id, device_id, endpoint_data['uuid'], endpoint_data['type'], topology_id=topology_id, kpi_sample_types=endpoint_sample_types) kpi_sample_types=endpoint_data.get('sample_types'), location=endpoint_data.get('location')) for endpoint_uuid, endpoint_type, endpoint_sample_types in endpoint_descriptors for endpoint_data in endpoint_descriptors ] ]
src/context/service/database/Constraint.py +1 −1 Original line number Original line Diff line number Diff line Loading @@ -122,7 +122,7 @@ def upsert_constraints( stmt = delete(klass) stmt = delete(klass) if service_uuid is not None: stmt = stmt.where(klass.service_uuid == service_uuid) if service_uuid is not None: stmt = stmt.where(klass.service_uuid == service_uuid) if slice_uuid is not None: stmt = stmt.where(klass.slice_uuid == slice_uuid ) if slice_uuid is not None: stmt = stmt.where(klass.slice_uuid == slice_uuid ) stmt = stmt.where(klass.constraint_uuid.in_(uuids_to_delete) stmt = stmt.where(klass.constraint_uuid.in_(uuids_to_delete)) #str_stmt = stmt.compile(dialect=postgresql.dialect(), compile_kwargs={"literal_binds": True}) #str_stmt = stmt.compile(dialect=postgresql.dialect(), compile_kwargs={"literal_binds": True}) #LOGGER.warning('delete stmt={:s}'.format(str(str_stmt))) #LOGGER.warning('delete stmt={:s}'.format(str(str_stmt))) constraint_deletes = session.execute(stmt) constraint_deletes = session.execute(stmt) Loading
src/device/requirements.in +2 −2 Original line number Original line Diff line number Diff line Loading @@ -14,7 +14,7 @@ anytree==2.8.0 anytree==2.8.0 APScheduler==3.8.1 APScheduler==3.10.1 cryptography==36.0.2 cryptography==36.0.2 #fastcache==1.1.0 #fastcache==1.1.0 Jinja2==3.0.3 Jinja2==3.0.3 Loading @@ -22,7 +22,7 @@ ncclient==0.6.13 p4runtime==1.3.0 p4runtime==1.3.0 paramiko==2.9.2 paramiko==2.9.2 python-json-logger==2.0.2 python-json-logger==2.0.2 pytz==2021.3 #pytz==2021.3 #redis==4.1.2 #redis==4.1.2 requests==2.27.1 requests==2.27.1 requests-mock==1.9.3 requests-mock==1.9.3 Loading