From e942575ba60edd8f96364a00ca63dc55f1eb5ff9 Mon Sep 17 00:00:00 2001 From: Zhenhong Zhao Date: Mon, 24 Aug 2020 19:52:49 -0700 Subject: [PATCH] Fixed for erasing LGTM alert and other minor issues --- dockers/docker-fpm-frr/docker_init.sh | 2 +- .../docker-fpm-frr/frr/ospfd/ospfd.conf.j2 | 2 + src/sonic-bgpcfgd/bgpcfgd_no_template | 37 +++++++++++++------ .../tests/sample_output/staticd_frr.conf | 1 + 4 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 dockers/docker-fpm-frr/frr/ospfd/ospfd.conf.j2 diff --git a/dockers/docker-fpm-frr/docker_init.sh b/dockers/docker-fpm-frr/docker_init.sh index 072b17391089..cfbf0f816626 100755 --- a/dockers/docker-fpm-frr/docker_init.sh +++ b/dockers/docker-fpm-frr/docker_init.sh @@ -18,7 +18,7 @@ CFGGEN_PARAMS=" \ " if [ -n "$TEMPL_CONFIG" ] && [ "$TEMPL_CONFIG" == "false" ]; then CFGGEN_PARAMS+=" \ - -t /usr/share/sonic/templates/bgdd/bfdd.conf.j2,/etc/frr/bfdd.conf \ + -t /usr/share/sonic/templates/bfdd/bfdd.conf.j2,/etc/frr/bfdd.conf \ -t /usr/share/sonic/templates/ospfd/ospfd.conf.j2,/etc/frr/ospfd.conf \ " fi diff --git a/dockers/docker-fpm-frr/frr/ospfd/ospfd.conf.j2 b/dockers/docker-fpm-frr/frr/ospfd/ospfd.conf.j2 new file mode 100644 index 000000000000..b31926919ce4 --- /dev/null +++ b/dockers/docker-fpm-frr/frr/ospfd/ospfd.conf.j2 @@ -0,0 +1,2 @@ +{% include "ospfd.conf.db.comm_list.j2" %} +{% include "ospfd.conf.db.interface.j2" %} diff --git a/src/sonic-bgpcfgd/bgpcfgd_no_template b/src/sonic-bgpcfgd/bgpcfgd_no_template index 37d684c723e0..9e8194deaf0e 100755 --- a/src/sonic-bgpcfgd/bgpcfgd_no_template +++ b/src/sonic-bgpcfgd/bgpcfgd_no_template @@ -8,7 +8,6 @@ import os from swsssdk import ConfigDBConnector import socket import threading -import pty import Queue import signal import re @@ -82,7 +81,6 @@ class BgpdClientMgr(threading.Thread): 'BGP_GLOBALS': ['bgpd'], 'BGP_GLOBALS_AF': ['bgpd'], 'PREFIX_SET': ['bgpd'], - 'PREFIX': ['bgpd'], 'COMMUNITY_SET': ['bgpd'], 'EXTENDED_COMMUNITY_SET': ['bgpd'], 'ROUTE_MAP': ['zebra', 'bgpd', 'ospfd'], @@ -498,6 +496,10 @@ class BGPKeyMapInfo: else: self.hdl_func = hdlr self.data = data + def __eq__(self, other): + return set(self.daemons) == set(other.daemons) and self.run_cmd == other.run_cmd + def __ne__(self, other): + return set(self.daemons) != set(other.daemons) or self.run_cmd != other.run_cmd def get_command(self, daemon, op, st_idx, *vals): return self.hdl_func(daemon, self.run_cmd, op, st_idx, vals, self.data) def __str__(self): @@ -544,6 +546,10 @@ class BGPKeyMapList(list): except ValueError: pass super(BGPKeyMapList, self).append((db_field, BGPKeyMapInfo(cmd_str, hdl_func, hdl_data))) + def __eq__(self, other): + return super(BGPKeyMapList, self).__eq__(other) and self.table_name == other.table_name and self.table_key == self.table_key + def __ne__(self, other): + return super(BGPKeyMapList, self).__ne__(other) or self.table_name != other.table_name or self.table_key != self.table_key @staticmethod def get_map_field_key(field): if type(field) is str: @@ -1177,7 +1183,6 @@ def handle_ospf_if_mtu_ignore(daemon, cmd_str, op, st_idx, args, data): def handle_ospf_if_nwtype(daemon, cmd_str, op, st_idx, args, data): cmd_list = [] - if_addr = "" if args[1] == '0.0.0.0' else args[1] no_op = 'no ' if op == CachedDataWithOp.OP_DELETE else '' nwtype = '' @@ -1234,7 +1239,6 @@ def handle_igmp_if_enable(daemon, cmd_str, op, st_idx, args, data): def handle_ip_sla_common(daemon, cmd_str, op, st_idx, args, data): cmd_list = [] - param_value = args[0] syslog.syslog(syslog.LOG_INFO, 'handle_ip_sla cmd_str {} op {} st_idx {} args {} data {}'.format( cmd_str, op, st_idx, args, data)) @@ -1248,7 +1252,6 @@ def handle_ip_sla_common(daemon, cmd_str, op, st_idx, args, data): def handle_ip_sla_tcp_connect(daemon, cmd_str, op, st_idx, args, data): cmd_list = [] - param_value = args[0] syslog.syslog(syslog.LOG_INFO, 'handle_ip_sla_tcp_connect cmd_str {} op {} st_idx {} args {} data {}'.format( cmd_str, op, st_idx, args, data)) @@ -1265,7 +1268,6 @@ def handle_ip_sla_tcp_connect(daemon, cmd_str, op, st_idx, args, data): def handle_ip_sla_icmp_echo(daemon, cmd_str, op, st_idx, args, data): cmd_list = [] - param_value = args[0] syslog.syslog(syslog.LOG_INFO, 'handle_ip_sla_icmp_echo cmd_str {} op {} st_idx {} args {} data {}'.format( cmd_str, op, st_idx, args, data)) @@ -1543,6 +1545,8 @@ class MatchPrefix: else: self.min_len = self.max_len = None self.action = action + def __hash__(self): + return hash((self.ip_prefix, self.min_len, self.max_len)) def __str__(self): ret_str = '%s %s' % (self.action.lower(), self.ip_prefix) if self.min_len is not None: @@ -1554,6 +1558,10 @@ class MatchPrefix: return (self.ip_prefix == other.ip_prefix and self.min_len == other.min_len and self.max_len == other.max_len) + def __ne__(self, other): + return (self.ip_prefix != other.ip_prefix or + self.min_len != other.min_len or + self.max_len != other.max_len) class MatchPrefixList(list): def __init__(self, af_mode = None): @@ -1562,6 +1570,10 @@ class MatchPrefixList(list): self.af = None else: self.af = socket.AF_INET if af_mode == 'ipv4' else socket.AF_INET6 + def __eq__(self, other): + return super(MatchPrefixList, self).__eq__(other) and self.af == other.af + def __ne__(self, other): + return super(MatchPrefixList, self).__ne__(other) or self.af != other.af @staticmethod def __get_ip_af(ip_pfx): ip_pfx = ip_pfx.split('/') @@ -1616,9 +1628,13 @@ class IpNextHop: syslog.syslog(syslog.LOG_ERR, 'Mandatory attribute not found for nexthop') raise ValueError def __eq__(self, other): - return (self.af == other.af and self.blackhole == other.blackhole and + return (self.af == other.af and self.blackhole == other.blackhole and self.ip == other.ip and self.track == other.track and self.interface == other.interface and self.tag == other.tag and self.distance == other.distance and self.nh_vrf == other.nh_vrf) + def __ne__(self, other): + return (self.af != other.af or self.blackhole != other.blackhole or + self.ip != other.ip or self.track != other.track or self.interface != other.interface or + self.tag != other.tag or self.distance != other.distance or self.nh_vrf != other.nh_vrf) def __hash__(self): return hash((self.af, self.blackhole, self.ip, self.track, self.interface, self.tag, self.distance, self.nh_vrf)) def __str__(self): @@ -3334,7 +3350,6 @@ class BGPConfigDaemon: metriccmd = "" metrictypecmd = "" alwayscmd = "" - mapname = "" acclistname = "" rmapoper = "" metricoper = "" @@ -3345,7 +3360,6 @@ class BGPConfigDaemon: if 'route-map' in data: dval = data['route-map'] rmapoper = dval.op - mapname = dval.data rmapcmd = " route-map {}".format(dval.data) if 'access-list' in data: @@ -3398,7 +3412,7 @@ class BGPConfigDaemon: cmd_suffix = "no distribute-list {} out {}".format(acclistname, protocol.lower()) command = "vtysh -c 'configure terminal' -c 'router ospf vrf {}' -c '{}'".\ - format(vrf, cmd_suffix) + format(vrf, cmd_suffix) if not self.__run_command(table, command): syslog.syslog(syslog.LOG_ERR, 'failed to create distribute-list {} {}'.format(protocol, direction)) @@ -3418,7 +3432,7 @@ class BGPConfigDaemon: cmd_suffix = "no redistribute {}".format(protocol.lower()) + del_cmd_suffix command = "vtysh -c 'configure terminal' -c 'router ospf vrf {}' -c '{}'".\ - format(vrf, cmd_suffix) + format(vrf, cmd_suffix) if not self.__run_command(table, command): syslog.syslog(syslog.LOG_ERR, 'failed to create default-info/redistribute {} {}'.format(protocol, direction)) @@ -3429,7 +3443,6 @@ class BGPConfigDaemon: if (direction == "IMPORT"): command = "" if (protocol == "DEFAULT_ROUTE"): - cmd_suffix = "no default-information originate" + cmd_suffix command = "vtysh -c 'configure terminal' -c 'router ospf vrf {}' -c 'no default-information originate'".\ format(vrf) else: diff --git a/src/sonic-config-engine/tests/sample_output/staticd_frr.conf b/src/sonic-config-engine/tests/sample_output/staticd_frr.conf index 31a11d8578aa..75cbbd6df164 100644 --- a/src/sonic-config-engine/tests/sample_output/staticd_frr.conf +++ b/src/sonic-config-engine/tests/sample_output/staticd_frr.conf @@ -18,3 +18,4 @@ log facility local4 ! set static default route to mgmt gateway as a backup to learned default ip route 0.0.0.0/0 10.0.0.1 200 !! +!