Skip to content

Commit 30fcbd0

Browse files
author
Stepan Blyschak
committed
[frr] fix pfx_filter to fix bgpd.conf.j2 rendering when no vlan
interfaces Otherwise: " Traceback (most recent call last): File "/usr/local/bin/sonic-cfggen", line 276, in <module> main() File "/usr/local/bin/sonic-cfggen", line 253, in main print(template.render(sort_data(data))) File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 1008, in render return self.environment.handle_exception(exc_info, True) File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 780, in handle_exception reraise(exc_type, exc_value, tb) File "/usr/share/sonic/templates/bgpd.conf.j2", line 49, in top-level template code {% block vlan_advertisement %} File "/usr/share/sonic/templates/bgpd.conf.j2", line 50, in block "vlan_advertisement" {% for (name, prefix) in VLAN_INTERFACE|pfx_filter %} File "/usr/local/bin/sonic-cfggen", line 96, in pfx_filter for key,val in value.items(): jinja2.exceptions.UndefinedError: 'VLAN_INTERFACE' is undefined " and " root@arc-switch1004:/# vtysh Hello, this is FRRouting (version 7.0.1-sonic). Copyright 1996-2005 Kunihiro Ishiguro, et al. arc-switch1004# show bgp su % BGP instance not found arc-switch1004# root@arc-switch1004:/# cat /etc/frr/bgpd.conf root@arc-switch1004:/# " Signed-off-by: Stepan Blyschak <[email protected]>
1 parent 95452b7 commit 30fcbd0

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/sonic-config-engine/sonic-cfggen

+9-5
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ minigraph file, config DB, json file(s), yaml files(s), command line input,
66
and write the data into DB, print as json, or render a jinja2 config template.
77
88
Examples:
9-
Render template with minigraph:
9+
Render template with minigraph:
1010
sonic-cfggen -m -t /usr/share/template/bgpd.conf.j2
11-
Dump config DB content into json file:
11+
Dump config DB content into json file:
1212
sonic-cfggen -d --print-data > db_dump.json
1313
Load content of json file into config DB:
1414
sonic-cfggen -j db_dump.json --write-to-db
@@ -93,6 +93,10 @@ def pfx_filter(value):
9393
For eg - VLAN_INTERFACE|Vlan1000 vs VLAN_INTERFACE|Vlan1000|192.168.0.1/21
9494
"""
9595
table = OrderedDict()
96+
97+
if not value:
98+
return table
99+
96100
for key,val in value.items():
97101
if not isinstance(key, tuple):
98102
continue
@@ -104,7 +108,7 @@ class FormatConverter:
104108
We will move to DB schema and remove this class when the config templates are modified.
105109
106110
TODO(taoyl): Current version of config db only supports BGP admin states.
107-
All other configuration are still loaded from minigraph. Plan to remove
111+
All other configuration are still loaded from minigraph. Plan to remove
108112
minigraph and move everything into config db in a later commit.
109113
"""
110114
@staticmethod
@@ -214,7 +218,7 @@ def main():
214218

215219
for yaml_file in args.yaml:
216220
with open(yaml_file, 'r') as stream:
217-
additional_data = yaml.load(stream)
221+
additional_data = yaml.load(stream)
218222
deep_update(data, FormatConverter.to_deserialized(additional_data))
219223

220224
for json_file in args.json:
@@ -223,7 +227,7 @@ def main():
223227

224228
if args.additional_data != None:
225229
deep_update(data, json.loads(args.additional_data))
226-
230+
227231
if args.from_db:
228232
configdb = ConfigDBConnector(**db_kwargs)
229233
configdb.connect()

0 commit comments

Comments
 (0)