Skip to content

Commit

Permalink
[config] Reduce Calls to SONiC Cfggen (sonic-net#1052)
Browse files Browse the repository at this point in the history
* [config] Reduce Calls to SONiC Cfggen

Calls to sonic-cfggen is CPU expensive. This PR reduces calls to
sonic-cfggen during config-setup when configuring buffer/qos.

singed-off-by: Tamer Ahmed <tamer.ahmed@microsoft.com>

* review comment, apply both buffer and qos configs or none
  • Loading branch information
tahmed-dev authored Aug 19, 2020
1 parent 8768580 commit 5263b54
Showing 1 changed file with 13 additions and 41 deletions.
54 changes: 13 additions & 41 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1562,63 +1562,35 @@ def reload():
click.secho(
"Command 'qos reload' failed with invalid namespace '{}'".
format(ns),
fg='yellow'
fg="yellow"
)
raise click.Abort()
asic_id_suffix = str(asic_id)

buffer_template_file = os.path.join(
hwsku_path,
asic_id_suffix,
'buffers.json.j2'
)
buffer_output_file = "/tmp/buffers{}.json".format(asic_id_suffix)
qos_output_file = "/tmp/qos{}.json".format(asic_id_suffix)

cmd_ns = "" if ns is DEFAULT_NAMESPACE else "-n {}".format(ns)
buffer_template_file = os.path.join(hwsku_path, asic_id_suffix, "buffers.json.j2")
if os.path.isfile(buffer_template_file):
command = "{} {} -d -t {} > {}".format(
SONIC_CFGGEN_PATH,
cmd_ns,
buffer_template_file,
buffer_output_file
)
clicommon.run_command(command, display_cmd=True)
qos_template_file = os.path.join(
hwsku_path,
asic_id_suffix,
'qos.json.j2'
)
sonic_version_file = os.path.join(
'/etc/sonic/', 'sonic_version.yml'
)
qos_template_file = os.path.join(hwsku_path, asic_id_suffix, "qos.json.j2")
if os.path.isfile(qos_template_file):
command = "{} {} -d -t {} -y {} > {}".format(
cmd_ns = "" if ns is DEFAULT_NAMESPACE else "-n {}".format(ns)
sonic_version_file = os.path.join('/', "etc", "sonic", "sonic_version.yml")
command = "{} {} -d -t {},config-db -t {},config-db -y {} --write-to-db".format(
SONIC_CFGGEN_PATH,
cmd_ns,
buffer_template_file,
qos_template_file,
sonic_version_file,
qos_output_file
sonic_version_file
)
clicommon.run_command(command, display_cmd=True)
# Apply the configurations only when both buffer and qos
# configuration files are presented
command = "{} {} -j {} --write-to-db".format(
SONIC_CFGGEN_PATH, cmd_ns, buffer_output_file
)
clicommon.run_command(command, display_cmd=True)
command = "{} {} -j {} --write-to-db".format(
SONIC_CFGGEN_PATH, cmd_ns, qos_output_file
)
# configuration files are present
clicommon.run_command(command, display_cmd=True)
else:
click.secho('QoS definition template not found at {}'.format(
click.secho("QoS definition template not found at {}".format(
qos_template_file
), fg='yellow')
), fg="yellow")
else:
click.secho('Buffer definition template not found at {}'.format(
click.secho("Buffer definition template not found at {}".format(
buffer_template_file
), fg='yellow')
), fg="yellow")

#
# 'warm_restart' group ('config warm_restart ...')
Expand Down

0 comments on commit 5263b54

Please sign in to comment.