Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sonic-cfggen] make minigraph parser fail when speed and lanes are not in PORT table #10228

Merged
merged 4 commits into from
Apr 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/sonic-config-engine/sonic-cfggen
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,19 @@ def _get_jinja2_env(paths):

return env

def _must_field_by_yang(data, table, must_fields):
"""
Check if table contains must field based on yang definition
"""
if table not in data:
return

for must_field in must_fields:
for _, fields in data[table].items():
if must_field not in fields:
print(must_field, 'is a must field in', table, file=sys.stderr)
sys.exit(1)

def main():
parser=argparse.ArgumentParser(description="Render configuration file from minigraph data and jinja2 template.")
group = parser.add_mutually_exclusive_group()
Expand Down Expand Up @@ -335,6 +348,8 @@ def main():
deep_update(data, parse_xml(minigraph, platform, asic_name=asic_name))
else:
deep_update(data, parse_xml(minigraph, port_config_file=args.port_config, asic_name=asic_name, hwsku_config_file=args.hwsku_config))
# check if minigraph parser has speed and lanes in PORT table
_must_field_by_yang(data, 'PORT', ['speed', 'lanes'])

if args.device_description is not None:
deep_update(data, parse_device_desc_xml(args.device_description))
Expand Down