Loading deploy/crdb.sh +2 −3 Original line number Diff line number Diff line Loading @@ -158,9 +158,8 @@ function crdb_drop_databases_single() { echo "Drop TFS databases, if exist" if [[ -z "${GITLAB_CI}" ]]; then kubectl --namespace ${CRDB_NAMESPACE} get service cockroachdb-public -o yaml CRDB_HOST="cockroachdb-0" #CRDB_HOST=$(kubectl --namespace ${CRDB_NAMESPACE} get service cockroachdb-public -o 'jsonpath={.spec.clusterIP}') #kubectl --namespace ${CRDB_NAMESPACE} get service cockroachdb-public -o yaml CRDB_HOST=$(kubectl --namespace ${CRDB_NAMESPACE} get service cockroachdb-public -o 'jsonpath={.spec.clusterIP}') CRDB_PORT=$(kubectl --namespace ${CRDB_NAMESPACE} get service cockroachdb-public -o 'jsonpath={.spec.ports[?(@.name=="sql")].port}') else CRDB_HOST="127.0.0.1" Loading src/common/tests/MockServicerImpl_Context.py +79 −3 Original line number Diff line number Diff line Loading @@ -21,9 +21,11 @@ from common.proto.context_pb2 import ( Device, DeviceEvent, DeviceFilter, DeviceId, DeviceIdList, DeviceList, Empty, EventTypeEnum, Link, LinkEvent, LinkId, LinkIdList, LinkList, OpticalLink, OpticalLinkList, Service, ServiceEvent, ServiceFilter, ServiceId, ServiceIdList, ServiceList, Slice, SliceEvent, SliceFilter, SliceId, SliceIdList, SliceList, Topology, TopologyDetails, TopologyEvent, TopologyId, TopologyIdList, TopologyList) Topology, TopologyDetails, TopologyEvent, TopologyId, TopologyIdList, TopologyList ) from common.proto.context_pb2_grpc import ContextServiceServicer from common.proto.policy_pb2 import PolicyRule, PolicyRuleId, PolicyRuleIdList, PolicyRuleList from common.tools.grpc.Tools import grpc_message_to_json, grpc_message_to_json_string Loading @@ -31,8 +33,10 @@ from common.tools.object_factory.Device import json_device_id from common.tools.object_factory.Link import json_link_id from .InMemoryObjectDatabase import InMemoryObjectDatabase from .MockMessageBroker import ( TOPIC_CONNECTION, TOPIC_CONTEXT, TOPIC_DEVICE, TOPIC_LINK, TOPIC_SERVICE, TOPIC_SLICE, TOPIC_TOPOLOGY, TOPIC_POLICY, MockMessageBroker, notify_event) TOPIC_CONNECTION, TOPIC_CONTEXT, TOPIC_DEVICE, TOPIC_LINK, TOPIC_SERVICE, TOPIC_SLICE, TOPIC_TOPOLOGY, TOPIC_POLICY, MockMessageBroker, notify_event ) LOGGER = logging.getLogger(__name__) Loading Loading @@ -579,6 +583,7 @@ class MockServicerImpl_Context(ContextServiceServicer): LOGGER.debug('[SelectService] reply={:s}'.format(grpc_message_to_json_string(reply))) return reply # ----- Connection ------------------------------------------------------------------------------------------------- def ListConnectionIds(self, request : ServiceId, context : grpc.ServicerContext) -> ConnectionIdList: Loading Loading @@ -628,6 +633,9 @@ class MockServicerImpl_Context(ContextServiceServicer): LOGGER.debug('[GetConnectionEvents] request={:s}'.format(grpc_message_to_json_string(request))) for message in self.msg_broker.consume({TOPIC_CONNECTION}): yield ConnectionEvent(**json.loads(message.content)) # ----- Policy Rule ------------------------------------------------------------------------------------------------ def ListPolicyRuleIds(self, request : Empty, context : grpc.ServicerContext): # pylint: disable=unused-argument LOGGER.debug('[ListPolicyRuleIds] request={:s}'.format(grpc_message_to_json_string(request))) reply = PolicyRuleIdList(policyRuleIdList=[ Loading Loading @@ -666,3 +674,71 @@ class MockServicerImpl_Context(ContextServiceServicer): reply = self._del(request, 'policy', policy_uuid, rule_id_field, TOPIC_CONTEXT, context) LOGGER.debug('[RemovePolicyRule] reply={:s}'.format(grpc_message_to_json_string(reply))) return reply # ----- Optical Link ----------------------------------------------------------------------------------------------- def GetOpticalLinkList(self, request : Empty, context : grpc.ServicerContext) -> OpticalLinkList: LOGGER.debug('[GetOpticalLinkList] request={:s}'.format(grpc_message_to_json_string(request))) reply = OpticalLinkList(optical_links=self.obj_db.get_entries('optical_link')) LOGGER.debug('[GetOpticalLinkList] reply={:s}'.format(grpc_message_to_json_string(reply))) return reply def GetOpticalLink(self, request : LinkId, context : grpc.ServicerContext) -> OpticalLink: LOGGER.debug('[GetOpticalLink] request={:s}'.format(grpc_message_to_json_string(request))) reply = self.obj_db.get_entry('optical_link', request.link_uuid.uuid, context) LOGGER.debug('[GetOpticalLink] reply={:s}'.format(grpc_message_to_json_string(reply))) return reply def SetOpticalLink(self, request : OpticalLink, context : grpc.ServicerContext) -> Empty: LOGGER.debug('[SetOpticalLink] request={:s}'.format(grpc_message_to_json_string(request))) link_uuid = request.link_id.link_uuid.uuid reply, link = self._set(request, 'optical_link', link_uuid, 'link_id', TOPIC_LINK) context_topology_uuids : Set[Tuple[str, str]] = set() context_topology_uuids.add((DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME)) for endpoint_id in link.link_endpoint_ids: endpoint_context_uuid = endpoint_id.topology_id.context_id.context_uuid.uuid if len(endpoint_context_uuid) == 0: endpoint_context_uuid = DEFAULT_CONTEXT_NAME endpoint_topology_uuid = endpoint_id.topology_id.topology_uuid.uuid if len(endpoint_topology_uuid) == 0: endpoint_topology_uuid = DEFAULT_TOPOLOGY_NAME context_topology_uuids.add((endpoint_context_uuid, endpoint_topology_uuid)) for context_uuid,topology_uuid in context_topology_uuids: container_name = 'topology[{:s}]'.format(str(context_uuid)) topology = self.obj_db.get_entry(container_name, topology_uuid, context) for _optical_link_id in topology.optical_link_ids: if _optical_link_id.link_uuid.uuid == link_uuid: break else: # link not found, add it topology.optical_link_ids.add().link_uuid.uuid = link_uuid reply = Empty() LOGGER.debug('[SetOpticalLink] reply={:s}'.format(grpc_message_to_json_string(reply))) return reply def DeleteOpticalLink(self, request : LinkId, context : grpc.ServicerContext) -> Empty: LOGGER.debug('[DeleteOpticalLink] request={:s}'.format(grpc_message_to_json_string(request))) link_uuid = request.link_uuid.uuid optical_link = self.obj_db.get_entry('optical_link', link_uuid, context) reply = self._del(request, 'optical_link', link_uuid, 'link_id', TOPIC_LINK, context) context_topology_uuids : Set[Tuple[str, str]] = set() context_topology_uuids.add((DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME)) for endpoint_id in optical_link.link_endpoint_ids: endpoint_context_uuid = endpoint_id.topology_id.context_id.context_uuid.uuid if len(endpoint_context_uuid) == 0: endpoint_context_uuid = DEFAULT_CONTEXT_NAME endpoint_topology_uuid = endpoint_id.topology_id.topology_uuid.uuid if len(endpoint_topology_uuid) == 0: endpoint_topology_uuid = DEFAULT_TOPOLOGY_NAME context_topology_uuids.add((endpoint_context_uuid, endpoint_topology_uuid)) for context_uuid,topology_uuid in context_topology_uuids: container_name = 'topology[{:s}]'.format(str(context_uuid)) topology = self.obj_db.get_entry(container_name, topology_uuid, context) for optical_link_id in topology.optical_link_ids: if optical_link_id.link_uuid.uuid == link_uuid: topology.optical_link_ids.remove(optical_link_id) break LOGGER.debug('[DeleteOpticalLink] reply={:s}'.format(grpc_message_to_json_string(reply))) return reply Loading
deploy/crdb.sh +2 −3 Original line number Diff line number Diff line Loading @@ -158,9 +158,8 @@ function crdb_drop_databases_single() { echo "Drop TFS databases, if exist" if [[ -z "${GITLAB_CI}" ]]; then kubectl --namespace ${CRDB_NAMESPACE} get service cockroachdb-public -o yaml CRDB_HOST="cockroachdb-0" #CRDB_HOST=$(kubectl --namespace ${CRDB_NAMESPACE} get service cockroachdb-public -o 'jsonpath={.spec.clusterIP}') #kubectl --namespace ${CRDB_NAMESPACE} get service cockroachdb-public -o yaml CRDB_HOST=$(kubectl --namespace ${CRDB_NAMESPACE} get service cockroachdb-public -o 'jsonpath={.spec.clusterIP}') CRDB_PORT=$(kubectl --namespace ${CRDB_NAMESPACE} get service cockroachdb-public -o 'jsonpath={.spec.ports[?(@.name=="sql")].port}') else CRDB_HOST="127.0.0.1" Loading
src/common/tests/MockServicerImpl_Context.py +79 −3 Original line number Diff line number Diff line Loading @@ -21,9 +21,11 @@ from common.proto.context_pb2 import ( Device, DeviceEvent, DeviceFilter, DeviceId, DeviceIdList, DeviceList, Empty, EventTypeEnum, Link, LinkEvent, LinkId, LinkIdList, LinkList, OpticalLink, OpticalLinkList, Service, ServiceEvent, ServiceFilter, ServiceId, ServiceIdList, ServiceList, Slice, SliceEvent, SliceFilter, SliceId, SliceIdList, SliceList, Topology, TopologyDetails, TopologyEvent, TopologyId, TopologyIdList, TopologyList) Topology, TopologyDetails, TopologyEvent, TopologyId, TopologyIdList, TopologyList ) from common.proto.context_pb2_grpc import ContextServiceServicer from common.proto.policy_pb2 import PolicyRule, PolicyRuleId, PolicyRuleIdList, PolicyRuleList from common.tools.grpc.Tools import grpc_message_to_json, grpc_message_to_json_string Loading @@ -31,8 +33,10 @@ from common.tools.object_factory.Device import json_device_id from common.tools.object_factory.Link import json_link_id from .InMemoryObjectDatabase import InMemoryObjectDatabase from .MockMessageBroker import ( TOPIC_CONNECTION, TOPIC_CONTEXT, TOPIC_DEVICE, TOPIC_LINK, TOPIC_SERVICE, TOPIC_SLICE, TOPIC_TOPOLOGY, TOPIC_POLICY, MockMessageBroker, notify_event) TOPIC_CONNECTION, TOPIC_CONTEXT, TOPIC_DEVICE, TOPIC_LINK, TOPIC_SERVICE, TOPIC_SLICE, TOPIC_TOPOLOGY, TOPIC_POLICY, MockMessageBroker, notify_event ) LOGGER = logging.getLogger(__name__) Loading Loading @@ -579,6 +583,7 @@ class MockServicerImpl_Context(ContextServiceServicer): LOGGER.debug('[SelectService] reply={:s}'.format(grpc_message_to_json_string(reply))) return reply # ----- Connection ------------------------------------------------------------------------------------------------- def ListConnectionIds(self, request : ServiceId, context : grpc.ServicerContext) -> ConnectionIdList: Loading Loading @@ -628,6 +633,9 @@ class MockServicerImpl_Context(ContextServiceServicer): LOGGER.debug('[GetConnectionEvents] request={:s}'.format(grpc_message_to_json_string(request))) for message in self.msg_broker.consume({TOPIC_CONNECTION}): yield ConnectionEvent(**json.loads(message.content)) # ----- Policy Rule ------------------------------------------------------------------------------------------------ def ListPolicyRuleIds(self, request : Empty, context : grpc.ServicerContext): # pylint: disable=unused-argument LOGGER.debug('[ListPolicyRuleIds] request={:s}'.format(grpc_message_to_json_string(request))) reply = PolicyRuleIdList(policyRuleIdList=[ Loading Loading @@ -666,3 +674,71 @@ class MockServicerImpl_Context(ContextServiceServicer): reply = self._del(request, 'policy', policy_uuid, rule_id_field, TOPIC_CONTEXT, context) LOGGER.debug('[RemovePolicyRule] reply={:s}'.format(grpc_message_to_json_string(reply))) return reply # ----- Optical Link ----------------------------------------------------------------------------------------------- def GetOpticalLinkList(self, request : Empty, context : grpc.ServicerContext) -> OpticalLinkList: LOGGER.debug('[GetOpticalLinkList] request={:s}'.format(grpc_message_to_json_string(request))) reply = OpticalLinkList(optical_links=self.obj_db.get_entries('optical_link')) LOGGER.debug('[GetOpticalLinkList] reply={:s}'.format(grpc_message_to_json_string(reply))) return reply def GetOpticalLink(self, request : LinkId, context : grpc.ServicerContext) -> OpticalLink: LOGGER.debug('[GetOpticalLink] request={:s}'.format(grpc_message_to_json_string(request))) reply = self.obj_db.get_entry('optical_link', request.link_uuid.uuid, context) LOGGER.debug('[GetOpticalLink] reply={:s}'.format(grpc_message_to_json_string(reply))) return reply def SetOpticalLink(self, request : OpticalLink, context : grpc.ServicerContext) -> Empty: LOGGER.debug('[SetOpticalLink] request={:s}'.format(grpc_message_to_json_string(request))) link_uuid = request.link_id.link_uuid.uuid reply, link = self._set(request, 'optical_link', link_uuid, 'link_id', TOPIC_LINK) context_topology_uuids : Set[Tuple[str, str]] = set() context_topology_uuids.add((DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME)) for endpoint_id in link.link_endpoint_ids: endpoint_context_uuid = endpoint_id.topology_id.context_id.context_uuid.uuid if len(endpoint_context_uuid) == 0: endpoint_context_uuid = DEFAULT_CONTEXT_NAME endpoint_topology_uuid = endpoint_id.topology_id.topology_uuid.uuid if len(endpoint_topology_uuid) == 0: endpoint_topology_uuid = DEFAULT_TOPOLOGY_NAME context_topology_uuids.add((endpoint_context_uuid, endpoint_topology_uuid)) for context_uuid,topology_uuid in context_topology_uuids: container_name = 'topology[{:s}]'.format(str(context_uuid)) topology = self.obj_db.get_entry(container_name, topology_uuid, context) for _optical_link_id in topology.optical_link_ids: if _optical_link_id.link_uuid.uuid == link_uuid: break else: # link not found, add it topology.optical_link_ids.add().link_uuid.uuid = link_uuid reply = Empty() LOGGER.debug('[SetOpticalLink] reply={:s}'.format(grpc_message_to_json_string(reply))) return reply def DeleteOpticalLink(self, request : LinkId, context : grpc.ServicerContext) -> Empty: LOGGER.debug('[DeleteOpticalLink] request={:s}'.format(grpc_message_to_json_string(request))) link_uuid = request.link_uuid.uuid optical_link = self.obj_db.get_entry('optical_link', link_uuid, context) reply = self._del(request, 'optical_link', link_uuid, 'link_id', TOPIC_LINK, context) context_topology_uuids : Set[Tuple[str, str]] = set() context_topology_uuids.add((DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME)) for endpoint_id in optical_link.link_endpoint_ids: endpoint_context_uuid = endpoint_id.topology_id.context_id.context_uuid.uuid if len(endpoint_context_uuid) == 0: endpoint_context_uuid = DEFAULT_CONTEXT_NAME endpoint_topology_uuid = endpoint_id.topology_id.topology_uuid.uuid if len(endpoint_topology_uuid) == 0: endpoint_topology_uuid = DEFAULT_TOPOLOGY_NAME context_topology_uuids.add((endpoint_context_uuid, endpoint_topology_uuid)) for context_uuid,topology_uuid in context_topology_uuids: container_name = 'topology[{:s}]'.format(str(context_uuid)) topology = self.obj_db.get_entry(container_name, topology_uuid, context) for optical_link_id in topology.optical_link_ids: if optical_link_id.link_uuid.uuid == link_uuid: topology.optical_link_ids.remove(optical_link_id) break LOGGER.debug('[DeleteOpticalLink] reply={:s}'.format(grpc_message_to_json_string(reply))) return reply