Resolve "(CTTC) Extend gNMI-OpenConfig SBI driver"

Closes #89 (closed)

Merge request reports

Loading
+25 −0
Changes for scripts/run_tests_locally-device-gnmi-openconfig.sh: 25 added lines, 0 removed lines.
Original line number Diff line number Diff line
#!/bin/bash
# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


PROJECTDIR=`pwd`

cd $PROJECTDIR/src
RCFILE=$PROJECTDIR/coverage/.coveragerc

# Run unitary tests and analyze coverage of code at same time
# helpful pytest flags: --log-level=INFO -o log_cli=true --verbose --maxfail=1 --durations=0
coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    device/tests/gnmi_openconfig/test_unitary_gnmi_openconfig.py
+25 −0
Changes for scripts/run_tests_locally-device-openconfig-arista-l2vpn.sh: 25 added lines, 0 removed lines.
Original line number Diff line number Diff line
#!/bin/bash
# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


PROJECTDIR=`pwd`

cd $PROJECTDIR/src
RCFILE=$PROJECTDIR/coverage/.coveragerc

# Run unitary tests and analyze coverage of code at same time
# helpful pytest flags: --log-level=INFO -o log_cli=true --verbose --maxfail=1 --durations=0
coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO -o log_cli=true --verbose \
    device/tests/test_unitary_openconfig_arista_l2vpn.py
+2 −1
Changes for src/common/tools/object_factory/EndPoint.py: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -43,13 +43,14 @@ def json_endpoint_ids(

def json_endpoint(
        device_id : Dict, endpoint_uuid : str, endpoint_type : str, topology_id : Optional[Dict] = None,
        kpi_sample_types : List[int] = [], location : Optional[Dict] = None
        name : Optional[str] = None, kpi_sample_types : List[int] = [], location : Optional[Dict] = None
    ):

    result = {
        'endpoint_id': json_endpoint_id(device_id, endpoint_uuid, topology_id=topology_id),
        'endpoint_type': endpoint_type,
    }
    if name is not None: result['name'] = name
    if kpi_sample_types is not None and len(kpi_sample_types) > 0:
        result['kpi_sample_types'] = copy.deepcopy(kpi_sample_types)
    if location is not None:
+31 −24
Changes for src/device/service/drivers/gnmi_openconfig/handlers/Component.py: 31 added lines, 24 removed lines.
Original line number Diff line number Diff line
@@ -12,45 +12,52 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import json, logging, re # libyang
from typing import Any, Dict, List, Tuple
from common.proto.kpi_sample_types_pb2 import KpiSampleType
from ._Handler import _Handler
from .YangHandler import YangHandler

LOGGER = logging.getLogger(__name__)

PATH_IF_CTR = "/interfaces/interface[name={:s}]/state/counters/{:s}"
PATH_IF_CTR = '/openconfig-interfaces:interfaces/interface[name={:s}]/state/counters/{:s}'

#pylint: disable=abstract-method
class ComponentHandler(_Handler):
    def get_resource_key(self) -> str: return '/endpoints/endpoint'
    def get_path(self) -> str: return '/components/component'
    def get_path(self) -> str: return '/openconfig-platform:components'

    def parse(self, json_data : Dict) -> List[Tuple[str, Dict[str, Any]]]:
        #LOGGER.info('json_data = {:s}'.format(json.dumps(json_data)))
        json_component_list : List[Dict] = json_data.get('component', [])
        response = []
        for json_component in json_component_list:
            #LOGGER.info('json_component = {:s}'.format(json.dumps(json_component)))
    def parse(
        self, json_data : Dict, yang_handler : YangHandler
    ) -> List[Tuple[str, Dict[str, Any]]]:
        LOGGER.debug('json_data = {:s}'.format(json.dumps(json_data)))

            endpoint = {}
        yang_components_path = self.get_path()
        json_data_valid = yang_handler.parse_to_dict(yang_components_path, json_data, fmt='json')

            component_type = json_component.get('state', {}).get('type')
            if component_type is None: continue
            component_type = component_type.replace('oc-platform-types:', '')
            component_type = component_type.replace('openconfig-platform-types:', '')
            if component_type not in {'PORT'}: continue
            endpoint['type'] = '-'
        entries = []
        for component in json_data_valid['components']['component']:
            LOGGER.debug('component={:s}'.format(str(component)))

            component_name = component['name']
            #component_config = component.get('config', {})

            #LOGGER.info('PORT json_component = {:s}'.format(json.dumps(json_component)))
            #yang_components : libyang.DContainer = yang_handler.get_data_path(yang_components_path)
            #yang_component_path = 'component[name="{:s}"]'.format(component_name)
            #yang_component : libyang.DContainer = yang_components.create_path(yang_component_path)
            #yang_component.merge_data_dict(component, strict=True, validate=False)

            component_name = json_component.get('name')
            if component_name is None: continue
            component_state = component.get('state', {})
            component_type = component_state.get('type')
            if component_type is None: continue
            component_type = component_type.split(':')[-1]
            if component_type not in {'PORT'}: continue

            # TODO: improve mapping between interface name and component name
            # By now, computed by time for the sake of saving time for the Hackfest.
            interface_name = component_name.lower().replace('-port', '')
            interface_name = re.sub(r'\-[pP][oO][rR][tT]', '', component_name)

            endpoint['uuid'] = interface_name
            endpoint = {'uuid': interface_name, 'type': '-'}
            endpoint['sample_types'] = {
                KpiSampleType.KPISAMPLETYPE_BYTES_RECEIVED     : PATH_IF_CTR.format(interface_name, 'in-octets' ),
                KpiSampleType.KPISAMPLETYPE_BYTES_TRANSMITTED  : PATH_IF_CTR.format(interface_name, 'out-octets'),
@@ -58,6 +65,6 @@ class ComponentHandler(_Handler):
                KpiSampleType.KPISAMPLETYPE_PACKETS_TRANSMITTED: PATH_IF_CTR.format(interface_name, 'out-pkts'  ),
            }

            if len(endpoint) == 0: continue
            response.append(('/endpoints/endpoint[{:s}]'.format(endpoint['uuid']), endpoint))
        return response
            entries.append(('/endpoints/endpoint[{:s}]'.format(endpoint['uuid']), endpoint))

        return entries
+162 −216

File changed.

Preview size limit exceeded, changes collapsed.

Loading
Loading