Skip to content

Commit baf394f

Browse files
author
qarlosalberto
committed
ci: resume criteria in viavi test
1 parent bcfcef4 commit baf394f

File tree

3 files changed

+113
-20
lines changed

3 files changed

+113
-20
lines changed

tests/e2e/tests/steps/kpis.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ def get_kpis(
8181
dl_nof_ko_aggregate += ue_info.dl_nof_ko
8282
kpis.nof_ko_aggregate += ue_info.ul_nof_ko + ue_info.dl_nof_ko
8383

84-
kpis.ul_bler_aggregate = ul_nof_ko_aggregate / (ul_nof_ok_aggregate + ul_nof_ko_aggregate)
85-
kpis.dl_bler_aggregate = dl_nof_ko_aggregate / (dl_nof_ok_aggregate + dl_nof_ko_aggregate)
84+
tota_ul_ko_ok = ul_nof_ok_aggregate + ul_nof_ko_aggregate
85+
total_dl_ko_ok = dl_nof_ok_aggregate + dl_nof_ko_aggregate
86+
87+
kpis.ul_bler_aggregate = 0 if not tota_ul_ko_ok else ul_nof_ko_aggregate / tota_ul_ko_ok
88+
kpis.dl_bler_aggregate = 0 if not total_dl_ko_ok else dl_nof_ko_aggregate / total_dl_ko_ok
8689

8790
# UE
8891
for ue in ue_array:

tests/e2e/tests/steps/stub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ def _get_metrics_msg(stub: RanStub, name: str, fail_if_kos: bool = False) -> str
714714
nof_kos = 0
715715
for ue_info in metrics.ue_array:
716716
nof_kos = ue_info.dl_nof_ko + ue_info.ul_nof_ko
717-
if nof_kos:
717+
if nof_kos and fail_if_kos:
718718
return f"{name} has {nof_kos} KOs / retrxs"
719719

720720
return ""

tests/e2e/tests/viavi.py

Lines changed: 107 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
from retina.protocol.gnb_pb2 import GNBStartInfo
2828
from retina.protocol.gnb_pb2_grpc import GNBStub
2929
from retina.viavi.client import CampaignStatusEnum, Viavi
30+
from rich.console import Console
31+
from rich.table import Table
3032

3133
from .steps.configuration import configure_metric_server_for_gnb
3234
from .steps.kpis import get_kpis, KPIs
@@ -58,6 +60,19 @@ class _ViaviConfiguration:
5860
warning_as_errors: bool = True
5961

6062

63+
# pylint: disable=too-many-instance-attributes
64+
@dataclass
65+
class _ViaviResult:
66+
"""
67+
Viavi result
68+
"""
69+
70+
criteria_name: str
71+
expected: float
72+
current: float
73+
is_ok: bool
74+
75+
6176
def load_yaml_config(config_filename: str) -> List[_ViaviConfiguration]:
6277
"""
6378
Load yaml config
@@ -117,6 +132,7 @@ def viavi_manual_test_timeout(request):
117132
@mark.viavi_manual
118133
# pylint: disable=too-many-arguments, too-many-locals
119134
def test_viavi_manual(
135+
capsys: pytest.CaptureFixture[str],
120136
# Retina
121137
retina_manager: RetinaTestManager,
122138
retina_data: RetinaTestData,
@@ -142,6 +158,7 @@ def test_viavi_manual(
142158
)
143159

144160
_test_viavi(
161+
capsys=capsys,
145162
# Retina
146163
retina_manager=retina_manager,
147164
retina_data=retina_data,
@@ -178,6 +195,7 @@ def test_viavi_manual(
178195
)
179196
# pylint: disable=too-many-arguments, too-many-locals
180197
def test_viavi(
198+
capsys: pytest.CaptureFixture[str],
181199
# Retina
182200
retina_manager: RetinaTestManager,
183201
retina_data: RetinaTestData,
@@ -199,6 +217,7 @@ def test_viavi(
199217
Runs a test using Viavi
200218
"""
201219
_test_viavi(
220+
capsys=capsys,
202221
# Retina
203222
retina_manager=retina_manager,
204223
retina_data=retina_data,
@@ -232,6 +251,7 @@ def test_viavi(
232251
)
233252
# pylint: disable=too-many-arguments, too-many-locals
234253
def test_viavi_debug(
254+
capsys: pytest.CaptureFixture[str],
235255
# Retina
236256
retina_manager: RetinaTestManager,
237257
retina_data: RetinaTestData,
@@ -253,6 +273,7 @@ def test_viavi_debug(
253273
Runs a test using Viavi
254274
"""
255275
_test_viavi(
276+
capsys=capsys,
256277
# Retina
257278
retina_manager=retina_manager,
258279
retina_data=retina_data,
@@ -274,6 +295,7 @@ def test_viavi_debug(
274295

275296
# pylint: disable=too-many-arguments, too-many-locals
276297
def _test_viavi(
298+
capsys: pytest.CaptureFixture[str],
277299
# Retina
278300
retina_manager: RetinaTestManager,
279301
retina_data: RetinaTestData,
@@ -384,7 +406,7 @@ def _test_viavi(
384406
logging.info("Folder with Viavi report: %s", report_folder)
385407
logging.info("Downloading Viavi report")
386408
viavi.download_directory(report_folder, Path(test_log_folder).joinpath("viavi"))
387-
check_metrics_criteria(test_declaration, gnb, viavi, metrics_summary, test_declaration.fail_if_kos)
409+
check_metrics_criteria(test_declaration, gnb, viavi, metrics_summary, test_declaration.fail_if_kos, capsys)
388410
except HTTPError:
389411
logging.error("Viavi Reports could not be downloaded")
390412

@@ -398,6 +420,7 @@ def check_metrics_criteria(
398420
viavi: Viavi,
399421
metrics_summary: Optional[MetricsSummary],
400422
fail_if_kos: bool,
423+
capsys: pytest.CaptureFixture[str],
401424
):
402425
"""
403426
Check pass/fail criteria
@@ -409,42 +432,109 @@ def check_metrics_criteria(
409432
viavi_failure_manager = viavi.get_test_failures()
410433
kpis: KPIs = get_kpis(gnb, viavi_failure_manager=viavi_failure_manager, metrics_summary=metrics_summary)
411434

412-
is_ok &= check_and_print_criteria(
413-
"DL bitrate", kpis.dl_brate_aggregate, test_configuration.expected_dl_bitrate, operator.gt, False
435+
criteria_result: List[_ViaviResult] = []
436+
criteria_dl_brate_aggregate = check_criteria(
437+
kpis.dl_brate_aggregate, test_configuration.expected_dl_bitrate, operator.gt
414438
)
415-
is_ok &= check_and_print_criteria(
416-
"UL bitrate", kpis.ul_brate_aggregate, test_configuration.expected_ul_bitrate, operator.gt, False
439+
criteria_result.append(
440+
_ViaviResult(
441+
"DL bitrate", test_configuration.expected_dl_bitrate, kpis.dl_brate_aggregate, criteria_dl_brate_aggregate
442+
)
417443
)
418-
is_ok &= (
419-
check_and_print_criteria("Number of KOs and/or retrxs", kpis.nof_ko_aggregate, 0, operator.eq, not fail_if_kos)
420-
or not fail_if_kos
444+
445+
criteria_ul_brate_aggregate = check_criteria(
446+
kpis.ul_brate_aggregate, test_configuration.expected_ul_bitrate, operator.gt
447+
)
448+
criteria_result.append(
449+
_ViaviResult(
450+
"UL bitrate", test_configuration.expected_ul_bitrate, kpis.ul_brate_aggregate, criteria_ul_brate_aggregate
451+
)
452+
)
453+
454+
criteria_nof_ko_aggregate = check_criteria(kpis.nof_ko_aggregate, 0, operator.eq) or not fail_if_kos
455+
criteria_result.append(
456+
_ViaviResult("Number of KOs and/or retrxs", 0, kpis.nof_ko_aggregate, criteria_nof_ko_aggregate)
421457
)
422458

423459
# Check procedure table
424460
viavi_failure_manager.print_failures(_OMIT_VIAVI_FAILURE_LIST)
425-
is_ok &= viavi_failure_manager.get_number_of_failures(_OMIT_VIAVI_FAILURE_LIST) == 0
461+
criteria_procedure_table = viavi_failure_manager.get_number_of_failures(_OMIT_VIAVI_FAILURE_LIST) == 0
462+
criteria_result.append(
463+
_ViaviResult(
464+
"Procedure table",
465+
0,
466+
viavi_failure_manager.get_number_of_failures(_OMIT_VIAVI_FAILURE_LIST),
467+
criteria_procedure_table,
468+
)
469+
)
426470

471+
is_ok = (
472+
criteria_dl_brate_aggregate
473+
and criteria_ul_brate_aggregate
474+
and criteria_nof_ko_aggregate
475+
and criteria_procedure_table
476+
)
477+
478+
create_table(criteria_result, capsys)
427479
if not is_ok:
428-
pytest.fail("Test didn't pass all the criteria")
480+
criteria_errors_str = []
481+
for criteria in criteria_result:
482+
if not criteria.is_ok:
483+
criteria_errors_str.append(criteria.criteria_name)
484+
pytest.fail("Test didn't pass the following criteria: " + ", ".join(criteria_errors_str))
485+
486+
487+
def create_table(results: List[_ViaviResult], capsys):
488+
"""
489+
Create a table with the results
490+
"""
491+
table = Table(title="Viavi Results")
492+
493+
table.add_column("Criteria Name", justify="left", style="cyan", no_wrap=True)
494+
table.add_column("Expected", justify="right", style="magenta")
495+
table.add_column("Result", justify="right", style="magenta")
496+
table.add_column("Pass", justify="center", style="magenta")
497+
498+
for result in results:
499+
row_style = "green" if result.is_ok else "red"
500+
table.add_row(
501+
result.criteria_name,
502+
f"{get_str_number_criteria(result.expected)}",
503+
f"{get_str_number_criteria(result.current)}",
504+
"✅" if result.is_ok else "❌",
505+
style=row_style,
506+
)
429507

508+
console = Console()
509+
# Capture the table to print it in the console
510+
with console.capture() as capture:
511+
console.print(table)
512+
output = "\n" + capture.get()
430513

431-
def check_and_print_criteria(
432-
name: str,
514+
# Disable temporarily the capsys to print the table
515+
with capsys.disabled():
516+
logging.info(output)
517+
518+
519+
def check_criteria(
433520
current: float,
434521
expected: float,
435522
operator_method: Callable[[float, float], bool],
436-
force_log_info: bool = False,
437523
) -> bool:
438524
"""
439-
Check and print criteria
525+
Check criteria
440526
"""
441527
is_ok = operator_method(current, expected)
442-
(logging.info if is_ok or force_log_info else logging.error)(
443-
f"{name} expected: {expected:.2e}, actual: {current:.2e}"
444-
)
445528
return is_ok
446529

447530

531+
def get_str_number_criteria(number_criteria: float) -> str:
532+
"""
533+
Get string number criteria
534+
"""
535+
return f"{number_criteria:.2e}" if abs(number_criteria) > 1000 else str(number_criteria)
536+
537+
448538
def get_viavi_configuration_from_testname(campaign_filename: str, test_name: str, timeout: int) -> _ViaviConfiguration:
449539
"""
450540
Get Viavi configuration from dict

0 commit comments

Comments
 (0)