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
Loading
Loading
Loading
Loading
+34 −6
Original line number Diff line number Diff line
@@ -70,6 +70,16 @@ 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):
    def __init__(self,
                 service: Service,
@@ -128,11 +138,20 @@ 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)
                    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
                    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 +208,20 @@ 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)
                    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
                    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)
+19 −5
Original line number Diff line number Diff line
@@ -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 response.name == link_uuid
        context_client.SetLink(Link(**link))

def test_devices_bootstrapped(context_client : ContextClient):  # pylint: disable=redefined-outer-name
+7 −26
Original line number Diff line number Diff line
@@ -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:
@@ -72,22 +72,3 @@ def test_rules_entry(
        service_client.CreateService(Service(**service_p4))
        service_p4['service_endpoint_ids'].extend(endpoints)
        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
+0 −7
Original line number Diff line number Diff line
@@ -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))