Skip to content

Commit 2a8181c

Browse files
baorliumssonicbld
authored andcommitted
[staticroutebfd] fix an error in error logging (#17043)
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.
1 parent 4efd510 commit 2a8181c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/sonic-bgpcfgd/staticroutebfd/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def static_route_set_handler(self, key, data):
373373

374374
valid, is_ipv4, ip = check_ip(ip_prefix)
375375
if not valid:
376-
log_err("invalid ip prefix for static route: ", key)
376+
log_err("invalid ip prefix for static route: '%s'"%(key))
377377
return True
378378

379379
arg_list = lambda v: [x.strip() for x in v.split(',')] if len(v.strip()) != 0 else None

src/sonic-bgpcfgd/tests/test_static_rt_bfd.py

+17
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,23 @@ def intf_setup(dut):
9595
{}
9696
)
9797

98+
@patch('staticroutebfd.main.log_err')
99+
def test_invalid_key(mocked_log_err):
100+
dut = constructor()
101+
intf_setup(dut)
102+
103+
set_del_test(dut, "srt",
104+
"SET",
105+
("2.2.2/24", {
106+
"bfd": "true",
107+
"nexthop": "192.168.1.2 , 192.168.2.2, 192.168.3.2",
108+
"ifname": "if1, if2, if3",
109+
}),
110+
{},
111+
{}
112+
)
113+
mocked_log_err.assert_called_with("invalid ip prefix for static route: '2.2.2/24'")
114+
98115
def test_set_del():
99116
dut = constructor()
100117
intf_setup(dut)

0 commit comments

Comments
 (0)