Skip to content
Snippets Groups Projects
Commit 04f63033 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Common - Tests - Mock Context:

- Added merge of device_ids and link_ids in Topology
parent fe92a91c
No related branches found
No related tags found
2 merge requests!235Release TeraFlowSDN 3.0,!173Resolve "(CTTC) Implement NBI connector IETF Network Topology"
...@@ -26,6 +26,8 @@ from common.proto.context_pb2 import ( ...@@ -26,6 +26,8 @@ from common.proto.context_pb2 import (
Topology, TopologyDetails, 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.tools.grpc.Tools import grpc_message_to_json, grpc_message_to_json_string from common.tools.grpc.Tools import grpc_message_to_json, grpc_message_to_json_string
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 .InMemoryObjectDatabase import InMemoryObjectDatabase
from .MockMessageBroker import ( from .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,
...@@ -146,6 +148,32 @@ class MockServicerImpl_Context(ContextServiceServicer): ...@@ -146,6 +148,32 @@ class MockServicerImpl_Context(ContextServiceServicer):
context_uuid = str(request.topology_id.context_id.context_uuid.uuid) context_uuid = str(request.topology_id.context_id.context_uuid.uuid)
container_name = 'topology[{:s}]'.format(context_uuid) container_name = 'topology[{:s}]'.format(context_uuid)
topology_uuid = request.topology_id.topology_uuid.uuid topology_uuid = request.topology_id.topology_uuid.uuid
if self.obj_db.has_entry(container_name, topology_uuid):
# merge device_ids and link_ids from database and request, and update request
db_topology = self.obj_db.get_entry(container_name, topology_uuid, context)
device_uuids = set()
for device_id in request.device_ids: device_uuids.add(device_id.device_uuid.uuid)
for device_id in db_topology.device_ids: device_uuids.add(device_id.device_uuid.uuid)
link_uuids = set()
for link_id in request.link_ids: link_uuids.add(link_id.link_uuid.uuid)
for link_id in db_topology.link_ids: link_uuids.add(link_id.link_uuid.uuid)
rw_request = Topology()
rw_request.CopyFrom(request)
del rw_request.device_ids[:]
for device_uuid in sorted(device_uuids):
rw_request.device_ids.append(DeviceId(**json_device_id(device_uuid)))
del rw_request.link_ids[:]
for link_uuid in sorted(link_uuids):
rw_request.link_ids.append(LinkId(**json_link_id(link_uuid)))
request = rw_request
reply,_ = self._set(request, container_name, topology_uuid, 'topology_id', TOPIC_TOPOLOGY) reply,_ = self._set(request, container_name, topology_uuid, 'topology_id', TOPIC_TOPOLOGY)
context_ = self.obj_db.get_entry('context', context_uuid, context) context_ = self.obj_db.get_entry('context', context_uuid, context)
......
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