From 8d37dd7f5ee7f10cc380f39da38fc279dca07b44 Mon Sep 17 00:00:00 2001 From: StormLiangMS <89824293+StormLiangMS@users.noreply.github.com> Date: Fri, 29 Jul 2022 23:33:09 +0800 Subject: [PATCH] [bgpcfgd] improve the log when delete a loopback interface (#11152) Why I did it The bgpcfgd doesn't support deletion of 'zebra set src', if an interface is deleted, the bgpcfgd will drop a warning message. In current implementation, we only care about the loopback0 interface but not others. To improve the log print to have the key info, which will give the name of the deleted interface. We can ignore it if it is not the loopback0 interface. The application layer should be aware of that update and deletion is not supported, delete or update with a new address of loopback0 could cause issue, this log can give enough info to root cause the issue. How I did it How to verify it --- src/sonic-bgpcfgd/bgpcfgd/managers_setsrc.py | 2 +- src/sonic-bgpcfgd/tests/test_setsrc.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sonic-bgpcfgd/bgpcfgd/managers_setsrc.py b/src/sonic-bgpcfgd/bgpcfgd/managers_setsrc.py index d1de585b05..903760c937 100644 --- a/src/sonic-bgpcfgd/bgpcfgd/managers_setsrc.py +++ b/src/sonic-bgpcfgd/bgpcfgd/managers_setsrc.py @@ -64,4 +64,4 @@ class ZebraSetSrc(Manager): def del_handler(self, key): """ Implementation of 'DEL' command for this class """ self.directory.remove(self.db_name, self.table_name, key) - log_warn("Delete command is not supported for 'zebra set src' templates") \ No newline at end of file + log_warn("Delete key '%s' is not supported for 'zebra set src' templates" % str(key)) \ No newline at end of file diff --git a/src/sonic-bgpcfgd/tests/test_setsrc.py b/src/sonic-bgpcfgd/tests/test_setsrc.py index 5d1a819088..4de72102b6 100644 --- a/src/sonic-bgpcfgd/tests/test_setsrc.py +++ b/src/sonic-bgpcfgd/tests/test_setsrc.py @@ -58,5 +58,6 @@ def test_set_handler_invalid_ip(mocked_log_err): @patch('bgpcfgd.managers_setsrc.log_warn') def test_del_handler(mocked_log_warn): m = constructor() - m.del_handler("Loopback0|10.1.0.32/32") - mocked_log_warn.assert_called_with("Delete command is not supported for 'zebra set src' templates") + del_key = "Loopback0|10.1.0.32/32" + m.del_handler(del_key) + mocked_log_warn.assert_called_with("Delete key '%s' is not supported for 'zebra set src' templates" % del_key)