@@ -89,7 +89,7 @@ def test_mirror_session_add():
8989 ["test_session" , "100.1.1.1" , "2.2.2.2" , "8" , "63" , "0" , "0" ])
9090
9191 mocked .assert_called_with ("test_session" , "100.1.1.1" , "2.2.2.2" , 8 , 63 , 0 , 0 , None )
92-
92+
9393 result = runner .invoke (
9494 config .config .commands ["mirror_session" ].commands ["add" ],
9595 ["test_session" , "100.1.1.1" , "2.2.2.2" , "8" , "63" ])
@@ -141,7 +141,7 @@ def test_mirror_session_erspan_add():
141141 ["test_session" , "1.1.1.1" , "2.2.2.2" , "6" , "63" , "65536" , "100" ])
142142 assert result .exit_code != 0
143143 assert ERR_MSG_GRE_TYPE_FAILURE in result .stdout
144-
144+
145145 result = runner .invoke (
146146 config .config .commands ["mirror_session" ].commands ["erspan" ].commands ["add" ],
147147 ["test_session" , "1.1.1.1" , "2.2.2.2" , "6" , "63" , "abcd" , "100" ])
@@ -295,7 +295,7 @@ def test_mirror_session_span_add():
295295 result = runner .invoke (
296296 config .config .commands ["mirror_session" ].commands ["span" ].commands ["add" ],
297297 ["test_session" , "Ethernet8" , "Ethernet4" , "tx" , "100" ])
298-
298+
299299 mocked .assert_called_with ("test_session" , "Ethernet8" , "Ethernet4" , "tx" , 100 , None )
300300
301301 result = runner .invoke (
@@ -355,121 +355,3 @@ def test_mirror_session_remove_invalid_yang_validation():
355355 ["mrr_sample" ])
356356 print (result .output )
357357 assert "Invalid ConfigDB. Error" in result .output
358-
359-
360- def test_mirror_session_capability_checking ():
361- """Test mirror session capability checking functionality"""
362- config .ADHOC_VALIDATION = True
363- runner = CliRunner ()
364-
365- # Test 1: Check that capability checking fails when direction is not supported
366- with mock .patch ('config.main.is_port_mirror_capability_supported' ) as mock_capability :
367- mock_capability .return_value = False
368-
369- # Test with rx direction - should fail
370- result = runner .invoke (
371- config .config .commands ["mirror_session" ].commands ["span" ].commands ["add" ],
372- ["test_session" , "Ethernet20" , "Ethernet24" , "rx" , "100" ])
373-
374- assert result .exit_code != 0
375- assert "Error: Port mirror direction 'rx' is not supported by the ASIC" in result .output
376-
377- # Test with tx direction - should fail
378- result = runner .invoke (
379- config .config .commands ["mirror_session" ].commands ["span" ].commands ["add" ],
380- ["test_session" , "Ethernet20" , "Ethernet24" , "tx" , "100" ])
381-
382- assert result .exit_code != 0
383- assert "Error: Port mirror direction 'tx' is not supported by the ASIC" in result .output
384-
385- # Test with both direction - should fail
386- result = runner .invoke (
387- config .config .commands ["mirror_session" ].commands ["span" ].commands ["add" ],
388- ["test_session" , "Ethernet20" , "Ethernet24" , "both" , "100" ])
389-
390- assert result .exit_code != 0
391- assert "Error: Port mirror direction 'both' is not supported by the ASIC" in result .output
392-
393-
394- def test_mirror_session_capability_function ():
395- """Test the is_port_mirror_capability_supported function directly"""
396-
397- # Test 1: Test with valid STATE_DB responses
398- with mock .patch ('config.main.SonicV2Connector' ) as mock_connector :
399- mock_instance = mock .Mock ()
400- mock_connector .return_value = mock_instance
401-
402- # Mock successful connection
403- mock_instance .connect .return_value = None
404-
405- # Test ingress capability check
406- mock_instance .get .side_effect = lambda db , entry , field : {
407- ("SWITCH_CAPABILITY|switch" , "PORT_INGRESS_MIRROR_CAPABLE" ): "true" ,
408- ("SWITCH_CAPABILITY|switch" , "PORT_EGRESS_MIRROR_CAPABLE" ): "true"
409- }.get ((entry , field ), "false" )
410-
411- # Test rx direction
412- result = config .is_port_mirror_capability_supported ("rx" )
413- assert result is True
414-
415- # Test tx direction
416- result = config .is_port_mirror_capability_supported ("tx" )
417- assert result is True
418-
419- # Test both direction
420- result = config .is_port_mirror_capability_supported ("both" )
421- assert result is True
422-
423- # Test no direction (should check both)
424- result = config .is_port_mirror_capability_supported (None )
425- assert result is True
426-
427- # Test 2: Test with partial capability support
428- with mock .patch ('config.main.SonicV2Connector' ) as mock_connector :
429- mock_instance = mock .Mock ()
430- mock_connector .return_value = mock_instance
431-
432- # Mock successful connection
433- mock_instance .connect .return_value = None
434-
435- # Mock only ingress supported
436- mock_instance .get .side_effect = lambda db , entry , field : {
437- ("SWITCH_CAPABILITY|switch" , "PORT_INGRESS_MIRROR_CAPABLE" ): "true" ,
438- ("SWITCH_CAPABILITY|switch" , "PORT_EGRESS_MIRROR_CAPABLE" ): "false"
439- }.get ((entry , field ), "false" )
440-
441- # Test rx direction (should pass)
442- result = config .is_port_mirror_capability_supported ("rx" )
443- assert result is True
444-
445- # Test tx direction (should fail)
446- result = config .is_port_mirror_capability_supported ("tx" )
447- assert result is False
448-
449- # Test both direction (should fail)
450- result = config .is_port_mirror_capability_supported ("both" )
451- assert result is False
452-
453- # Test no direction (should fail)
454- result = config .is_port_mirror_capability_supported (None )
455- assert result is False
456-
457- # Test 3: Test with no capability support
458- with mock .patch ('config.main.SonicV2Connector' ) as mock_connector :
459- mock_instance = mock .Mock ()
460- mock_connector .return_value = mock_instance
461-
462- # Mock successful connection
463- mock_instance .connect .return_value = None
464-
465- # Mock no capabilities supported
466- mock_instance .get .side_effect = lambda db , entry , field : {
467- ("SWITCH_CAPABILITY|switch" , "PORT_INGRESS_MIRROR_CAPABLE" ): "false" ,
468- ("SWITCH_CAPABILITY|switch" , "PORT_EGRESS_MIRROR_CAPABLE" ): "false"
469- }.get ((entry , field ), "false" )
470-
471- # All directions should fail
472- assert config .is_port_mirror_capability_supported ("rx" ) is False
473- assert config .is_port_mirror_capability_supported ("tx" ) is False
474- assert config .is_port_mirror_capability_supported ("both" ) is False
475- assert config .is_port_mirror_capability_supported (None ) is False
0 commit comments