Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[202012][cherry-pick]Fix validation of input of config mirror_session add #2187

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,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:
Expand All @@ -1699,7 +1699,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)
Expand Down
22 changes: 20 additions & 2 deletions tests/config_mirror_session_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ def test_mirror_session_add():
mocked.assert_called_with("test_session", "100.1.1.1", "2.2.2.2", 8, 63, 10, 100, None)


result = runner.invoke(
config.config.commands["mirror_session"].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)


def test_mirror_session_erspan_add():
runner = CliRunner()
Expand Down Expand Up @@ -129,6 +135,12 @@ def test_mirror_session_erspan_add():

mocked.assert_called_with("test_session", "100.1.1.1", "2.2.2.2", 8, 63, 10, 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()
Expand All @@ -144,7 +156,13 @@ def test_mirror_session_span_add():
with mock.patch('config.main.add_span') as mocked:
result = runner.invoke(
config.config.commands["mirror_session"].commands["span"].commands["add"],
["test_session", "Ethernet0", "Ethernet4", "rx", "100"])
["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", "0"])

mocked.assert_called_with("test_session", "Ethernet0", "Ethernet4", "rx", 100, None)
mocked.assert_called_with("test_session", "Ethernet0", "Ethernet4", "rx", 0, None)