Skip to content

Commit

Permalink
[staticroutebfd] fix an error in error logging (sonic-net#17043)
Browse files Browse the repository at this point in the history
Why I did it
Fix an error in the log_err call.
this error can be triggered by an invalid static route key. usually the code cannot go here with normal config file. but hit this issue with an invalid key by manual testing with redis-cli directly. the file is scanned by Python lint to prevent such errors.

Work item tracking
Microsoft ADO ():26250268

How I did it
fix the format error.

How to verify it
1, ran pylint to check the design, make sure no such error in the design file.
2, wrote a separate python program to verify the log call.
In the current logging related testing, usually use patch/mock for logging. for this specific error, could not trigger it if we call mock function instead the real function in the design. so need to do lint checking for code change.
  • Loading branch information
baorliu authored and mssonicbld committed Feb 2, 2024
1 parent e676ad1 commit 0f9febd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/sonic-bgpcfgd/staticroutebfd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def static_route_set_handler(self, key, data):

valid, is_ipv4, ip = check_ip(ip_prefix)
if not valid:
log_err("invalid ip prefix for static route: ", key)
log_err("invalid ip prefix for static route: '%s'"%(key))
return True

#use lower case if there is letter in IPv6 address string
Expand Down
17 changes: 17 additions & 0 deletions src/sonic-bgpcfgd/tests/test_static_rt_bfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,23 @@ def test_set_del_ipv6():
{'del_default:2603:10e2:400::4/128': { }}
)

@patch('staticroutebfd.main.log_err')
def test_invalid_key(mocked_log_err):
dut = constructor()
intf_setup(dut)

set_del_test(dut, "srt",
"SET",
("2.2.2/24", {
"bfd": "true",
"nexthop": "192.168.1.2 , 192.168.2.2, 192.168.3.2",
"ifname": "if1, if2, if3",
}),
{},
{}
)
mocked_log_err.assert_called_with("invalid ip prefix for static route: '2.2.2/24'")

def test_set_del():
dut = constructor()
intf_setup(dut)
Expand Down

0 comments on commit 0f9febd

Please sign in to comment.