Skip to content

Commit 4c7e54a

Browse files
[qos reload] Fix "config qos reload" overriding entire CONFIG_DB (#3479)
Fixes #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 <[email protected]>
1 parent 544584e commit 4c7e54a

4 files changed

Lines changed: 1574 additions & 190 deletions

File tree

config/main.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3141,7 +3141,7 @@ def reload(ctx, no_dynamic_buffer, no_delay, dry_run, json_data, ports, verbose)
31413141

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

@@ -3187,11 +3187,27 @@ def reload(ctx, no_dynamic_buffer, no_delay, dry_run, json_data, ports, verbose)
31873187
)
31883188
if os.path.isfile(qos_template_file):
31893189
cmd_ns = [] if ns is DEFAULT_NAMESPACE else ['-n', str(ns)]
3190-
fname = "{}{}".format(dry_run, asic_id_suffix) if dry_run else "config-db"
3191-
command = [SONIC_CFGGEN_PATH] + cmd_ns + from_db + ['-t', '{},{}'.format(buffer_template_file, fname), '-t', '{},{}'.format(qos_template_file, fname), '-y', sonic_version_file]
3192-
# Apply the configurations only when both buffer and qos
3193-
# configuration files are present
3190+
buffer_fname = "/tmp/cfg_buffer{}.json".format(asic_id_suffix)
3191+
qos_fname = "/tmp/cfg_qos{}.json".format(asic_id_suffix)
3192+
3193+
command = [SONIC_CFGGEN_PATH] + cmd_ns + from_db + [
3194+
'-t', '{},{}'.format(buffer_template_file, buffer_fname),
3195+
'-t', '{},{}'.format(qos_template_file, qos_fname),
3196+
'-y', sonic_version_file
3197+
]
31943198
clicommon.run_command(command, display_cmd=True)
3199+
3200+
command = [SONIC_CFGGEN_PATH] + cmd_ns + ["-j", buffer_fname, "-j", qos_fname]
3201+
if dry_run:
3202+
out, rc = clicommon.run_command(command + ["--print-data"], display_cmd=True, return_cmd=True)
3203+
if rc != 0:
3204+
# clicommon.run_command does this by default when rc != 0 and return_cmd=False
3205+
sys.exit(rc)
3206+
with open("{}{}".format(dry_run, asic_id_suffix), 'w') as f:
3207+
json.dump(json.loads(out), f, sort_keys=True, indent=4)
3208+
else:
3209+
clicommon.run_command(command + ["--write-to-db"], display_cmd=True)
3210+
31953211
else:
31963212
click.secho("QoS definition template not found at {}".format(
31973213
qos_template_file

0 commit comments

Comments
 (0)