Skip to content

Commit 5263b54

Browse files
authored
[config] Reduce Calls to SONiC Cfggen (sonic-net#1052)
* [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 <[email protected]> * review comment, apply both buffer and qos configs or none
1 parent 8768580 commit 5263b54

File tree

1 file changed

+13
-41
lines changed

1 file changed

+13
-41
lines changed

config/main.py

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,63 +1562,35 @@ def reload():
15621562
click.secho(
15631563
"Command 'qos reload' failed with invalid namespace '{}'".
15641564
format(ns),
1565-
fg='yellow'
1565+
fg="yellow"
15661566
)
15671567
raise click.Abort()
15681568
asic_id_suffix = str(asic_id)
15691569

1570-
buffer_template_file = os.path.join(
1571-
hwsku_path,
1572-
asic_id_suffix,
1573-
'buffers.json.j2'
1574-
)
1575-
buffer_output_file = "/tmp/buffers{}.json".format(asic_id_suffix)
1576-
qos_output_file = "/tmp/qos{}.json".format(asic_id_suffix)
1577-
1578-
cmd_ns = "" if ns is DEFAULT_NAMESPACE else "-n {}".format(ns)
1570+
buffer_template_file = os.path.join(hwsku_path, asic_id_suffix, "buffers.json.j2")
15791571
if os.path.isfile(buffer_template_file):
1580-
command = "{} {} -d -t {} > {}".format(
1581-
SONIC_CFGGEN_PATH,
1582-
cmd_ns,
1583-
buffer_template_file,
1584-
buffer_output_file
1585-
)
1586-
clicommon.run_command(command, display_cmd=True)
1587-
qos_template_file = os.path.join(
1588-
hwsku_path,
1589-
asic_id_suffix,
1590-
'qos.json.j2'
1591-
)
1592-
sonic_version_file = os.path.join(
1593-
'/etc/sonic/', 'sonic_version.yml'
1594-
)
1572+
qos_template_file = os.path.join(hwsku_path, asic_id_suffix, "qos.json.j2")
15951573
if os.path.isfile(qos_template_file):
1596-
command = "{} {} -d -t {} -y {} > {}".format(
1574+
cmd_ns = "" if ns is DEFAULT_NAMESPACE else "-n {}".format(ns)
1575+
sonic_version_file = os.path.join('/', "etc", "sonic", "sonic_version.yml")
1576+
command = "{} {} -d -t {},config-db -t {},config-db -y {} --write-to-db".format(
15971577
SONIC_CFGGEN_PATH,
15981578
cmd_ns,
1579+
buffer_template_file,
15991580
qos_template_file,
1600-
sonic_version_file,
1601-
qos_output_file
1581+
sonic_version_file
16021582
)
1603-
clicommon.run_command(command, display_cmd=True)
16041583
# Apply the configurations only when both buffer and qos
1605-
# configuration files are presented
1606-
command = "{} {} -j {} --write-to-db".format(
1607-
SONIC_CFGGEN_PATH, cmd_ns, buffer_output_file
1608-
)
1609-
clicommon.run_command(command, display_cmd=True)
1610-
command = "{} {} -j {} --write-to-db".format(
1611-
SONIC_CFGGEN_PATH, cmd_ns, qos_output_file
1612-
)
1584+
# configuration files are present
16131585
clicommon.run_command(command, display_cmd=True)
16141586
else:
1615-
click.secho('QoS definition template not found at {}'.format(
1587+
click.secho("QoS definition template not found at {}".format(
16161588
qos_template_file
1617-
), fg='yellow')
1589+
), fg="yellow")
16181590
else:
1619-
click.secho('Buffer definition template not found at {}'.format(
1591+
click.secho("Buffer definition template not found at {}".format(
16201592
buffer_template_file
1621-
), fg='yellow')
1593+
), fg="yellow")
16221594

16231595
#
16241596
# 'warm_restart' group ('config warm_restart ...')

0 commit comments

Comments
 (0)