From a15d79b6f1dc6c54350cc119e8186fa0c35ac42f Mon Sep 17 00:00:00 2001 From: pavel-shirshov Date: Thu, 30 Jul 2020 02:46:19 -0700 Subject: [PATCH] [bgpcfgd]: Clarify error messages on reset Loopback0 ip address (#5062) To clarify error messages in case the ip address for Loopback is already set. It doesn't make sense to call correct ip address as ambiguous in this case --- src/sonic-bgpcfgd/bgpcfgd | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/sonic-bgpcfgd/bgpcfgd b/src/sonic-bgpcfgd/bgpcfgd index c94e5c3b54..3bedd86790 100755 --- a/src/sonic-bgpcfgd/bgpcfgd +++ b/src/sonic-bgpcfgd/bgpcfgd @@ -788,16 +788,24 @@ class ZebraSetSrc(Manager): ip_addr_w_mask = key.replace("Loopback0|", "") slash_pos = ip_addr_w_mask.rfind("/") if slash_pos == -1: - log_err("Wrong Loopback0 ip address: '%s'" % ip_addr_w_mask) + log_err("Wrong Loopback0 ip prefix: '%s'" % ip_addr_w_mask) return True ip_addr = ip_addr_w_mask[:slash_pos] try: - if TemplateFabric.is_ipv4(ip_addr) and self.lo_ipv4 is None: - self.lo_ipv4 = ip_addr - txt = self.zebra_set_src_template.render(rm_name="RM_SET_SRC", lo_ip=ip_addr, ip_proto="") - elif TemplateFabric.is_ipv6(ip_addr) and self.lo_ipv6 is None: - self.lo_ipv6 = ip_addr - txt = self.zebra_set_src_template.render(rm_name="RM_SET_SRC6", lo_ip=ip_addr, ip_proto="v6") + if TemplateFabric.is_ipv4(ip_addr): + if self.lo_ipv4 is None: + self.lo_ipv4 = ip_addr + txt = self.zebra_set_src_template.render(rm_name="RM_SET_SRC", lo_ip=ip_addr, ip_proto="") + else: + log_warn("Update command is not supported for set src templates. current ip='%s'. new ip='%s'" % (self.lo_ipv4, ip_addr)) + return True + elif TemplateFabric.is_ipv6(ip_addr): + if self.lo_ipv6 is None: + self.lo_ipv6 = ip_addr + txt = self.zebra_set_src_template.render(rm_name="RM_SET_SRC6", lo_ip=ip_addr, ip_proto="v6") + else: + log_warn("Update command is not supported for set src templates. current ip='%s'. new ip='%s'" % (self.lo_ipv6, ip_addr)) + return True else: log_err("Got ambiguous ip address '%s'" % ip_addr) return True