Skip to content

Commit

Permalink
[sonic-cfggen] Load JSON files before minigraph file (#4202)
Browse files Browse the repository at this point in the history
If sonic-cfggen is passed the -m argument (to load the minigraph file) along with one or more -j <json_file> arguments, load the JSON files before loading the minigraph file.

This ensures that the init_cfg.json file is loaded before the minigraph, therefore the minigraph can override any default configuration options specified in init_cfg.json. Currently, the behavior is reversed.

Note: This is not an issue if loading loading multiple JSON files, because sonic-cfggen loads them in the left-to-right order they were specified on the command line, therefore providing flexibility for loading JSON files in a specific order. As long as init_cfg.json is specified before config_db.json, the values specified in config_db.json will take precedence.
  • Loading branch information
jleveque authored and yxieca committed Mar 2, 2020
1 parent f2e60f8 commit 7a095dc
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/sonic-config-engine/sonic-cfggen
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ def main():
sys.exit(1)
deep_update(data, {'PORT': ports})

for json_file in args.json:
with open(json_file, 'r') as stream:
deep_update(data, FormatConverter.to_deserialized(json.load(stream)))

if args.minigraph != None:
minigraph = args.minigraph
if platform:
Expand All @@ -205,10 +209,6 @@ def main():
additional_data = yaml.load(stream)
deep_update(data, FormatConverter.to_deserialized(additional_data))

for json_file in args.json:
with open(json_file, 'r') as stream:
deep_update(data, FormatConverter.to_deserialized(json.load(stream)))

if args.additional_data != None:
deep_update(data, json.loads(args.additional_data))

Expand Down

0 comments on commit 7a095dc

Please sign in to comment.