Skip to content

Commit 2b7cd2b

Browse files
author
qarlosalberto
committed
ci: viavi config from yaml
1 parent aaab37c commit 2b7cd2b

File tree

6 files changed

+294
-101
lines changed

6 files changed

+294
-101
lines changed

.gitlab/ci/e2e.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,15 @@ load retina variables:
8181
export FORCE_COLOR=1
8282
export KUBECONFIG=$K_PATH
8383
84-
e2e request validation:
84+
e2e request and config validation:
8585
stage: static
8686
extends:
8787
- .prepare_test
8888
rules:
8989
- if: $ON_MR
9090
changes:
9191
- .gitlab/ci/e2e/**/*
92+
- tests/e2e/tests/viavi/*
9293
image:
9394
name: ${RETINA_REGISTRY_PREFIX}/launcher:${RETINA_VERSION}
9495
entrypoint: ["/bin/sh", "-c"]
@@ -99,6 +100,7 @@ e2e request validation:
99100
for f in $file_list; do
100101
retina-request-checker --input $f
101102
done
103+
python3 ${CI_PROJECT_DIR}/tests/e2e/tests/viavi/validate_test_declaration.py
102104
needs: &retina-needs
103105
- job: "load retina variables"
104106
artifacts: true

tests/e2e/tests/viavi.py

Lines changed: 101 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
import logging
1313
import operator
1414
from dataclasses import dataclass
15-
from enum import Enum
1615
from pathlib import Path
17-
from typing import Callable, Optional
16+
from typing import Callable, List, Optional
1817

1918
import pytest
20-
from pytest import mark, param
19+
import yaml
20+
from pytest import mark
2121
from requests import HTTPError
2222
from retina.client.manager import RetinaTestManager
2323
from retina.launcher.artifacts import RetinaTestData
@@ -31,34 +31,64 @@
3131
from .steps.configuration import configure_metric_server_for_gnb
3232
from .steps.stub import get_metrics, GNB_STARTUP_TIMEOUT, GnbMetrics, handle_start_error, stop
3333

34-
CAMPAIGN_FILENAME = "C:\\ci\\CI 4x4 ORAN-FH.xml"
3534
_OMIT_VIAVI_FAILURE_LIST = ["authentication"]
3635
_POD_ERROR = "Error creating the pod"
3736

3837

39-
class _TestName(Enum):
40-
"""
41-
Test names
42-
"""
43-
44-
UE1_STATIC_DL_UL_UDP = "1UE static DL + UL UDP - Dell"
45-
UE32_STATIC_DL_UL_UDP = "32UE static DL + UL UDP - Dell"
46-
47-
38+
# pylint: disable=too-many-instance-attributes
4839
@dataclass
4940
class _ViaviConfiguration:
5041
"""
5142
Viavi configuration
5243
"""
5344

45+
campaign_filename: str = ""
46+
test_name: str = ""
47+
test_timeout: int = 0
48+
gnb_extra_commands: str = ""
49+
id: str = ""
5450
max_pdschs_per_slot: int = 1
5551
max_puschs_per_slot: int = 1
5652
enable_qos_viavi: bool = False
57-
warning_as_errors: bool = True
53+
# test/fail criteria
5854
expected_ul_bitrate: float = 0
5955
expected_dl_bitrate: float = 0
56+
fail_if_kos: bool = True
57+
warning_as_errors: bool = True
6058

6159

60+
def load_yaml_config(config_filename: str) -> List[_ViaviConfiguration]:
61+
"""
62+
Load yaml config
63+
"""
64+
test_declaration_list: List[_ViaviConfiguration] = []
65+
config_filepath = Path(__file__).parent.joinpath("viavi", config_filename).absolute()
66+
with open(config_filepath, "r", encoding="UTF-8") as file:
67+
test_declaration_list_raw = yaml.safe_load(file)["tests"]
68+
69+
for test_declaration in test_declaration_list_raw:
70+
test_declaration_list.append(
71+
_ViaviConfiguration(
72+
campaign_filename=test_declaration["campaign_filename"],
73+
test_name=test_declaration["test_name"],
74+
test_timeout=test_declaration["test_timeout"],
75+
gnb_extra_commands=test_declaration["gnb_extra_commands"],
76+
id=test_declaration["id"],
77+
max_pdschs_per_slot=test_declaration["max_pdschs_per_slot"],
78+
max_puschs_per_slot=test_declaration["max_pdschs_per_slot"],
79+
enable_qos_viavi=test_declaration["enable_qos_viavi"],
80+
expected_dl_bitrate=test_declaration["expected_dl_bitrate"],
81+
expected_ul_bitrate=test_declaration["expected_ul_bitrate"],
82+
fail_if_kos=test_declaration["fail_if_kos"],
83+
warning_as_errors=test_declaration["warning_as_errors"],
84+
)
85+
)
86+
return test_declaration_list
87+
88+
89+
################################################################################
90+
# Manual tests
91+
################################################################################
6292
@pytest.fixture
6393
def viavi_manual_campaign_filename(request):
6494
"""
@@ -106,6 +136,10 @@ def test_viavi_manual(
106136
"""
107137
Runs a test using Viavi
108138
"""
139+
test_declaration = get_viavi_configuration_from_testname(
140+
viavi_manual_campaign_filename, viavi_manual_test_name, viavi_manual_test_timeout
141+
)
142+
109143
_test_viavi(
110144
# Retina
111145
retina_manager=retina_manager,
@@ -117,9 +151,7 @@ def test_viavi_manual(
117151
metrics_server=None,
118152
# Test info
119153
metrics_summary=None,
120-
campaign_filename=viavi_manual_campaign_filename,
121-
test_name=viavi_manual_test_name,
122-
test_timeout=viavi_manual_test_timeout,
154+
test_declaration=test_declaration,
123155
# Test extra params
124156
always_download_artifacts=always_download_artifacts,
125157
gnb_startup_timeout=gnb_startup_timeout,
@@ -128,22 +160,15 @@ def test_viavi_manual(
128160
)
129161

130162

131-
@mark.parametrize(
132-
"test_name, test_timeout, post_commands",
133-
(
134-
param(
135-
_TestName.UE1_STATIC_DL_UL_UDP.value,
136-
45 * 60,
137-
"log --mac_level=info",
138-
id="1UE Bidirectional UDP",
139-
),
140-
param(
141-
_TestName.UE32_STATIC_DL_UL_UDP.value,
142-
45 * 60,
143-
"log --mac_level=info",
144-
id="32UE Bidirectional UDP",
145-
),
146-
),
163+
################################################################################
164+
# CI tests
165+
################################################################################
166+
@pytest.mark.parametrize(
167+
"test_declaration",
168+
[
169+
pytest.param(test_declaration, id=test_declaration.id)
170+
for test_declaration in load_yaml_config("test_declaration.yml")
171+
],
147172
)
148173
@mark.viavi
149174
@mark.flaky(
@@ -162,11 +187,8 @@ def test_viavi(
162187
metrics_server: MetricServerInfo,
163188
# Test info
164189
metrics_summary: MetricsSummary,
165-
test_name: str,
166-
test_timeout: int,
167-
post_commands: str,
190+
test_declaration: _ViaviConfiguration,
168191
# Test extra params
169-
warning_as_errors: bool = True,
170192
always_download_artifacts: bool = True,
171193
gnb_startup_timeout: int = GNB_STARTUP_TIMEOUT,
172194
gnb_stop_timeout: int = 0,
@@ -186,29 +208,21 @@ def test_viavi(
186208
metrics_server=metrics_server,
187209
# Test info
188210
metrics_summary=metrics_summary,
189-
campaign_filename=CAMPAIGN_FILENAME,
190-
test_name=test_name,
191-
test_timeout=test_timeout,
211+
test_declaration=test_declaration,
192212
# Test extra params
193-
warning_as_errors=warning_as_errors,
194213
always_download_artifacts=always_download_artifacts,
195214
gnb_startup_timeout=gnb_startup_timeout,
196215
gnb_stop_timeout=gnb_stop_timeout,
197216
log_search=log_search,
198-
post_commands=post_commands,
199217
)
200218

201219

202-
@mark.parametrize(
203-
"test_name, test_timeout, post_commands",
204-
(
205-
param(
206-
_TestName.UE32_STATIC_DL_UL_UDP.value,
207-
45 * 60,
208-
"log --mac_level=info",
209-
id="32UE Bidirectional UDP",
210-
),
211-
),
220+
@pytest.mark.parametrize(
221+
"test_declaration",
222+
[
223+
pytest.param(test_declaration, id=test_declaration.id)
224+
for test_declaration in load_yaml_config("test_declaration_debug.yml")
225+
],
212226
)
213227
@mark.viavi_debug
214228
@mark.flaky(
@@ -227,9 +241,7 @@ def test_viavi_debug(
227241
metrics_server: MetricServerInfo,
228242
# Test info
229243
metrics_summary: MetricsSummary,
230-
test_name: str,
231-
test_timeout: int,
232-
post_commands: str,
244+
test_declaration: _ViaviConfiguration,
233245
# Test extra params
234246
always_download_artifacts: bool = True,
235247
gnb_startup_timeout: int = GNB_STARTUP_TIMEOUT,
@@ -250,16 +262,12 @@ def test_viavi_debug(
250262
metrics_server=metrics_server,
251263
# Test info
252264
metrics_summary=metrics_summary,
253-
campaign_filename=CAMPAIGN_FILENAME,
254-
test_name=test_name,
255-
test_timeout=test_timeout,
265+
test_declaration=test_declaration,
256266
# Test extra params
257267
always_download_artifacts=always_download_artifacts,
258268
gnb_startup_timeout=gnb_startup_timeout,
259269
gnb_stop_timeout=gnb_stop_timeout,
260270
log_search=log_search,
261-
post_commands=post_commands,
262-
warning_as_errors=False,
263271
)
264272

265273

@@ -275,23 +283,16 @@ def _test_viavi(
275283
metrics_server: Optional[MetricServerInfo],
276284
# Test info
277285
metrics_summary: Optional[MetricsSummary],
278-
campaign_filename: str,
279-
test_name: str,
280-
test_timeout: int,
286+
test_declaration: _ViaviConfiguration,
281287
# Test extra params
282-
warning_as_errors: bool = True,
283288
always_download_artifacts: bool = True,
284289
gnb_startup_timeout: int = GNB_STARTUP_TIMEOUT,
285290
gnb_stop_timeout: int = 0,
286291
log_search: bool = True,
287-
post_commands: str = "",
288-
fail_if_kos: bool = True,
289292
):
290293
"""
291294
Runs a test using Viavi
292295
"""
293-
test_configuration = get_viavi_configuration(test_name, warning_as_errors)
294-
295296
retina_data.test_config = {
296297
"gnb": {
297298
"parameters": {
@@ -308,9 +309,9 @@ def _test_viavi(
308309
"nof_antennas_dl": 4,
309310
"nof_antennas_ul": 1,
310311
"prach_config_index": 159,
311-
"max_puschs_per_slot": test_configuration.max_puschs_per_slot,
312-
"max_pdschs_per_slot": test_configuration.max_pdschs_per_slot,
313-
"enable_qos_viavi": test_configuration.enable_qos_viavi,
312+
"max_puschs_per_slot": test_declaration.max_puschs_per_slot,
313+
"max_pdschs_per_slot": test_declaration.max_pdschs_per_slot,
314+
"enable_qos_viavi": test_declaration.enable_qos_viavi,
314315
},
315316
"templates": {"extra": str(Path(__file__).joinpath("../viavi/config.yml").resolve())},
316317
},
@@ -338,22 +339,25 @@ def _test_viavi(
338339
fivegc_definition=FiveGCDefinition(amf_ip=amf_ip, amf_port=amf_port),
339340
start_info=StartInfo(
340341
timeout=gnb_startup_timeout,
341-
post_commands=post_commands,
342+
post_commands=test_declaration.gnb_extra_commands,
342343
),
343344
)
344345
)
345346

346347
# Create campaign
347-
logging.info(f"Starting Campaign {campaign_filename}" + (f" - Test {test_name}" if test_name is not None else ""))
348-
campaign_name = viavi.schedule_campaign(campaign_filename, test_name)
348+
logging.info(
349+
f"Starting Campaign {test_declaration.campaign_filename}"
350+
+ (f" - Test {test_declaration.test_name}" if test_declaration.test_name is not None else "")
351+
)
352+
campaign_name = viavi.schedule_campaign(test_declaration.campaign_filename, test_declaration.test_name)
349353

350354
# Start campaign
351355
viavi.run_campaign(campaign_name)
352356
logging.info("Campaign started")
353357

354358
# Wait until end
355359
try:
356-
info = viavi.wait_until_running_campaign_finishes(test_timeout)
360+
info = viavi.wait_until_running_campaign_finishes(test_declaration.test_timeout)
357361
if info.status is not CampaignStatusEnum.PASS:
358362
pytest.fail(f"Viavi Test Failed: {info.message}")
359363
# Final stop
@@ -364,8 +368,8 @@ def _test_viavi(
364368
retina_data,
365369
gnb_stop_timeout=gnb_stop_timeout,
366370
log_search=log_search,
367-
warning_as_errors=test_configuration.warning_as_errors,
368-
fail_if_kos=False,
371+
warning_as_errors=test_declaration.warning_as_errors,
372+
fail_if_kos=test_declaration.fail_if_kos,
369373
)
370374

371375
# This except and the finally should be inside the request, but the campaign_name makes it complicated
@@ -381,11 +385,14 @@ def _test_viavi(
381385
logging.info("Folder with Viavi report: %s", report_folder)
382386
logging.info("Downloading Viavi report")
383387
viavi.download_directory(report_folder, Path(test_log_folder).joinpath("viavi"))
384-
check_metrics_criteria(test_configuration, gnb, viavi, metrics_summary, fail_if_kos)
388+
check_metrics_criteria(test_declaration, gnb, viavi, metrics_summary, test_declaration.fail_if_kos)
385389
except HTTPError:
386390
logging.error("Viavi Reports could not be downloaded")
387391

388392

393+
################################################################################
394+
# Helper functions
395+
################################################################################
389396
def check_metrics_criteria(
390397
test_configuration: _ViaviConfiguration,
391398
gnb: GNBStub,
@@ -422,7 +429,7 @@ def check_metrics_criteria(
422429
# Check procedure table
423430
viavi_failure_manager = viavi.get_test_failures()
424431
viavi_failure_manager.print_failures(_OMIT_VIAVI_FAILURE_LIST)
425-
is_ok &= viavi_failure_manager.get_number_of_failures(_OMIT_VIAVI_FAILURE_LIST) > 0
432+
is_ok &= viavi_failure_manager.get_number_of_failures(_OMIT_VIAVI_FAILURE_LIST) == 0
426433

427434
if not is_ok:
428435
pytest.fail("Test didn't pass all the criteria")
@@ -439,26 +446,20 @@ def check_and_print_criteria(
439446
return is_ok
440447

441448

442-
def get_viavi_configuration(test_name: str, warning_as_errors: bool) -> _ViaviConfiguration:
449+
def get_viavi_configuration_from_testname(campaign_filename: str, test_name: str, timeout: int) -> _ViaviConfiguration:
443450
"""
444-
Get Viavi configuration
451+
Get Viavi configuration from dict
445452
"""
446-
if test_name == _TestName.UE1_STATIC_DL_UL_UDP.value:
447-
return _ViaviConfiguration(
448-
max_pdschs_per_slot=8,
449-
max_puschs_per_slot=8,
450-
enable_qos_viavi=False,
451-
warning_as_errors=warning_as_errors,
452-
expected_dl_bitrate=80e6,
453-
expected_ul_bitrate=80e6,
454-
)
455-
if test_name == _TestName.UE32_STATIC_DL_UL_UDP.value:
456-
return _ViaviConfiguration(
457-
max_pdschs_per_slot=1,
458-
max_puschs_per_slot=1,
459-
enable_qos_viavi=False,
460-
warning_as_errors=warning_as_errors,
461-
expected_dl_bitrate=80e6,
462-
expected_ul_bitrate=80e6,
463-
)
464-
raise ValueError(f"Test name {test_name} not supported")
453+
config = load_yaml_config("test_declaration.yml")
454+
for test_config in config:
455+
if test_config.test_name == test_name:
456+
test_declaration = test_config
457+
break
458+
459+
if test_declaration is None:
460+
logging.warning("There is no config for the test: %s", test_name)
461+
test_declaration = _ViaviConfiguration()
462+
463+
test_declaration.campaign_filename = campaign_filename
464+
test_declaration.test_timeout = timeout
465+
return test_declaration

0 commit comments

Comments
 (0)