From 231d309b69be939a1dba91b3dce33b34123aafc0 Mon Sep 17 00:00:00 2001 From: Prince Sunny Date: Mon, 10 Jun 2019 14:02:55 -0700 Subject: [PATCH] Generate interface table to have an entry designated to default VRF. (#2848) * Generate default VRF table for router interfaces * Updated jinja2 template to have prefix filter --- .../docker-dhcp-relay.supervisord.conf.j2 | 6 +++--- dockers/docker-dhcp-relay/wait_for_intf.sh.j2 | 6 +++--- dockers/docker-fpm-frr/bgpd.conf.j2 | 8 ++++---- dockers/docker-fpm-frr/frr.conf.j2 | 14 +++++++------- dockers/docker-fpm-frr/zebra.conf.j2 | 6 +++--- dockers/docker-fpm-gobgp/zebra.conf.j2 | 6 +++--- dockers/docker-fpm-quagga/bgpd.conf.j2 | 8 ++++---- dockers/docker-fpm-quagga/zebra.conf.j2 | 6 +++--- dockers/docker-orchagent/ipinip.json.j2 | 8 ++++---- dockers/docker-router-advertiser/radvd.conf.j2 | 2 +- .../docker-router-advertiser/wait_for_intf.sh.j2 | 2 +- files/image_config/interfaces/interfaces.j2 | 4 ++-- files/image_config/ntp/ntp.conf.j2 | 2 +- files/scripts/arp_update | 4 ++-- src/sonic-config-engine/minigraph.py | 7 ++++++- src/sonic-config-engine/sonic-cfggen | 13 +++++++++++++ src/sonic-config-engine/tests/test_cfggen.py | 6 +++--- .../tests/test_minigraph_case.py | 4 ++-- 18 files changed, 65 insertions(+), 47 deletions(-) diff --git a/dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2 b/dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2 index cd18dfa13108..bbc24ecc091c 100644 --- a/dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2 +++ b/dockers/docker-dhcp-relay/docker-dhcp-relay.supervisord.conf.j2 @@ -49,13 +49,13 @@ isc-dhcp-relay-{{ vlan_name }} {# We treat this VLAN as a downstream interface (-id), as we only want to listen for requests #} command=/usr/sbin/dhcrelay -d -m discard -a %%h:%%p %%P --name-alias-map-file /tmp/port-name-alias-map.txt -id {{ vlan_name }} {#- We treat all other interfaces as upstream interfaces (-iu), as we only want to listen for replies #} -{% for (name, prefix) in VLAN_INTERFACE %} +{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %} {% if prefix | ipv4 and name != vlan_name %} -iu {{ name }}{% endif -%} {% endfor %} -{% for (name, prefix) in INTERFACE %} +{% for (name, prefix) in INTERFACE|pfx_filter %} {% if prefix | ipv4 %} -iu {{ name }}{% endif -%} {% endfor %} -{% for (name, prefix) in PORTCHANNEL_INTERFACE %} +{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %} {% if prefix | ipv4 %} -iu {{ name }}{% endif -%} {% endfor %} {% for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %} {{ dhcp_server }}{% endfor %} diff --git a/dockers/docker-dhcp-relay/wait_for_intf.sh.j2 b/dockers/docker-dhcp-relay/wait_for_intf.sh.j2 index 23133706cb6c..bf50abe4f053 100644 --- a/dockers/docker-dhcp-relay/wait_for_intf.sh.j2 +++ b/dockers/docker-dhcp-relay/wait_for_intf.sh.j2 @@ -29,12 +29,12 @@ function wait_until_iface_ready # Wait for all interfaces to be up and ready -{% for (name, prefix) in INTERFACE %} +{% for (name, prefix) in INTERFACE|pfx_filter %} wait_until_iface_ready ${PORT_TABLE_PREFIX} {{ name }} {% endfor %} -{% for (name, prefix) in VLAN_INTERFACE %} +{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %} wait_until_iface_ready ${VLAN_TABLE_PREFIX} {{ name }} {% endfor %} -{% for (name, prefix) in PORTCHANNEL_INTERFACE %} +{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %} wait_until_iface_ready ${LAG_TABLE_PREFIX} {{ name }} {% endfor %} diff --git a/dockers/docker-fpm-frr/bgpd.conf.j2 b/dockers/docker-fpm-frr/bgpd.conf.j2 index 4879736437bc..b69f895ccbed 100644 --- a/dockers/docker-fpm-frr/bgpd.conf.j2 +++ b/dockers/docker-fpm-frr/bgpd.conf.j2 @@ -29,13 +29,13 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }} no bgp default ipv4-unicast bgp graceful-restart restart-time 240 bgp graceful-restart -{% for (name, prefix) in LOOPBACK_INTERFACE %} +{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %} {% if prefix | ipv4 and name == 'Loopback0' %} bgp router-id {{ prefix | ip }} {% endif %} {% endfor %} {# advertise loopback #} -{% for (name, prefix) in LOOPBACK_INTERFACE %} +{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %} {% if prefix | ipv4 and name == 'Loopback0' %} network {{ prefix | ip }}/32 {% elif prefix | ipv6 and name == 'Loopback0' %} @@ -47,7 +47,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }} {% endblock bgp_init %} {% endif %} {% block vlan_advertisement %} -{% for (name, prefix) in VLAN_INTERFACE %} +{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %} {% if prefix | ipv4 %} network {{ prefix }} {% elif prefix | ipv6 %} @@ -108,7 +108,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }} {% if bgp_peer['src_address'] is defined %} neighbor {{ bgp_peer['name'] }} update-source {{ bgp_peer['src_address'] | ip }} {% else %} -{% for (name, prefix) in LOOPBACK_INTERFACE %} +{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %} {% if name == 'Loopback1' %} neighbor {{ bgp_peer['name'] }} update-source {{ prefix | ip }} {% endif %} diff --git a/dockers/docker-fpm-frr/frr.conf.j2 b/dockers/docker-fpm-frr/frr.conf.j2 index d4fdec897da2..7e3d0f458b1f 100644 --- a/dockers/docker-fpm-frr/frr.conf.j2 +++ b/dockers/docker-fpm-frr/frr.conf.j2 @@ -16,7 +16,7 @@ log facility local4 ! {% block interfaces %} ! Enable link-detect (default disabled) -{% for (name, prefix) in INTERFACE %} +{% for (name, prefix) in INTERFACE|pfx_filter %} interface {{ name }} link-detect ! @@ -30,7 +30,7 @@ link-detect ! {% block default_route %} ! set static default route to mgmt gateway as a backup to learned default -{% for (name, prefix) in MGMT_INTERFACE %} +{% for (name, prefix) in MGMT_INTERFACE|pfx_filter %} {% if prefix | ipv4 %} ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200 {% endif %} @@ -41,7 +41,7 @@ ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200 {% set lo_ipv4_addrs = [] %} {% set lo_ipv6_addrs = [] %} {% if LOOPBACK_INTERFACE %} -{% for (name, prefix) in LOOPBACK_INTERFACE %} +{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %} {% if name == 'Loopback0' %} {% if prefix | ipv6 %} {% if lo_ipv6_addrs.append(prefix) %} @@ -87,13 +87,13 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }} {% if DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %} bgp graceful-restart {% endif %} -{% for (name, prefix) in LOOPBACK_INTERFACE %} +{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %} {% if prefix | ipv4 and name == 'Loopback0' %} bgp router-id {{ prefix | ip }} {% endif %} {% endfor %} {# advertise loopback #} -{% for (name, prefix) in LOOPBACK_INTERFACE %} +{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %} {% if prefix | ipv4 and name == 'Loopback0' %} network {{ prefix | ip }}/32 {% elif prefix | ipv6 and name == 'Loopback0' %} @@ -105,7 +105,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }} {% endblock bgp_init %} {% endif %} {% block vlan_advertisement %} -{% for (name, prefix) in VLAN_INTERFACE %} +{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %} {% if prefix | ipv4 %} network {{ prefix }} {% elif prefix | ipv6 %} @@ -173,7 +173,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }} neighbor {{ bgp_peer['name'] }} passive neighbor {{ bgp_peer['name'] }} remote-as {{ deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']] }} neighbor {{ bgp_peer['name'] }} ebgp-multihop 255 -{% for (name, prefix) in LOOPBACK_INTERFACE %} +{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %} {% if name == 'Loopback1' %} neighbor {{ bgp_peer['name'] }} update-source {{ prefix | ip }} {% endif %} diff --git a/dockers/docker-fpm-frr/zebra.conf.j2 b/dockers/docker-fpm-frr/zebra.conf.j2 index 4acb474b0e35..c0357eaed86a 100644 --- a/dockers/docker-fpm-frr/zebra.conf.j2 +++ b/dockers/docker-fpm-frr/zebra.conf.j2 @@ -14,7 +14,7 @@ enable password zebra ! {% block interfaces %} ! Enable link-detect (default disabled) -{% for (name, prefix) in INTERFACE %} +{% for (name, prefix) in INTERFACE|pfx_filter %} interface {{ name }} link-detect ! @@ -28,7 +28,7 @@ link-detect ! {% block default_route %} ! set static default route to mgmt gateway as a backup to learned default -{% for (name, prefix) in MGMT_INTERFACE %} +{% for (name, prefix) in MGMT_INTERFACE|pfx_filter %} {% if prefix | ipv4 %} ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200 {% endif %} @@ -39,7 +39,7 @@ ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200 {% set lo_ipv4_addrs = [] %} {% set lo_ipv6_addrs = [] %} {% if LOOPBACK_INTERFACE %} -{% for (name, prefix) in LOOPBACK_INTERFACE %} +{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %} {% if name == 'Loopback0' %} {% if prefix | ipv6 %} {% if lo_ipv6_addrs.append(prefix) %} diff --git a/dockers/docker-fpm-gobgp/zebra.conf.j2 b/dockers/docker-fpm-gobgp/zebra.conf.j2 index 8b967f98671c..2da0316ae500 100644 --- a/dockers/docker-fpm-gobgp/zebra.conf.j2 +++ b/dockers/docker-fpm-gobgp/zebra.conf.j2 @@ -14,7 +14,7 @@ enable password zebra ! {% block interfaces %} ! Enable link-detect (default disabled) -{% for (name, prefix) in INTERFACE %} +{% for (name, prefix) in INTERFACE|pfx_filter %} interface {{ name }} link-detect ! @@ -28,7 +28,7 @@ link-detect ! {% block default_route %} ! set static default route to mgmt gateway as a backup to learned default -{% for (name, prefix) in MGMT_INTERFACE %} +{% for (name, prefix) in MGMT_INTERFACE|pfx_filter %} {% if prefix | ipv4 %} ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200 {% endif %} @@ -39,7 +39,7 @@ ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200 {% set lo_ipv4_addrs = [] %} {% set lo_ipv6_addrs = [] %} {% if LOOPBACK_INTERFACE %} -{% for (name, prefix) in LOOPBACK_INTERFACE %} +{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %} {% if prefix | ipv6 %} {% if lo_ipv6_addrs.append(prefix) %} {% endif %} diff --git a/dockers/docker-fpm-quagga/bgpd.conf.j2 b/dockers/docker-fpm-quagga/bgpd.conf.j2 index 4879736437bc..b69f895ccbed 100644 --- a/dockers/docker-fpm-quagga/bgpd.conf.j2 +++ b/dockers/docker-fpm-quagga/bgpd.conf.j2 @@ -29,13 +29,13 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }} no bgp default ipv4-unicast bgp graceful-restart restart-time 240 bgp graceful-restart -{% for (name, prefix) in LOOPBACK_INTERFACE %} +{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %} {% if prefix | ipv4 and name == 'Loopback0' %} bgp router-id {{ prefix | ip }} {% endif %} {% endfor %} {# advertise loopback #} -{% for (name, prefix) in LOOPBACK_INTERFACE %} +{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %} {% if prefix | ipv4 and name == 'Loopback0' %} network {{ prefix | ip }}/32 {% elif prefix | ipv6 and name == 'Loopback0' %} @@ -47,7 +47,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }} {% endblock bgp_init %} {% endif %} {% block vlan_advertisement %} -{% for (name, prefix) in VLAN_INTERFACE %} +{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %} {% if prefix | ipv4 %} network {{ prefix }} {% elif prefix | ipv6 %} @@ -108,7 +108,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }} {% if bgp_peer['src_address'] is defined %} neighbor {{ bgp_peer['name'] }} update-source {{ bgp_peer['src_address'] | ip }} {% else %} -{% for (name, prefix) in LOOPBACK_INTERFACE %} +{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %} {% if name == 'Loopback1' %} neighbor {{ bgp_peer['name'] }} update-source {{ prefix | ip }} {% endif %} diff --git a/dockers/docker-fpm-quagga/zebra.conf.j2 b/dockers/docker-fpm-quagga/zebra.conf.j2 index 4acb474b0e35..c0357eaed86a 100644 --- a/dockers/docker-fpm-quagga/zebra.conf.j2 +++ b/dockers/docker-fpm-quagga/zebra.conf.j2 @@ -14,7 +14,7 @@ enable password zebra ! {% block interfaces %} ! Enable link-detect (default disabled) -{% for (name, prefix) in INTERFACE %} +{% for (name, prefix) in INTERFACE|pfx_filter %} interface {{ name }} link-detect ! @@ -28,7 +28,7 @@ link-detect ! {% block default_route %} ! set static default route to mgmt gateway as a backup to learned default -{% for (name, prefix) in MGMT_INTERFACE %} +{% for (name, prefix) in MGMT_INTERFACE|pfx_filter %} {% if prefix | ipv4 %} ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200 {% endif %} @@ -39,7 +39,7 @@ ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200 {% set lo_ipv4_addrs = [] %} {% set lo_ipv6_addrs = [] %} {% if LOOPBACK_INTERFACE %} -{% for (name, prefix) in LOOPBACK_INTERFACE %} +{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %} {% if name == 'Loopback0' %} {% if prefix | ipv6 %} {% if lo_ipv6_addrs.append(prefix) %} diff --git a/dockers/docker-orchagent/ipinip.json.j2 b/dockers/docker-orchagent/ipinip.json.j2 index 7ce291dbdf8c..66bec75da7dc 100644 --- a/dockers/docker-orchagent/ipinip.json.j2 +++ b/dockers/docker-orchagent/ipinip.json.j2 @@ -2,7 +2,7 @@ {% set ipv6_addresses = [] %} {% set ipv4_loopback_addresses = [] %} {% set ipv6_loopback_addresses = [] %} -{% for (name, prefix) in LOOPBACK_INTERFACE %} +{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %} {%- if prefix | ipv4 and name == 'Loopback0' %} {%- set ipv4_addresses = ipv4_addresses.append(prefix) %} {%- set ipv4_loopback_addresses = ipv4_loopback_addresses.append(prefix) %} @@ -12,7 +12,7 @@ {%- set ipv6_loopback_addresses = ipv6_loopback_addresses.append(prefix) %} {%- endif %} {% endfor %} -{% for (name, prefix) in INTERFACE %} +{% for (name, prefix) in INTERFACE|pfx_filter %} {%- if prefix | ipv4 %} {%- set ipv4_addresses = ipv4_addresses.append(prefix) %} {%- endif %} @@ -20,7 +20,7 @@ {%- set ipv6_addresses = ipv6_addresses.append(prefix) %} {%- endif %} {% endfor %} -{% for (name, prefix) in PORTCHANNEL_INTERFACE %} +{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %} {%- if prefix | ipv4 %} {%- set ipv4_addresses = ipv4_addresses.append(prefix) %} {%- endif %} @@ -28,7 +28,7 @@ {%- set ipv6_addresses = ipv6_addresses.append(prefix) %} {%- endif %} {% endfor %} -{% for (name, prefix) in VLAN_INTERFACE %} +{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %} {%- if prefix | ipv4 %} {%- set ipv4_addresses = ipv4_addresses.append(prefix) %} {%- endif %} diff --git a/dockers/docker-router-advertiser/radvd.conf.j2 b/dockers/docker-router-advertiser/radvd.conf.j2 index 940c26fd6588..bc323977b134 100644 --- a/dockers/docker-router-advertiser/radvd.conf.j2 +++ b/dockers/docker-router-advertiser/radvd.conf.j2 @@ -10,7 +10,7 @@ {# If our configuration has VLAN interfaces... #} {% if VLAN_INTERFACE %} -{% for (name, prefix) in VLAN_INTERFACE %} +{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %} {# If this VLAN has an IPv6 address... #} {% if prefix | ipv6 %} interface {{ name }} diff --git a/dockers/docker-router-advertiser/wait_for_intf.sh.j2 b/dockers/docker-router-advertiser/wait_for_intf.sh.j2 index 856c47678f23..a044df0fc996 100644 --- a/dockers/docker-router-advertiser/wait_for_intf.sh.j2 +++ b/dockers/docker-router-advertiser/wait_for_intf.sh.j2 @@ -27,6 +27,6 @@ function wait_until_iface_ready # Wait for all interfaces to be up and ready -{% for (name, prefix) in VLAN_INTERFACE %} +{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %} wait_until_iface_ready ${VLAN_TABLE_PREFIX} {{ name }} {% endfor %} diff --git a/files/image_config/interfaces/interfaces.j2 b/files/image_config/interfaces/interfaces.j2 index 3245d525977d..4e7a115b39a0 100644 --- a/files/image_config/interfaces/interfaces.j2 +++ b/files/image_config/interfaces/interfaces.j2 @@ -10,7 +10,7 @@ auto lo iface lo inet loopback # Use command 'ip addr list dev lo' to check all addresses -{% for (name, prefix) in LOOPBACK_INTERFACE %} +{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %} iface lo {{ 'inet' if prefix | ipv4 else 'inet6' }} static address {{ prefix | ip }} netmask {{ prefix | netmask if prefix | ipv4 else prefix | prefixlen }} @@ -22,7 +22,7 @@ iface lo {{ 'inet' if prefix | ipv4 else 'inet6' }} static # The management network interface auto eth0 {% if MGMT_INTERFACE %} -{% for (name, prefix) in MGMT_INTERFACE %} +{% for (name, prefix) in MGMT_INTERFACE|pfx_filter %} iface eth0 {{ 'inet' if prefix | ipv4 else 'inet6' }} static address {{ prefix | ip }} netmask {{ prefix | netmask if prefix | ipv4 else prefix | prefixlen }} diff --git a/files/image_config/ntp/ntp.conf.j2 b/files/image_config/ntp/ntp.conf.j2 index d7df6bcd2e04..1255369773f0 100644 --- a/files/image_config/ntp/ntp.conf.j2 +++ b/files/image_config/ntp/ntp.conf.j2 @@ -30,7 +30,7 @@ server {{ ntp_server }} iburst #only listen on localhost and eth0 ips (default is to listen on all ip addresses) interface ignore wildcard {% if MGMT_INTERFACE %} -{% for (mgmt_intf, mgmt_prefix) in MGMT_INTERFACE %} +{% for (mgmt_intf, mgmt_prefix) in MGMT_INTERFACE|pfx_filter %} interface listen {{ mgmt_prefix | ip }} {% endfor %} {% else %} diff --git a/files/scripts/arp_update b/files/scripts/arp_update index f7c5ec8bb856..055aa98baf5d 100755 --- a/files/scripts/arp_update +++ b/files/scripts/arp_update @@ -9,9 +9,9 @@ while /bin/true; do # find L3 interfaces which are UP, send ipv6 multicast pings - echo "{% for (name, prefix) in INTERFACE %} {{name}} {% endfor %}" > /tmp/intf_tmp.j2 + echo "{% for (name, prefix) in INTERFACE|pfx_filter %} {{name}} {% endfor %}" > /tmp/intf_tmp.j2 INTERFACE=`sonic-cfggen -d -t /tmp/intf_tmp.j2` - echo "{% for (name, prefix) in PORTCHANNEL_INTERFACE %} {{name}} {% endfor %}" > /tmp/pc_intf_tmp.j2 + echo "{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %} {{name}} {% endfor %}" > /tmp/pc_intf_tmp.j2 PC_INTERFACE=`sonic-cfggen -d -t /tmp/pc_intf_tmp.j2` ALL_INTERFACE="$INTERFACE $PC_INTERFACE" diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index ac22b2b3454f..8d08b399b434 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -515,12 +515,16 @@ def parse_xml(filename, platform=None, port_config_file=None): for intf in intfs: if intf[0][0:4] == 'Vlan': vlan_intfs[intf] = {} + vlan_intfs[intf[0]] = {} elif vlan_invert_mapping.has_key(intf[0]): vlan_intfs[(vlan_invert_mapping[intf[0]], intf[1])] = {} + vlan_intfs[vlan_invert_mapping[intf[0]]] = {} elif intf[0][0:11] == 'PortChannel': pc_intfs[intf] = {} + pc_intfs[intf[0]] = {} else: phyport_intfs[intf] = {} + phyport_intfs[intf[0]] = {} results['INTERFACE'] = phyport_intfs results['VLAN_INTERFACE'] = vlan_intfs @@ -601,9 +605,10 @@ def parse_xml(filename, platform=None, port_config_file=None): for pc_intf in pc_intfs.keys(): # remove portchannels not in PORTCHANNEL dictionary - if pc_intf[0] not in pcs: + if isinstance(pc_intf, tuple) and pc_intf[0] not in pcs: print >> sys.stderr, "Warning: ignore '%s' interface '%s' as '%s' is not in the valid PortChannel list" % (pc_intf[0], pc_intf[1], pc_intf[0]) del pc_intfs[pc_intf] + pc_intfs.pop(pc_intf[0], None) results['PORTCHANNEL_INTERFACE'] = pc_intfs diff --git a/src/sonic-config-engine/sonic-cfggen b/src/sonic-config-engine/sonic-cfggen index 3f7951248c61..e0bd07ff8cf1 100755 --- a/src/sonic-config-engine/sonic-cfggen +++ b/src/sonic-config-engine/sonic-cfggen @@ -86,6 +86,18 @@ def unique_name(l): new_list.append(item) return new_list +def pfx_filter(value): + """INTERFACE Table can have keys in one of the two formats: + string or tuple - This filter skips the string keys and only + take into account the tuple. + For eg - VLAN_INTERFACE|Vlan1000 vs VLAN_INTERFACE|Vlan1000|192.168.0.1/21 + """ + table = OrderedDict() + for key,val in value.items(): + if not isinstance(key, tuple): + continue + table[key] = val + return table class FormatConverter: """Convert config DB based schema to legacy minigraph based schema for backward capability. @@ -234,6 +246,7 @@ def main(): env.filters['ipv4'] = is_ipv4 env.filters['ipv6'] = is_ipv6 env.filters['unique_name'] = unique_name + env.filters['pfx_filter'] = pfx_filter for attr in ['ip', 'network', 'prefixlen', 'netmask']: env.filters[attr] = partial(prefix_attr, attr) template = env.get_template(template_file) diff --git a/src/sonic-config-engine/tests/test_cfggen.py b/src/sonic-config-engine/tests/test_cfggen.py index 5a6c0f62ce26..f267651ff675 100644 --- a/src/sonic-config-engine/tests/test_cfggen.py +++ b/src/sonic-config-engine/tests/test_cfggen.py @@ -107,7 +107,7 @@ def test_minigraph_mgmt_ports(self): def test_minigraph_interfaces(self): argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v "INTERFACE.keys()"' output = self.run_script(argument) - self.assertEqual(output.strip(), "[('Ethernet0', '10.0.0.58/31'), ('Ethernet0', 'FC00::75/126')]") + self.assertEqual(output.strip(), "[('Ethernet0', '10.0.0.58/31'), 'Ethernet0', ('Ethernet0', 'FC00::75/126')]") def test_minigraph_vlans(self): argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v VLAN' @@ -122,7 +122,7 @@ def test_minigraph_vlan_members(self): def test_minigraph_vlan_interfaces(self): argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v "VLAN_INTERFACE.keys()"' output = self.run_script(argument) - self.assertEqual(output.strip(), "[('Vlan1000', '192.168.0.1/27')]") + self.assertEqual(output.strip(), "[('Vlan1000', '192.168.0.1/27'), 'Vlan1000']") def test_minigraph_portchannels(self): argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v PORTCHANNEL' @@ -142,7 +142,7 @@ def test_minigraph_portchannel_members(self): def test_minigraph_portchannel_interfaces(self): argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v "PORTCHANNEL_INTERFACE.keys()"' output = self.run_script(argument) - self.assertEqual(output.strip(), "[('PortChannel01', 'FC00::71/126'), ('PortChannel01', '10.0.0.56/31')]") + self.assertEqual(output.strip(), "['PortChannel01', ('PortChannel01', '10.0.0.56/31'), ('PortChannel01', 'FC00::71/126')]") def test_minigraph_neighbors(self): argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v "DEVICE_NEIGHBOR[\'Ethernet124\']"' diff --git a/src/sonic-config-engine/tests/test_minigraph_case.py b/src/sonic-config-engine/tests/test_minigraph_case.py index 9a859e7fb0f6..d363acdca074 100644 --- a/src/sonic-config-engine/tests/test_minigraph_case.py +++ b/src/sonic-config-engine/tests/test_minigraph_case.py @@ -67,7 +67,7 @@ def test_minigraph_everflow(self): def test_minigraph_interfaces(self): argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v \'INTERFACE.keys()\'' output = self.run_script(argument) - self.assertEqual(output.strip(), "[('Ethernet0', '10.0.0.58/31'), ('Ethernet0', 'FC00::75/126')]") + self.assertEqual(output.strip(), "[('Ethernet0', '10.0.0.58/31'), 'Ethernet0', ('Ethernet0', 'FC00::75/126')]") def test_minigraph_vlans(self): argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v VLAN' @@ -82,7 +82,7 @@ def test_minigraph_vlan_members(self): def test_minigraph_vlan_interfaces(self): argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "VLAN_INTERFACE.keys()"' output = self.run_script(argument) - self.assertEqual(output.strip(), "[('Vlan1000', '192.168.0.1/27')]") + self.assertEqual(output.strip(), "[('Vlan1000', '192.168.0.1/27'), 'Vlan1000']") def test_minigraph_portchannels(self): argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v PORTCHANNEL'