Skip to content

Commit cd330f0

Browse files
authored
[sonic-cfggen] make minigraph parser fail when speed and lanes are not in PORT table (sonic-net#10228)
Why I did it Config db schema generated by minigraph can’t pass yang validation, PORT table does not have 'lanes' and 'speed' field. How I did it Make cfggen command fail when 'lanes' and 'speed' are not provided How to verify it Run 'sonic-cfggen -m xxx.xml --print-data' to make sure command fail when 'lanes' and 'speed' not in PORT table
1 parent 011c21d commit cd330f0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/sonic-config-engine/sonic-cfggen

+15
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,19 @@ def _get_jinja2_env(paths):
247247

248248
return env
249249

250+
def _must_field_by_yang(data, table, must_fields):
251+
"""
252+
Check if table contains must field based on yang definition
253+
"""
254+
if table not in data:
255+
return
256+
257+
for must_field in must_fields:
258+
for _, fields in data[table].items():
259+
if must_field not in fields:
260+
print(must_field, 'is a must field in', table, file=sys.stderr)
261+
sys.exit(1)
262+
250263
def main():
251264
parser=argparse.ArgumentParser(description="Render configuration file from minigraph data and jinja2 template.")
252265
group = parser.add_mutually_exclusive_group()
@@ -335,6 +348,8 @@ def main():
335348
deep_update(data, parse_xml(minigraph, platform, asic_name=asic_name))
336349
else:
337350
deep_update(data, parse_xml(minigraph, port_config_file=args.port_config, asic_name=asic_name, hwsku_config_file=args.hwsku_config))
351+
# check if minigraph parser has speed and lanes in PORT table
352+
_must_field_by_yang(data, 'PORT', ['speed', 'lanes'])
338353

339354
if args.device_description is not None:
340355
deep_update(data, parse_device_desc_xml(args.device_description))

0 commit comments

Comments
 (0)