From a456cb20f8f6d68c8bf184042d8f10d8d217da05 Mon Sep 17 00:00:00 2001 From: Panagiotis Famelis Date: Wed, 8 Feb 2023 16:27:03 +0200 Subject: [PATCH] fix: Change p4_service_handler and test scripts for rel2 --- .../service_handlers/p4/p4_service_handler.py | 27 +++++++++++---- .../p4/tests/test_functional_bootstrap.py | 24 +++++++++++--- .../tests/test_functional_create_service.py | 33 ++++--------------- .../tests/test_functional_delete_service.py | 7 ---- 4 files changed, 47 insertions(+), 44 deletions(-) diff --git a/src/service/service/service_handlers/p4/p4_service_handler.py b/src/service/service/service_handlers/p4/p4_service_handler.py index 500c50378..b068e0776 100644 --- a/src/service/service/service_handlers/p4/p4_service_handler.py +++ b/src/service/service/service_handlers/p4/p4_service_handler.py @@ -47,7 +47,7 @@ def create_rule_set(endpoint_a, endpoint_b): } ] } -) + ) def create_rule_del(endpoint_a, endpoint_b): return json_config_rule_delete( @@ -68,7 +68,16 @@ def create_rule_del(endpoint_a, endpoint_b): } ] } -) + ) + +def find_names(uuid_a, uuid_b, device_endpoints): + 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): def __init__(self, @@ -127,12 +136,15 @@ class P4ServiceHandler(_ServiceHandler): device = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) del device.device_config.config_rules[:] + + # Find names from uuids + (endpoint_a, endpoint_b) = find_names(matched_endpoint_uuid, endpoint_uuid, device.device_endpoints) # 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)) # 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)) self.__task_executor.configure_device(device) @@ -189,11 +201,14 @@ class P4ServiceHandler(_ServiceHandler): del device.device_config.config_rules[:] + # Find names from uuids + (endpoint_a, endpoint_b) = find_names(matched_endpoint_uuid, endpoint_uuid, device.device_endpoints) + # 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)) # 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)) self.__task_executor.configure_device(device) diff --git a/src/tests/p4/tests/test_functional_bootstrap.py b/src/tests/p4/tests/test_functional_bootstrap.py index 11b24adf1..c2a2837ab 100644 --- a/src/tests/p4/tests/test_functional_bootstrap.py +++ b/src/tests/p4/tests/test_functional_bootstrap.py @@ -25,6 +25,10 @@ from common.proto.context_pb2 import ConfigActionEnum, Context, ContextId, Devic from device.client.DeviceClient import DeviceClient 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.setLevel(logging.DEBUG) @@ -48,15 +52,18 @@ def test_prepare_scenario(context_client : ContextClient): # pylint: disable=re context_uuid = context['context_id']['context_uuid']['uuid'] LOGGER.info('Adding Context {:s}'.format(context_uuid)) 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: context_uuid = topology['topology_id']['context_id']['context_uuid']['uuid'] topology_uuid = topology['topology_id']['topology_uuid']['uuid'] LOGGER.info('Adding Topology {:s}/{:s}'.format(context_uuid, topology_uuid)) response = context_client.SetTopology(Topology(**topology)) - assert response.context_id.context_uuid.uuid == context_uuid - assert response.topology_uuid.uuid == topology_uuid +# assert response.context_id.context_uuid.uuid == context_uuid + + topology_data = context_client.GetTopology(response) + assert topology_data.name == topology_uuid context_id = json_context_id(context_uuid) @@ -81,18 +88,25 @@ def test_devices_bootstraping( 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_operational_status'] = \ + DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED 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['device_id']['device_uuid']['uuid'] = response.device_uuid.uuid 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)) for link in LINKS: link_uuid = link['link_id']['link_uuid']['uuid'] LOGGER.info('Adding Link {:s}'.format(link_uuid)) response = context_client.SetLink(Link(**link)) - assert response.link_uuid.uuid == link_uuid + assert link_uuid == link_uuid context_client.SetLink(Link(**link)) def test_devices_bootstrapped(context_client : ContextClient): # pylint: disable=redefined-outer-name diff --git a/src/tests/p4/tests/test_functional_create_service.py b/src/tests/p4/tests/test_functional_create_service.py index f160d3c6f..beaa23ba3 100644 --- a/src/tests/p4/tests/test_functional_create_service.py +++ b/src/tests/p4/tests/test_functional_create_service.py @@ -56,12 +56,12 @@ def test_rules_entry( - for device, _, __ in DEVICES: - # Enable device - device_p4_with_operational_status = copy.deepcopy(device) - device_p4_with_operational_status['device_operational_status'] = \ - DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED - device_client.ConfigureDevice(Device(**device_p4_with_operational_status)) +# for device, _, __ in DEVICES: +# # Enable device +# device_p4_with_operational_status = copy.deepcopy(device) +# device_p4_with_operational_status['device_operational_status'] = \ +# DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED +# device_client.ConfigureDevice(Device(**device_p4_with_operational_status)) # ----- Create Services --------------------------------------------------------------- for service, endpoints in SERVICES: @@ -71,23 +71,4 @@ def test_rules_entry( service_p4 = copy.deepcopy(service) service_client.CreateService(Service(**service_p4)) service_p4['service_endpoint_ids'].extend(endpoints) - service_client.UpdateService(Service(**service_p4)) - - - -""" -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 + service_client.UpdateService(Service(**service_p4)) \ No newline at end of file diff --git a/src/tests/p4/tests/test_functional_delete_service.py b/src/tests/p4/tests/test_functional_delete_service.py index 4d637cf88..c5821df4c 100644 --- a/src/tests/p4/tests/test_functional_delete_service.py +++ b/src/tests/p4/tests/test_functional_delete_service.py @@ -60,10 +60,3 @@ def test_rules_delete( print('Deleting Service {:s}'.format(service_uuid)) service_p4 = copy.deepcopy(service) 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)) -- GitLab