17
17
from mfd_common_libs .custom_logger import add_logging_level
18
18
from mfd_common_libs .log_levels import TEST_FAIL , TEST_INFO , TEST_PASS
19
19
from mfd_connect .exceptions import ConnectionCalledProcessError
20
- from mtl_engine .const import DOWNLOAD_REPORT_TRIES , FRAMES_CAPTURE , LOG_FOLDER , TESTCMD_LVL
20
+ from mtl_engine .const import (
21
+ DOWNLOAD_REPORT_TRIES ,
22
+ FRAMES_CAPTURE ,
23
+ LOG_FOLDER ,
24
+ TESTCMD_LVL ,
25
+ )
21
26
from mtl_engine .csv_report import (
22
27
csv_add_test ,
23
28
csv_write_report ,
29
+ get_compliance_result ,
24
30
update_compliance_result ,
25
31
)
26
32
39
45
)
40
46
from pytest_mfd_logging .amber_log_formatter import AmberLogFormatter
41
47
42
-
43
48
logger = logging .getLogger (__name__ )
44
49
phase_report_key = pytest .StashKey [Dict [str , pytest .CollectReport ]]()
45
50
@@ -280,37 +285,38 @@ def log_session():
280
285
281
286
282
287
@pytest .fixture (scope = "function" )
283
- def pcap_capture (request , media_file , test_config , hosts , mtl_path
284
- ):
288
+ def pcap_capture (request , media_file , test_config , hosts , mtl_path ):
285
289
capture_cfg = test_config .get ("capture_cfg" , {})
286
290
capturer = None
287
291
if capture_cfg and capture_cfg .get ("enable" ):
288
292
host = hosts ["client" ] if "client" in hosts else list (hosts .values ())[0 ]
289
293
media_file_info , _ = media_file
290
294
test_name = request .node .name
291
295
if "frames_number" not in capture_cfg and "capture_time" not in capture_cfg :
292
- capture_cfg ["packets_number" ] = FRAMES_CAPTURE * calculate_packets_per_frame (
293
- media_file_info ["width" ],
294
- media_file_info ["height" ]
296
+ capture_cfg ["packets_number" ] = (
297
+ FRAMES_CAPTURE * calculate_packets_per_frame (media_file_info )
298
+ )
299
+ logger .info (
300
+ f"Capture { capture_cfg ['packets_number' ]} packets for { FRAMES_CAPTURE } frames"
295
301
)
296
- logger .info (f"Capture { capture_cfg ['packets_number' ]} packets for { FRAMES_CAPTURE } frames" )
297
302
elif "frames_number" in capture_cfg :
298
- capture_cfg ["packets_number" ] = capture_cfg .pop ("frames_number" ) * calculate_packets_per_frame (
299
- media_file_info ["width" ],
300
- media_file_info ["height" ]
303
+ capture_cfg ["packets_number" ] = capture_cfg [
304
+ "frames_number"
305
+ ] * calculate_packets_per_frame (media_file_info )
306
+ logger .info (
307
+ f"Capture { capture_cfg ['packets_number' ]} packets for { capture_cfg ['frames_number' ]} frames"
301
308
)
302
- logger .info (f"Capture { capture_cfg ['packets_number' ]} packets for { capture_cfg ['frames_number' ]} frames" )
303
309
capturer = NetsniffRecorder (
304
310
host = host ,
305
311
test_name = test_name ,
306
312
pcap_dir = capture_cfg .get ("pcap_dir" , "/tmp" ),
307
313
interface = host .network_interfaces [0 ].name ,
308
314
silent = capture_cfg .get ("silent" , True ),
309
315
packets_capture = capture_cfg .get ("packets_number" , None ),
310
- capture_time = capture_cfg .get ("capture_time" , None )
316
+ capture_time = capture_cfg .get ("capture_time" , None ),
311
317
)
312
318
yield capturer
313
- if capturer :
319
+ if capturer and capturer . netsniff_process :
314
320
ebu_server = test_config .get ("ebu_server" , {})
315
321
if not ebu_server :
316
322
logger .error ("EBU server configuration not found in test_config.yaml" )
@@ -320,7 +326,7 @@ def pcap_capture(request, media_file, test_config, hosts, mtl_path
320
326
ebu_passwd = ebu_server .get ("password" , None )
321
327
ebu_proxy = ebu_server .get ("proxy" , None )
322
328
proxy_cmd = f" --proxy { ebu_proxy } " if ebu_proxy else ""
323
- compliance_upl = host .connection .execute_command (
329
+ compliance_upl = capturer . host .connection .execute_command (
324
330
"python3 ./tests/validation/compliance/upload_pcap.py"
325
331
f" --ip { ebu_ip } "
326
332
f" --login { ebu_login } "
@@ -332,13 +338,9 @@ def pcap_capture(request, media_file, test_config, hosts, mtl_path
332
338
logger .error (f"PCAP upload failed: { compliance_upl .stderr } " )
333
339
return
334
340
uuid = (
335
- compliance_upl .stdout .split (">>>UUID>>>" )[1 ]
336
- .split ("<<<UUID<<<" )[0 ]
337
- .strip ()
338
- )
339
- logger .debug (
340
- f"PCAP successfully uploaded to EBU LIST with UUID: { uuid } "
341
+ compliance_upl .stdout .split (">>>UUID>>>" )[1 ].split ("<<<UUID<<<" )[0 ].strip ()
341
342
)
343
+ logger .debug (f"PCAP successfully uploaded to EBU LIST with UUID: { uuid } " )
342
344
uploader = PcapComplianceClient (config_path = "" )
343
345
uploader .ebu_ip = ebu_ip
344
346
uploader .user = ebu_login
@@ -353,9 +355,13 @@ def pcap_capture(request, media_file, test_config, hosts, mtl_path
353
355
tries -= 1
354
356
report = uploader .download_report ()
355
357
if not report .get ("analyzed" , False ):
356
- logger .error (f"Report is not ready after { DOWNLOAD_REPORT_TRIES } seconds, skipping compliance check" )
358
+ logger .error (
359
+ f"Report is not ready after { DOWNLOAD_REPORT_TRIES } seconds, skipping compliance check"
360
+ )
357
361
return
358
- if report .get ("not_compliant_streams" , 1 ) == 0 :
362
+ result = report .get ("not_compliant_streams" , 1 )
363
+ update_compliance_result (request .node .nodeid , "Pass" if result == 0 else "Fail" )
364
+ if result == 0 :
359
365
logger .info ("PCAP compliance check passed" )
360
366
else :
361
367
log_fail ("PCAP compliance check failed" )
@@ -380,18 +386,24 @@ def log_case(request, caplog: pytest.LogCaptureFixture):
380
386
clear_issue ()
381
387
yield
382
388
report = request .node .stash [phase_report_key ]
383
- if report ["setup" ].failed :
384
- logger .log (level = TEST_FAIL , msg = f"Setup failed for { case_id } " )
389
+
390
+ def fail_test (stage ):
391
+ logger .log (level = TEST_FAIL , msg = f"{ stage } failed for { case_id } " )
385
392
os .chmod (logfile , 0o4755 )
386
- result = "Fail"
393
+ return "Fail"
394
+
395
+ if report ["setup" ].failed :
396
+ result = fail_test ("Setup" )
387
397
elif ("call" not in report ) or report ["call" ].failed :
388
- logger .log (level = TEST_FAIL , msg = f"Test failed for { case_id } " )
389
- os .chmod (logfile , 0o4755 )
390
- result = "Fail"
398
+ result = fail_test ("Test" )
391
399
elif report ["call" ].passed :
392
- logger .log (level = TEST_PASS , msg = f"Test passed for { case_id } " )
393
- os .chmod (logfile , 0o755 )
394
- result = "Pass"
400
+ compliance = get_compliance_result (case_id )
401
+ if compliance is not None and compliance == "Fail" :
402
+ result = fail_test ("Compliance" )
403
+ else :
404
+ logger .log (level = TEST_PASS , msg = f"Test passed for { case_id } " )
405
+ os .chmod (logfile , 0o755 )
406
+ result = "Pass"
395
407
else :
396
408
logger .log (level = TEST_INFO , msg = f"Test skipped for { case_id } " )
397
409
result = "Skip"
0 commit comments