99"""
1010Launch tests in Viavi
1111"""
12-
1312import logging
13+ import operator
1414from dataclasses import dataclass
1515from enum import Enum
1616from pathlib import Path
17- from typing import Optional
17+ from typing import Callable , Optional
1818
1919import pytest
2020from pytest import mark , param
2929from retina .viavi .client import CampaignStatusEnum , Viavi
3030
3131from .steps .configuration import configure_metric_server_for_gnb
32- from .steps .stub import GNB_STARTUP_TIMEOUT , handle_start_error , stop
32+ from .steps .stub import get_metrics , GNB_STARTUP_TIMEOUT , GnbMetrics , handle_start_error , stop
3333
3434CAMPAIGN_FILENAME = "C:\\ ci\\ CI 4x4 ORAN-FH.xml"
3535_OMIT_VIAVI_FAILURE_LIST = ["authentication" ]
@@ -50,10 +50,12 @@ class _ViaviConfiguration:
5050 Viavi configuration
5151 """
5252
53- max_pdschs_per_slot : int
54- max_puschs_per_slot : int
55- enable_qos_viavi : bool
56- warning_as_errors : bool
53+ max_pdschs_per_slot : int = 1
54+ max_puschs_per_slot : int = 1
55+ enable_qos_viavi : bool = False
56+ warning_as_errors : bool = True
57+ expected_ul_bitrate : float = 0
58+ expected_dl_bitrate : float = 0
5759
5860
5961@pytest .fixture
@@ -244,7 +246,6 @@ def test_viavi_debug(
244246 log_search = log_search ,
245247 post_commands = post_commands ,
246248 warning_as_errors = False ,
247- fail_if_kos = False ,
248249 )
249250
250251
@@ -349,7 +350,7 @@ def _test_viavi(
349350 gnb_stop_timeout = gnb_stop_timeout ,
350351 log_search = log_search ,
351352 warning_as_errors = test_configuration .warning_as_errors ,
352- fail_if_kos = fail_if_kos ,
353+ fail_if_kos = False ,
353354 )
354355
355356 # This except and the finally should be inside the request, but the campaign_name makes it complicated
@@ -365,15 +366,52 @@ def _test_viavi(
365366 logging .info ("Folder with Viavi report: %s" , report_folder )
366367 logging .info ("Downloading Viavi report" )
367368 viavi .download_directory (report_folder , Path (test_log_folder ).joinpath ("viavi" ))
368- viavi_failure_manager = viavi .get_test_failures ()
369- if viavi_failure_manager .get_number_of_failures (_OMIT_VIAVI_FAILURE_LIST ) > 0 :
370- nof_failures = viavi_failure_manager .get_number_of_failures (_OMIT_VIAVI_FAILURE_LIST )
371- viavi_failure_manager .print_failures (_OMIT_VIAVI_FAILURE_LIST )
372- pytest .fail (f"Viavi Test Failed with { nof_failures } failures" )
369+ run_check_fail_criteria (test_configuration , gnb , viavi , fail_if_kos )
373370 except HTTPError :
374371 logging .error ("Viavi Reports could not be downloaded" )
375372
376373
374+ def run_check_fail_criteria (test_configuration : _ViaviConfiguration , gnb : GNBStub , viavi : Viavi , fail_if_kos : bool ):
375+ """
376+ Check pass/fail criteria
377+ """
378+
379+ is_ok = True
380+
381+ # Check metrics
382+ gnb_metrics : GnbMetrics = get_metrics (gnb )
383+
384+ is_ok &= check_and_print_criteria (
385+ "DL bitrate" , gnb_metrics .dl_brate_agregate , test_configuration .expected_dl_bitrate , operator .gt
386+ )
387+ is_ok &= check_and_print_criteria (
388+ "UL bitrate" , gnb_metrics .ul_brate_agregate , test_configuration .expected_ul_bitrate , operator .gt
389+ )
390+ is_ok &= (
391+ check_and_print_criteria ("Number of KOs and/or retrxs" , gnb_metrics .nof_kos_aggregate , 0 , operator .eq )
392+ and not fail_if_kos
393+ )
394+
395+ # Check procedure table
396+ viavi_failure_manager = viavi .get_test_failures ()
397+ viavi_failure_manager .print_failures (_OMIT_VIAVI_FAILURE_LIST )
398+ is_ok &= viavi_failure_manager .get_number_of_failures (_OMIT_VIAVI_FAILURE_LIST ) > 0
399+
400+ if not is_ok :
401+ pytest .fail ("Test didn't pass all the criteria" )
402+
403+
404+ def check_and_print_criteria (
405+ name : str , current : float , expected : float , operator_method : Callable [[float , float ], bool ]
406+ ) -> bool :
407+ """
408+ Check and print criteria
409+ """
410+ is_ok = operator_method (current , expected )
411+ (logging .info if is_ok else logging .error )(f"{ name } expected: { expected } , actual: { current } " )
412+ return is_ok
413+
414+
377415def get_viavi_configuration (test_name : str , warning_as_errors : bool ) -> _ViaviConfiguration :
378416 """
379417 Get Viavi configuration
@@ -384,12 +422,16 @@ def get_viavi_configuration(test_name: str, warning_as_errors: bool) -> _ViaviCo
384422 max_puschs_per_slot = 8 ,
385423 enable_qos_viavi = False ,
386424 warning_as_errors = warning_as_errors ,
425+ expected_dl_bitrate = 80e6 ,
426+ expected_ul_bitrate = 80e6 ,
387427 )
388428 if test_name == _TestName .UE32_STATIC_DL_UL_UDP .value :
389429 return _ViaviConfiguration (
390430 max_pdschs_per_slot = 1 ,
391431 max_puschs_per_slot = 1 ,
392432 enable_qos_viavi = False ,
393433 warning_as_errors = warning_as_errors ,
434+ expected_dl_bitrate = 80e6 ,
435+ expected_ul_bitrate = 80e6 ,
394436 )
395437 raise ValueError (f"Test name { test_name } not supported" )
0 commit comments