Commit b8e074b2 authored by Waleed Akbar's avatar Waleed Akbar
Browse files

Add gNMI OpenConfig collector tests and utility functions

- Introduced new test suite for gNMI OpenConfig collector with comprehensive test cases for GET methods.
- Implemented utility functions for managing configurations and checking updates.
- Created storage and tools modules to support test data management and resource composition.
- Removed obsolete test files and JSON topology data to streamline the test structure.
- Added logging for better traceability during test execution.
- Added extra time for context and NBI service to get deployed.
parent f1a182d3
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -33,11 +33,11 @@ VALUES_FILE_PROM="$VALUES_FILE_PATH/prometheus_values.yaml"
# -----------------------------------------------------------
# Mimir Configuration
# -----------------------------------------------------------
RELEASE_NAME_MIMIR="mon-mimir"
CHART_REPO_NAME_MIMIR="grafana"
CHART_REPO_URL_MIMIR="https://grafana.github.io/helm-charts"
CHART_NAME_MIMIR="mimir-distributed"
VALUES_FILE_MIMIR="$VALUES_FILE_PATH/mimir_values.yaml"
# RELEASE_NAME_MIMIR="mon-mimir"
# CHART_REPO_NAME_MIMIR="grafana"
# CHART_REPO_URL_MIMIR="https://grafana.github.io/helm-charts"
# CHART_NAME_MIMIR="mimir-distributed"
# VALUES_FILE_MIMIR="$VALUES_FILE_PATH/mimir_values.yaml"

# -----------------------------------------------------------
# Grafana Configuration
@@ -105,12 +105,12 @@ kubectl rollout status deployment/"$RELEASE_NAME_PROM-server" -n "$NAMESPACE" ||


# 2) Deploy Mimir
deploy_chart "$RELEASE_NAME_MIMIR" \
             "$CHART_REPO_NAME_MIMIR" \
             "$CHART_REPO_URL_MIMIR" \
             "$CHART_NAME_MIMIR" \
             "$VALUES_FILE_MIMIR" \
             "$NAMESPACE"
# deploy_chart "$RELEASE_NAME_MIMIR" \
#              "$CHART_REPO_NAME_MIMIR" \
#              "$CHART_REPO_URL_MIMIR" \
#              "$CHART_NAME_MIMIR" \
#              "$VALUES_FILE_MIMIR" \
#              "$NAMESPACE"

# Depending on how Mimir runs (StatefulSets, Deployments), you can wait for
# the correct resource to be ready. For example:
+6 −0
Original line number Diff line number Diff line
@@ -55,9 +55,15 @@ spec:
          readinessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:1010"]
            initialDelaySeconds: 50   # Context's gunicorn takes 30~40 seconds to bootstrap
            periodSeconds: 10
            failureThreshold: 10
          livenessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:1010"]
            initialDelaySeconds: 50   # Context's gunicorn takes 30~40 seconds to bootstrap
            periodSeconds: 10
            failureThreshold: 10
          resources:
            requests:
              cpu: 250m
+8 −2
Original line number Diff line number Diff line
@@ -49,16 +49,22 @@ spec:
          readinessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:9090"]
            initialDelaySeconds: 50   # NBI's gunicorn takes 30~40 seconds to bootstrap
            periodSeconds: 10
            failureThreshold: 10
          livenessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:9090"]
            initialDelaySeconds: 50   # NBI's gunicorn takes 30~40 seconds to bootstrap
            periodSeconds: 10
            failureThreshold: 10
          resources:
            requests:
              cpu: 50m
              cpu: 128m
              memory: 64Mi
            limits:
              cpu: 500m
              memory: 512Mi
              memory: 1Gi
---
apiVersion: v1
kind: Service
+20 −0
Original line number Diff line number Diff line
# Copyright 2022-2024 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 os

TRUE_VALUES = {'T', 'TRUE', 'YES', '1'}
DEVICE_EMULATED_ONLY = os.environ.get('DEVICE_EMULATED_ONLY')
LOAD_ALL_DEVICE_DRIVERS = (DEVICE_EMULATED_ONLY is None) or (DEVICE_EMULATED_ONLY.upper() not in TRUE_VALUES)
+28 −0
Original line number Diff line number Diff line
@@ -12,39 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest
import logging
from unittest.mock import patch, MagicMock
from src.telemetry.backend.collectors.gnmi_openconfig.GnmiOpenConfigCollector import GnmiOpenConfigCollector

LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)

@pytest.fixture(autouse=True)
def log_all_methods(request):
    LOGGER.info(f" >>>>> Starting test: {request.node.name} ")
    yield
    LOGGER.info(f" <<<<< Finished test: {request.node.name} ")

@pytest.fixture()
def gnmi_openconfig_driver():
    collector = GnmiOpenConfigCollector(
        "192.168.1.1", 
        57400, 
        secure   = True,
        username = "admin",
        password = "secret",
        use_tls  = False
    )
    LOGGER.info("Yielding GnmiOpenConfigCollector collector instance ...")
    yield collector
    LOGGER.info("Terminating GnmiOpenConfigCollector collector instance ...")

# def test_init(gnmi_openconfig_driver):
#     # Test initializing the driver with all parameters
#     driver = gnmi_openconfig_driver
#     assert driver.address == "192.168.1.1"
#     assert driver.port    == 57400


from typing import Any, Dict
from common.proto.context_pb2 import DeviceConfig, ConfigActionEnum


def get_connect_rules(device_config : DeviceConfig) -> Dict[str, Any]:
    connect_rules = dict()
    for config_rule in device_config.config_rules:
        if config_rule.action != ConfigActionEnum.CONFIGACTION_SET: continue
        if config_rule.WhichOneof('config_rule') != 'custom': continue
        if not config_rule.custom.resource_key.startswith('_connect/'): continue
        connect_attribute = config_rule.custom.resource_key.replace('_connect/', '')
        connect_rules[connect_attribute] = config_rule.custom.resource_value
    return connect_rules
Loading