Commit 99f9e846 authored by Waleed Akbar's avatar Waleed Akbar
Browse files

Refactor KPI and telemetry tests:

- remove obsolete files and add new test cases for KPI descriptors and telemetry collectors
parent 10e69712
Loading
Loading
Loading
Loading
+76 −0
Original line number Diff line number Diff line
@@ -12,24 +12,65 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import uuid
import uuid, random
from common.proto import kpi_manager_pb2
from common.proto import telemetry_frontend_pb2
from common.proto.kpi_sample_types_pb2 import KpiSampleType

KPI_DESCRIPTOR_RECEIVED_POWER_UUID = str(uuid.uuid4())
KPI_DESCRIPTOR_PRE_FEC_BER_UUID    = str(uuid.uuid4())

# create collector UUIDs later ...
COLLECTOR_RECEIVED_POWER_UUID = str(uuid.uuid4())
COLLECTOR_PRE_FEC_BER_UUID    = str(uuid.uuid4())

# Router Device UUID (used in KPI Descriptor creation)
ROUTER_HUB_DEVICE_UUID  = "a79e0852-a603-5200-8de4-aeef1059c27f" # Confirm the order of the device (which one is hub/leaf?)
ROUTER_LEAF_DEVICE_UUID = "ad768743-bafd-598e-b256-de435bee50c2" # Confirm the order of the device (which one is hub/leaf?)

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                 = KPI_DESCRIPTOR_PRE_FEC_BER_UUID
    _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
    _create_kpi_request.device_id.device_uuid.uuid         = ROUTER_LEAF_DEVICE_UUID
    _create_kpi_request.endpoint_id.endpoint_uuid.uuid     = "channel-1"
    return _create_kpi_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                 = KPI_DESCRIPTOR_RECEIVED_POWER_UUID
    _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
    _create_kpi_request.device_id.device_uuid.uuid         = ROUTER_LEAF_DEVICE_UUID
    _create_kpi_request.endpoint_id.endpoint_uuid.uuid     = "channel-1"
    return _create_kpi_request

def create_PRE_FEC_BER_kpi_id_request():
    _create_kpi_id = kpi_manager_pb2.KpiId()
    _create_kpi_id.kpi_id.uuid = KPI_DESCRIPTOR_PRE_FEC_BER_UUID
    return _create_kpi_id

def create_RECEIVED_POWER_kpi_id_request():
    _create_kpi_id = kpi_manager_pb2.KpiId()
    _create_kpi_id.kpi_id.uuid = KPI_DESCRIPTOR_RECEIVED_POWER_UUID
    return _create_kpi_id


# TELEMETRY_COLLECTOR REQUESTS MESAGES

def create_collector_request_received_power():
    _create_collector_request                                = telemetry_frontend_pb2.Collector()
    _create_collector_request.collector_id.collector_id.uuid = COLLECTOR_RECEIVED_POWER_UUID
    _create_collector_request.kpi_id.kpi_id.uuid             = KPI_DESCRIPTOR_RECEIVED_POWER_UUID
    _create_collector_request.duration_s                     = float(random.randint(30, 50))
    _create_collector_request.interval_s                     = float(random.randint(2, 4))
    return _create_collector_request

def create_collector_request_PRE_FEC_BER():
    _create_collector_request                                = telemetry_frontend_pb2.Collector()
    _create_collector_request.collector_id.collector_id.uuid = COLLECTOR_PRE_FEC_BER_UUID
    _create_collector_request.kpi_id.kpi_id.uuid             = KPI_DESCRIPTOR_PRE_FEC_BER_UUID
    _create_collector_request.duration_s                     = float(random.randint(30, 50))
    _create_collector_request.interval_s                     = float(random.randint(2, 4))
    return _create_collector_request
+0 −40
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.

import uuid
import random
from common.proto import telemetry_frontend_pb2


def create_collector_request_received_power():
    _create_collector_request                                = telemetry_frontend_pb2.Collector()
    _create_collector_request.collector_id.collector_id.uuid = str(uuid.uuid4()) 
    # _create_collector_request.collector_id.collector_id.uuid = "efef4d95-1cf1-43c4-9742-95c283dddddd"
    # _create_collector_request.kpi_id.kpi_id.uuid             = str(uuid.uuid4())
    _create_collector_request.kpi_id.kpi_id.uuid             = "a8acbf03-1543-4c6e-9272-ab4623b4b2f2"
    # _create_collector_request.kpi_id.kpi_id.uuid             = "6e22f180-ba28-4641-b190-2287bf447777"
    _create_collector_request.duration_s                     = float(random.randint(30, 50))
    _create_collector_request.interval_s                     = float(random.randint(2, 4))
    return _create_collector_request

def create_collector_request_PRE_FEC_BER():
    _create_collector_request                                = telemetry_frontend_pb2.Collector()
    _create_collector_request.collector_id.collector_id.uuid = str(uuid.uuid4()) 
    # _create_collector_request.collector_id.collector_id.uuid = "efef4d95-1cf1-43c4-9742-95c283ddffff"
    # _create_collector_request.kpi_id.kpi_id.uuid             = str(uuid.uuid4())
    _create_collector_request.kpi_id.kpi_id.uuid             = "b3b7164b-a830-4244-86f4-d8c7fca3aa0e"
    # _create_collector_request.kpi_id.kpi_id.uuid             = "6e22f180-ba28-4641-b190-2287bf448888"
    _create_collector_request.duration_s                     = float(random.randint(30, 50))
    _create_collector_request.interval_s                     = float(random.randint(2, 4))
    return _create_collector_request
+1 −1
Original line number Diff line number Diff line
@@ -144,7 +144,7 @@ export CRDB_PASSWORD="tfs123"
export CRDB_DEPLOY_MODE="single"

# Disable flag for dropping database, if it exists.
export CRDB_DROP_DATABASE_IF_EXISTS=""
export CRDB_DROP_DATABASE_IF_EXISTS="YES"

# Disable flag for re-deploying CockroachDB from scratch.
export CRDB_REDEPLOY=""
+18 −0
Original line number Diff line number Diff line
#!/bin/bash
# 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.

LOG_DIR="$(dirname "$0")/logs"
mkdir -p "${LOG_DIR}"
kubectl --namespace tfs logs deployment/telemetryservice -c backend > "${LOG_DIR}/teleservice_backend_$(date '+%Y%m%d_%H%M').log"
+0 −72
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.
#
# Kubernetes Job: create_kpi_descriptor test
#
# Runs src/tests/ecoc26_pluggables/tests/create_kpi_descriptor.py inside the
# tfs namespace so that Kubernetes service env vars are automatically injected
# (e.g. KPI_MANAGERSERVICE_SERVICE_HOST, KPI_MANAGERSERVICE_SERVICE_PORT_GRPC).
#
# Prerequisites:
#   - The tfs namespace must be deployed (deploy/tfs.sh).
#   - The host path /home/cttc/tfs-ctrl must be accessible on every K8s node
#     (true for single-node MicroK8s).
#
# Usage: see run_create_kpi_descriptor.sh

apiVersion: batch/v1
kind: Job
metadata:
  name: create-kpi-descriptor-test
  namespace: tfs
spec:
  ttlSecondsAfterFinished: 600   # auto-delete the Job 10 min after it finishes
  backoffLimit: 0                # do not retry on failure
  template:
    spec:
      restartPolicy: Never
      containers:
        - name: test-runner
          # Re-use the kpi_manager image: it already has pytest, compiled proto
          # stubs under /var/teraflow/common/proto/, and the KpiManagerClient.
          image: localhost:32000/tfs/kpi_manager:dev
          imagePullPolicy: IfNotPresent
          # Run from the project root so that "src." package imports resolve.
          workingDir: /home/cttc/tfs-ctrl
          command:
            - python
            - -m
            - pytest
            - --log-level=DEBUG
            - --log-cli-level=DEBUG
            - --verbose
            - src/tests/ecoc26_pluggables/tests/create_kpi_descriptor.py
          env:
            # PYTHONPATH resolution order:
            #   1. /var/teraflow              → compiled common.proto stubs,
            #                                   kpi_manager.client, common.Settings
            #   2. /home/cttc/tfs-ctrl/src    → context.client, device.client,
            #                                   telemetry.frontend.client, etc.
            #   3. /home/cttc/tfs-ctrl        → src.tests.ecoc26_pluggables.* imports
            - name: PYTHONPATH
              value: "/var/teraflow:/home/cttc/tfs-ctrl/src:/home/cttc/tfs-ctrl"
          volumeMounts:
            - name: tfs-source
              mountPath: /home/cttc/tfs-ctrl
              readOnly: true
      volumes:
        - name: tfs-source
          hostPath:
            path: /home/cttc/tfs-ctrl
            type: Directory
Loading