Skip to content

Commit

Permalink
[qos reload] Fix "config qos reload" overriding entire CONFIG_DB (#3479)
Browse files Browse the repository at this point in the history
Fixes sonic-net/sonic-buildimage#15894

- What I did
config qos reload command uses a combination of sonic-cfggen's flags -d and --write-to-db that makes it override entire CONFIG_DB, updating every key. This leads to issues with Orchs, daemons that do not support updating keys in CONFIG_DB. Best case, it causes errors in logs.

- How I did it
First, render templates to temporary files, then load those files into CONFIG_DB.
Also, fixed an issue where using dry_run option only produced QOS config but not the buffer configuration and updated test files accordingly.

- How to verify it
Run on switch:

root@sonic/home/admin# config qos reload
Running command: /usr/local/bin/sonic-cfggen -d -t /usr/share/sonic/device/x86_64-mlnx_msn2100-r0/ACS-MSN2100/buffers_dynamic.json.j2,/tmp/cfg_buffer.json -t /usr/share/sonic/device/x86_64-mlnx_msn2100-r0/ACS-MSN2100/qos.json.j2,/tmp/cfg_qos.json -y /etc/sonic/sonic_version.yml
Running command: /usr/local/bin/sonic-cfggen -j /tmp/cfg_buffer.json -j /tmp/cfg_qos.json --write-to-db

Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
  • Loading branch information
stepanblyschak authored Sep 3, 2024
1 parent 544584e commit 4c7e54a
Show file tree
Hide file tree
Showing 4 changed files with 1,574 additions and 190 deletions.
26 changes: 21 additions & 5 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3141,7 +3141,7 @@ def reload(ctx, no_dynamic_buffer, no_delay, dry_run, json_data, ports, verbose)

_, hwsku_path = device_info.get_paths_to_platform_and_hwsku_dirs()
sonic_version_file = device_info.get_sonic_version_file()
from_db = ['-d', '--write-to-db']
from_db = ['-d']
if dry_run:
from_db = ['--additional-data'] + [str(json_data)] if json_data else []

Expand Down Expand Up @@ -3187,11 +3187,27 @@ def reload(ctx, no_dynamic_buffer, no_delay, dry_run, json_data, ports, verbose)
)
if os.path.isfile(qos_template_file):
cmd_ns = [] if ns is DEFAULT_NAMESPACE else ['-n', str(ns)]
fname = "{}{}".format(dry_run, asic_id_suffix) if dry_run else "config-db"
command = [SONIC_CFGGEN_PATH] + cmd_ns + from_db + ['-t', '{},{}'.format(buffer_template_file, fname), '-t', '{},{}'.format(qos_template_file, fname), '-y', sonic_version_file]
# Apply the configurations only when both buffer and qos
# configuration files are present
buffer_fname = "/tmp/cfg_buffer{}.json".format(asic_id_suffix)
qos_fname = "/tmp/cfg_qos{}.json".format(asic_id_suffix)

command = [SONIC_CFGGEN_PATH] + cmd_ns + from_db + [
'-t', '{},{}'.format(buffer_template_file, buffer_fname),
'-t', '{},{}'.format(qos_template_file, qos_fname),
'-y', sonic_version_file
]
clicommon.run_command(command, display_cmd=True)

command = [SONIC_CFGGEN_PATH] + cmd_ns + ["-j", buffer_fname, "-j", qos_fname]
if dry_run:
out, rc = clicommon.run_command(command + ["--print-data"], display_cmd=True, return_cmd=True)
if rc != 0:
# clicommon.run_command does this by default when rc != 0 and return_cmd=False
sys.exit(rc)
with open("{}{}".format(dry_run, asic_id_suffix), 'w') as f:
json.dump(json.loads(out), f, sort_keys=True, indent=4)
else:
clicommon.run_command(command + ["--write-to-db"], display_cmd=True)

else:
click.secho("QoS definition template not found at {}".format(
qos_template_file
Expand Down
Loading

0 comments on commit 4c7e54a

Please sign in to comment.