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

Merge branch 'fix/p4' into 'release/2.0.1'

fix: Change p4_service_handler and test scripts for rel2

See merge request !57
parents 1a929de7 c1a712b3
No related branches found
No related tags found
2 merge requests!142Release TeraFlowSDN 2.1,!57fix: Change p4_service_handler and test scripts for rel2
...@@ -47,7 +47,7 @@ def create_rule_set(endpoint_a, endpoint_b): ...@@ -47,7 +47,7 @@ def create_rule_set(endpoint_a, endpoint_b):
} }
] ]
} }
) )
def create_rule_del(endpoint_a, endpoint_b): def create_rule_del(endpoint_a, endpoint_b):
return json_config_rule_delete( return json_config_rule_delete(
...@@ -68,7 +68,17 @@ def create_rule_del(endpoint_a, endpoint_b): ...@@ -68,7 +68,17 @@ def create_rule_del(endpoint_a, endpoint_b):
} }
] ]
} }
) )
def find_names(uuid_a, uuid_b, device_endpoints):
endpoint_a, endpoint_b = None, None
for endpoint in device_endpoints:
if endpoint.endpoint_id.endpoint_uuid.uuid == uuid_a:
endpoint_a = endpoint.name
elif endpoint.endpoint_id.endpoint_uuid.uuid == uuid_b:
endpoint_b = endpoint.name
return (endpoint_a, endpoint_b)
class P4ServiceHandler(_ServiceHandler): class P4ServiceHandler(_ServiceHandler):
def __init__(self, def __init__(self,
...@@ -127,12 +137,21 @@ class P4ServiceHandler(_ServiceHandler): ...@@ -127,12 +137,21 @@ class P4ServiceHandler(_ServiceHandler):
device = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) device = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid)))
del device.device_config.config_rules[:] del device.device_config.config_rules[:]
# Find names from uuids
(endpoint_a, endpoint_b) = find_names(matched_endpoint_uuid, endpoint_uuid, device.device_endpoints)
if endpoint_a is None:
LOGGER.exception('Unable to find name of endpoint({:s})'.format(str(matched_endpoint_uuid)))
raise Exception('Unable to find name of endpoint({:s})'.format(str(matched_endpoint_uuid)))
if endpoint_b is None:
LOGGER.exception('Unable to find name of endpoint({:s})'.format(str(endpoint_uuid)))
raise Exception('Unable to find name of endpoint({:s})'.format(str(endpoint_uuid)))
# One way # One way
rule = create_rule_set(matched_endpoint_uuid, endpoint_uuid) rule = create_rule_set(endpoint_a, endpoint_b)
device.device_config.config_rules.append(ConfigRule(**rule)) device.device_config.config_rules.append(ConfigRule(**rule))
# The other way # The other way
rule = create_rule_set(endpoint_uuid, matched_endpoint_uuid) rule = create_rule_set(endpoint_b, endpoint_a)
device.device_config.config_rules.append(ConfigRule(**rule)) device.device_config.config_rules.append(ConfigRule(**rule))
self.__task_executor.configure_device(device) self.__task_executor.configure_device(device)
...@@ -189,11 +208,20 @@ class P4ServiceHandler(_ServiceHandler): ...@@ -189,11 +208,20 @@ class P4ServiceHandler(_ServiceHandler):
del device.device_config.config_rules[:] del device.device_config.config_rules[:]
# Find names from uuids
(endpoint_a, endpoint_b) = find_names(matched_endpoint_uuid, endpoint_uuid, device.device_endpoints)
if endpoint_a is None:
LOGGER.exception('Unable to find name of endpoint({:s})'.format(str(matched_endpoint_uuid)))
raise Exception('Unable to find name of endpoint({:s})'.format(str(matched_endpoint_uuid)))
if endpoint_b is None:
LOGGER.exception('Unable to find name of endpoint({:s})'.format(str(endpoint_uuid)))
raise Exception('Unable to find name of endpoint({:s})'.format(str(endpoint_uuid)))
# One way # One way
rule = create_rule_del(matched_endpoint_uuid, endpoint_uuid) rule = create_rule_del(endpoint_a, endpoint_b)
device.device_config.config_rules.append(ConfigRule(**rule)) device.device_config.config_rules.append(ConfigRule(**rule))
# The other way # The other way
rule = create_rule_del(endpoint_uuid, matched_endpoint_uuid) rule = create_rule_del(endpoint_b, endpoint_a)
device.device_config.config_rules.append(ConfigRule(**rule)) device.device_config.config_rules.append(ConfigRule(**rule))
self.__task_executor.configure_device(device) self.__task_executor.configure_device(device)
......
...@@ -25,6 +25,10 @@ from common.proto.context_pb2 import ConfigActionEnum, Context, ContextId, Devic ...@@ -25,6 +25,10 @@ from common.proto.context_pb2 import ConfigActionEnum, Context, ContextId, Devic
from device.client.DeviceClient import DeviceClient from device.client.DeviceClient import DeviceClient
from .Objects import CONTEXT_ID, CONTEXTS, DEVICES, LINKS, TOPOLOGIES from .Objects import CONTEXT_ID, CONTEXTS, DEVICES, LINKS, TOPOLOGIES
from common.tools.object_factory.ConfigRule import (
json_config_rule_set, json_config_rule_delete)
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG) LOGGER.setLevel(logging.DEBUG)
...@@ -48,15 +52,18 @@ def test_prepare_scenario(context_client : ContextClient): # pylint: disable=re ...@@ -48,15 +52,18 @@ def test_prepare_scenario(context_client : ContextClient): # pylint: disable=re
context_uuid = context['context_id']['context_uuid']['uuid'] context_uuid = context['context_id']['context_uuid']['uuid']
LOGGER.info('Adding Context {:s}'.format(context_uuid)) LOGGER.info('Adding Context {:s}'.format(context_uuid))
response = context_client.SetContext(Context(**context)) response = context_client.SetContext(Context(**context))
assert response.context_uuid.uuid == context_uuid context_data = context_client.GetContext(response)
assert context_data.name == context_uuid
for topology in TOPOLOGIES: for topology in TOPOLOGIES:
context_uuid = topology['topology_id']['context_id']['context_uuid']['uuid'] context_uuid = topology['topology_id']['context_id']['context_uuid']['uuid']
topology_uuid = topology['topology_id']['topology_uuid']['uuid'] topology_uuid = topology['topology_id']['topology_uuid']['uuid']
LOGGER.info('Adding Topology {:s}/{:s}'.format(context_uuid, topology_uuid)) LOGGER.info('Adding Topology {:s}/{:s}'.format(context_uuid, topology_uuid))
response = context_client.SetTopology(Topology(**topology)) response = context_client.SetTopology(Topology(**topology))
assert response.context_id.context_uuid.uuid == context_uuid # assert response.context_id.context_uuid.uuid == context_uuid
assert response.topology_uuid.uuid == topology_uuid
topology_data = context_client.GetTopology(response)
assert topology_data.name == topology_uuid
context_id = json_context_id(context_uuid) context_id = json_context_id(context_uuid)
...@@ -81,18 +88,25 @@ def test_devices_bootstraping( ...@@ -81,18 +88,25 @@ def test_devices_bootstraping(
device_p4_with_connect_rules = copy.deepcopy(device) device_p4_with_connect_rules = copy.deepcopy(device)
device_p4_with_connect_rules['device_config']['config_rules'].extend(connect_rules) device_p4_with_connect_rules['device_config']['config_rules'].extend(connect_rules)
device_p4_with_connect_rules['device_operational_status'] = \
DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED
response = device_client.AddDevice(Device(**device_p4_with_connect_rules)) response = device_client.AddDevice(Device(**device_p4_with_connect_rules))
assert response.device_uuid.uuid == device_uuid
LOGGER.info('Adding Device {:s}'.format(device_uuid))
device_p4_with_endpoints = copy.deepcopy(device) device_p4_with_endpoints = copy.deepcopy(device)
device_p4_with_endpoints['device_id']['device_uuid']['uuid'] = response.device_uuid.uuid
device_p4_with_endpoints['device_endpoints'].extend(endpoints) device_p4_with_endpoints['device_endpoints'].extend(endpoints)
for i in device_p4_with_endpoints['device_endpoints']:
i['endpoint_id']['device_id']['device_uuid']['uuid'] = response.device_uuid.uuid
LOGGER.info('Adding Endpoints {:s}'.format(device_uuid))
device_client.ConfigureDevice(Device(**device_p4_with_endpoints)) device_client.ConfigureDevice(Device(**device_p4_with_endpoints))
for link in LINKS: for link in LINKS:
link_uuid = link['link_id']['link_uuid']['uuid'] link_uuid = link['link_id']['link_uuid']['uuid']
LOGGER.info('Adding Link {:s}'.format(link_uuid)) LOGGER.info('Adding Link {:s}'.format(link_uuid))
response = context_client.SetLink(Link(**link)) response = context_client.SetLink(Link(**link))
assert response.link_uuid.uuid == link_uuid assert response.name == link_uuid
context_client.SetLink(Link(**link)) context_client.SetLink(Link(**link))
def test_devices_bootstrapped(context_client : ContextClient): # pylint: disable=redefined-outer-name def test_devices_bootstrapped(context_client : ContextClient): # pylint: disable=redefined-outer-name
......
...@@ -56,12 +56,12 @@ def test_rules_entry( ...@@ -56,12 +56,12 @@ def test_rules_entry(
for device, _, __ in DEVICES: # for device, _, __ in DEVICES:
# Enable device # # Enable device
device_p4_with_operational_status = copy.deepcopy(device) # device_p4_with_operational_status = copy.deepcopy(device)
device_p4_with_operational_status['device_operational_status'] = \ # device_p4_with_operational_status['device_operational_status'] = \
DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED # DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED
device_client.ConfigureDevice(Device(**device_p4_with_operational_status)) # device_client.ConfigureDevice(Device(**device_p4_with_operational_status))
# ----- Create Services --------------------------------------------------------------- # ----- Create Services ---------------------------------------------------------------
for service, endpoints in SERVICES: for service, endpoints in SERVICES:
...@@ -71,23 +71,4 @@ def test_rules_entry( ...@@ -71,23 +71,4 @@ def test_rules_entry(
service_p4 = copy.deepcopy(service) service_p4 = copy.deepcopy(service)
service_client.CreateService(Service(**service_p4)) service_client.CreateService(Service(**service_p4))
service_p4['service_endpoint_ids'].extend(endpoints) service_p4['service_endpoint_ids'].extend(endpoints)
service_client.UpdateService(Service(**service_p4)) service_client.UpdateService(Service(**service_p4))
\ No newline at end of file
"""
con_cl = ContextClient(get_setting('CONTEXTSERVICE_SERVICE_HOST'), get_setting('CONTEXTSERVICE_SERVICE_PORT_GRPC'))
dev_cl = DeviceClient(get_setting('DEVICESERVICE_SERVICE_HOST'), get_setting('DEVICESERVICE_SERVICE_PORT_GRPC'))
srv_cl = ServiceClient(get_setting('SERVICESERVICE_SERVICE_HOST'), get_setting('SERVICESERVICE_SERVICE_PORT_GRPC'))
for service, endpoints in SERVICES:
service_uuid = service['service_id']['service_uuid']['uuid']
print('Creating Service {:s}'.format(service_uuid))
service_p4 = copy.deepcopy(service)
srv_cl.CreateService(Service(**service_p4))
#service_data = con_cl.GetService(ServiceId(**json_service_id('svc1')))
#print('service_data = {:s}'.format(grpc_message_to_json_string(service_data)))
service_p4 = copy.deepcopy(service)
service_p4['service_endpoint_ids'].extend(endpoints)
srv_cl.UpdateService(Service(**service_p4))
"""
\ No newline at end of file
...@@ -60,10 +60,3 @@ def test_rules_delete( ...@@ -60,10 +60,3 @@ def test_rules_delete(
print('Deleting Service {:s}'.format(service_uuid)) print('Deleting Service {:s}'.format(service_uuid))
service_p4 = copy.deepcopy(service) service_p4 = copy.deepcopy(service)
response = service_client.DeleteService(ServiceId(**json_service_id(service_uuid, CONTEXT_ID))) response = service_client.DeleteService(ServiceId(**json_service_id(service_uuid, CONTEXT_ID)))
# ----- Disable Devices ---------------------------------------------------------------
for device, _, _ in DEVICES:
device_p4_with_operational_status = copy.deepcopy(device)
device_p4_with_operational_status['device_operational_status'] = \
DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_DISABLED
device_client.ConfigureDevice(Device(**device_p4_with_operational_status))
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