Commit 10e69712 authored by Waleed Akbar's avatar Waleed Akbar
Browse files

Add telemetry and KPI testing framework with Kubernetes job support

- Added deployment script for Kubernetes with configurable components.
- Implemented fixture methods for context, device, KPI manager, and telemetry clients.
- Added Kubernetes job YAML files for running tests in the tfs namespace.
- Implemented shell scripts to manage the execution of test jobs and log outputs.
- Updated TODO list to reflect progress on telemetry and KPI integration tasks.
parent 8cf56de5
Loading
Loading
Loading
Loading
+1 −13
Original line number Diff line number Diff line
#!/bin/bash
# Copyright 2022-2025 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
# Copyright 2022-2026 ETSI 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.
@@ -13,14 +12,3 @@
# See the License for the specific language governing permissions and
# limitations under the License.

PROJECTDIR=`pwd`
cd $PROJECTDIR/src


# RCFILE=$PROJECTDIR/coverage/.coveragerc
CRDB_SQL_ADDRESS=$(kubectl get service cockroachdb-public --namespace crdb -o 'jsonpath={.spec.clusterIP}')
export CRDB_URI="cockroachdb://tfs:tfs123@${CRDB_SQL_ADDRESS}:26257/tfs_kpi_mgmt?sslmode=require"

python3 -m pytest --log-level=DEBUG --log-cli-level=DEBUG --verbose \
    tests/ecoc26_pluggables/descriptors/kpi_manager/create_kpi_descriptor.py::test_SetKpiDescriptor_PRE_FEC_BER
+2 −4
Original line number Diff line number Diff line
@@ -19,8 +19,7 @@ from common.proto.kpi_sample_types_pb2 import KpiSampleType

def create_kpi_descriptor_PRE_FEC_BER_request():
    _create_kpi_request                                    = kpi_manager_pb2.KpiDescriptor()
    # _create_kpi_request.kpi_id.kpi_id.uuid                 = str(uuid.uuid4())
    _create_kpi_request.kpi_id.kpi_id.uuid                 = "6e22f180-ba28-4641-b190-2287bf448888"
    _create_kpi_request.kpi_id.kpi_id.uuid                 = str(uuid.uuid4())
    _create_kpi_request.kpi_description                    = "Pluggable KPI PRE-FEC BER descriptor for testing purposes"
    _create_kpi_request.kpi_sample_type                    = KpiSampleType.KPISAMPLETYPE_PRE_FEC_BER
    _create_kpi_request.device_id.device_uuid.uuid         = str(uuid.uuid4())  # Add Device UUID here
@@ -28,8 +27,7 @@ def create_kpi_descriptor_PRE_FEC_BER_request():

def create_kpi_descriptor_RECEIVED_POWER_request():
    _create_kpi_request                                    = kpi_manager_pb2.KpiDescriptor()
    # _create_kpi_request.kpi_id.kpi_id.uuid                 = str(uuid.uuid4())
    _create_kpi_request.kpi_id.kpi_id.uuid                 = "6e22f180-ba28-4641-b190-2287bf448888"
    _create_kpi_request.kpi_id.kpi_id.uuid                 = str(uuid.uuid4())
    _create_kpi_request.kpi_description                    = "Pluggable KPI Received power descriptor for testing purposes"
    _create_kpi_request.kpi_sample_type                    = KpiSampleType.KPISAMPLETYPE_RECEIVED_POWER_PLUGGABLE
    _create_kpi_request.device_id.device_uuid.uuid         = str(uuid.uuid4())  # Add Device UUID here
+14 −0
Original line number Diff line number Diff line
# Copyright 2022-2026 ETSI 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.
+36 −0
Original line number Diff line number Diff line
{
    "contexts": [
        {"context_id": {"context_uuid": {"uuid": "admin"}}}
    ],
    "topologies": [
        {"topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}}}
    ],
    "devices": [
        {
            "device_id": {"device_uuid": {"uuid": "IP1"}}, "device_type": "emu-packet-router",
            "device_drivers": ["DEVICEDRIVER_UNDEFINED"], "device_operational_status": "DEVICEOPERATIONALSTATUS_UNDEFINED",
            "device_config": {"config_rules": [
                {"action": "CONFIGACTION_SET", "custom": {"resource_key": "_connect/address",  "resource_value": "127.0.0.1"}},
                {"action": "CONFIGACTION_SET", "custom": {"resource_key": "_connect/port",     "resource_value": "0"        }},
                {"action": "CONFIGACTION_SET", "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [
                    {"uuid": "PORT-xe1", "type": "copper"},
                    {"uuid": "PORT-xe2", "type": "copper"},
                    {"uuid": "PORT-xe3", "type": "copper"}
                ]}}}
            ]}
        },
        {
            "device_id": {"device_uuid": {"uuid": "IP2"}}, "device_type": "emu-packet-router",
            "device_drivers": ["DEVICEDRIVER_UNDEFINED"], "device_operational_status": "DEVICEOPERATIONALSTATUS_UNDEFINED",
            "device_config": {"config_rules": [
                {"action": "CONFIGACTION_SET", "custom": {"resource_key": "_connect/address",  "resource_value": "127.0.0.1"}},
                {"action": "CONFIGACTION_SET", "custom": {"resource_key": "_connect/port",     "resource_value": "0"        }},
                {"action": "CONFIGACTION_SET", "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [
                    {"uuid": "PORT-xe1", "type": "copper"},
                    {"uuid": "PORT-xe2", "type": "copper"},
                    {"uuid": "PORT-xe3", "type": "copper"}
                ]}}}
            ]}
        }
    ]
}
+0 −92
Original line number Diff line number Diff line
import logging
import os, pytest
from typing import Union

from common.Constants import ServiceNameEnum
from common.Settings import ( 
    ENVVAR_SUFIX_SERVICE_HOST, ENVVAR_SUFIX_SERVICE_PORT_GRPC, get_env_var_name, get_service_port_grpc)
from common.tests.MockServicerImpl_Context import MockServicerImpl_Context
from common.proto.context_pb2_grpc import add_ContextServiceServicer_to_server
from common.tools.service.GenericGrpcService import GenericGrpcService

from kpi_manager.service.KpiManagerService import KpiManagerService
from kpi_manager.client.KpiManagerClient import KpiManagerClient
from tests.ecoc26_pluggables.descriptors.Kpi_messages import create_kpi_descriptor_PRE_FEC_BER_request, create_kpi_descriptor_RECEIVED_POWER_request
from common.proto.kpi_manager_pb2 import KpiId


LOGGER = logging.getLogger(__name__)


###########################
# DUMMY KPI SERVICE AND CLIENT FOR TESTING
###########################

LOCAL_HOST = '127.0.0.1'

KPIMANAGER_SERVICE_PORT = get_service_port_grpc(ServiceNameEnum.KPIMANAGER)  # type: ignore
os.environ[get_env_var_name(ServiceNameEnum.KPIMANAGER, ENVVAR_SUFIX_SERVICE_HOST     )] = str(LOCAL_HOST)
os.environ[get_env_var_name(ServiceNameEnum.KPIMANAGER, ENVVAR_SUFIX_SERVICE_PORT_GRPC)] = str(KPIMANAGER_SERVICE_PORT)

LOGGER = logging.getLogger(__name__)

class MockContextService(GenericGrpcService):
    def __init__(self, bind_port: Union[str, int]) -> None:
        super().__init__(bind_port, LOCAL_HOST, enable_health_servicer=False, cls_name='MockService')

    # pylint: disable=attribute-defined-outside-init
    def install_servicers(self):
        self.context_servicer = MockServicerImpl_Context()
        add_ContextServiceServicer_to_server(self.context_servicer, self.server)

@pytest.fixture(scope='session')
def kpi_manager_service():
    LOGGER.info('Initializing KpiManagerService...')
    _service = KpiManagerService()
    _service.start()

    # yield the server, when test finishes, execution will resume to stop it
    LOGGER.info('Yielding KpiManagerService...')
    yield _service

    LOGGER.info('Terminating KpiManagerService...')
    _service.stop()

    LOGGER.info('Terminated KpiManagerService...')


@pytest.fixture(scope='session')
def kpi_manager_client(kpi_manager_service : KpiManagerService): # pylint: disable=redefined-outer-name,unused-argument
    LOGGER.info('Initializing KpiManagerClient...')
    _client = KpiManagerClient()

    # yield the server, when test finishes, execution will resume to stop it
    LOGGER.info('Yielding KpiManagerClient...')
    yield _client

    LOGGER.info('Closing KpiManagerClient...')
    _client.close()

    LOGGER.info('Closed KpiManagerClient...')

##################################################
# Prepare Environment, should be the first test
##################################################


def test_SetKpiDescriptor_PRE_FEC_BER(kpi_manager_client):
    LOGGER.info(" >>> test_SetKpiDescriptor: START <<< ")
    response = kpi_manager_client.SetKpiDescriptor(
        create_kpi_descriptor_PRE_FEC_BER_request()
    )
    LOGGER.info("Response gRPC message object: {:}".format(response))
    assert isinstance(response, KpiId)

def test_SetKpiDescriptor_RECEIVED_POWER(kpi_manager_client):
    LOGGER.info(" >>> test_SetKpiDescriptor: START <<< ")
    response = kpi_manager_client.SetKpiDescriptor(
        create_kpi_descriptor_RECEIVED_POWER_request()
    )
    LOGGER.info("Response gRPC message object: {:}".format(response))
    assert isinstance(response, KpiId)
Loading