From 166739ef2ab8cc7949b6f804921d423d406bc7b6 Mon Sep 17 00:00:00 2001 From: bingwang-ms <66248323+bingwang-ms@users.noreply.github.com> Date: Fri, 11 Nov 2022 16:17:49 +0800 Subject: [PATCH] Accept 0 for queue and dscp (#2494) --- config/main.py | 4 ++-- tests/config_mirror_session_test.py | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/config/main.py b/config/main.py index 46cec34e43..126045adbb 100644 --- a/config/main.py +++ b/config/main.py @@ -2136,7 +2136,7 @@ def gather_session_info(session_info, policer, queue, src_port, direction): if policer: session_info['policer'] = policer - if queue: + if queue is not None: session_info['queue'] = queue if src_port: @@ -2162,7 +2162,7 @@ def add_erspan(session_name, src_ip, dst_ip, dscp, ttl, gre_type, queue, policer "ttl": ttl } - if gre_type: + if gre_type is not None: session_info['gre_type'] = gre_type session_info = gather_session_info(session_info, policer, queue, src_port, direction) diff --git a/tests/config_mirror_session_test.py b/tests/config_mirror_session_test.py index a26e109a6d..de5e755a3f 100644 --- a/tests/config_mirror_session_test.py +++ b/tests/config_mirror_session_test.py @@ -85,7 +85,7 @@ def test_mirror_session_add(): ["test_session", "100.1.1.1", "2.2.2.2", "8", "63", "0", "0"]) mocked.assert_called_with("test_session", "100.1.1.1", "2.2.2.2", 8, 63, 0, 0, None) - + result = runner.invoke( config.config.commands["mirror_session"].commands["add"], ["test_session", "100.1.1.1", "2.2.2.2", "8", "63"]) @@ -137,7 +137,7 @@ def test_mirror_session_erspan_add(): ["test_session", "1.1.1.1", "2.2.2.2", "6", "63", "65536", "100"]) assert result.exit_code != 0 assert ERR_MSG_GRE_TYPE_FAILURE in result.stdout - + result = runner.invoke( config.config.commands["mirror_session"].commands["erspan"].commands["add"], ["test_session", "1.1.1.1", "2.2.2.2", "6", "63", "abcd", "100"]) @@ -165,6 +165,12 @@ def test_mirror_session_erspan_add(): mocked.assert_called_with("test_session", "100.1.1.1", "2.2.2.2", 8, 63, 0x1234, 100, None, None, None) + result = runner.invoke( + config.config.commands["mirror_session"].commands["erspan"].commands["add"], + ["test_session", "100.1.1.1", "2.2.2.2", "8", "63", "0", "0"]) + + mocked.assert_called_with("test_session", "100.1.1.1", "2.2.2.2", 8, 63, 0, 0, None, None, None) + def test_mirror_session_span_add(): runner = CliRunner() @@ -258,9 +264,12 @@ def test_mirror_session_span_add(): result = runner.invoke( config.config.commands["mirror_session"].commands["span"].commands["add"], ["test_session", "Ethernet8", "Ethernet4", "tx", "100"]) + + mocked.assert_called_with("test_session", "Ethernet8", "Ethernet4", "tx", 100, None) + result = runner.invoke( config.config.commands["mirror_session"].commands["span"].commands["add"], - ["test_session", "Ethernet0", "Ethernet4", "rx", "100"]) + ["test_session", "Ethernet0", "Ethernet4", "rx", "0"]) - mocked.assert_called_with("test_session", "Ethernet0", "Ethernet4", "rx", 100, None) + mocked.assert_called_with("test_session", "Ethernet0", "Ethernet4", "rx", 0, None)