Skip to content

Commit c8f13b8

Browse files
tahmed-devsanthosh-kt
authored andcommitted
[dhcp-relay] Reduce Calls to SONiC Cfggen (sonic-net#5175)
Calls to sonic-cfggen is CPU expensive. This PR reduces calls to sonic-cfggen to one call during startup when starting dhcp-relay service. singed-off-by: Tamer Ahmed <[email protected]>
1 parent dc69dd3 commit c8f13b8

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

dockers/docker-dhcp-relay/Dockerfile.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ RUN apt-get clean -y && \
2525
rm -rf /debs
2626

2727
COPY ["docker_init.sh", "start.sh", "/usr/bin/"]
28-
COPY ["docker-dhcp-relay.supervisord.conf.j2", "wait_for_intf.sh.j2", "/usr/share/sonic/templates/"]
28+
COPY ["docker-dhcp-relay.supervisord.conf.j2", "port-name-alias-map.txt.j2", "wait_for_intf.sh.j2", "/usr/share/sonic/templates/"]
2929
COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
3030
COPY ["critical_processes", "/etc/supervisor"]
3131

dockers/docker-dhcp-relay/docker_init.sh

+13-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22

33
# Generate supervisord config file
44
mkdir -p /etc/supervisor/conf.d/
5-
sonic-cfggen -d -t /usr/share/sonic/templates/docker-dhcp-relay.supervisord.conf.j2 > /etc/supervisor/conf.d/docker-dhcp-relay.supervisord.conf
65

7-
# Generate the script that waits for all interfaces to come up and make it executable
8-
sonic-cfggen -d -t /usr/share/sonic/templates/wait_for_intf.sh.j2 > /usr/bin/wait_for_intf.sh
9-
chmod +x /usr/bin/wait_for_intf.sh
6+
# Generate the following files from templates:
7+
# 1. supervisord configuration
8+
# 2. wait_for_intf.sh, which waits for all interfaces to come up
9+
# 3. port-to-alias name map
10+
CFGGEN_PARAMS=" \
11+
-d \
12+
-t /usr/share/sonic/templates/docker-dhcp-relay.supervisord.conf.j2,/etc/supervisor/conf.d/docker-dhcp-relay.supervisord.conf \
13+
-t /usr/share/sonic/templates/wait_for_intf.sh.j2,/usr/bin/wait_for_intf.sh \
14+
-t /usr/share/sonic/templates/port-name-alias-map.txt.j2,/tmp/port-name-alias-map.txt \
15+
"
16+
sonic-cfggen $CFGGEN_PARAMS
1017

11-
# Generate port name-alias map for isc-dhcp-relay to parse. Each line contains one
12-
# name-alias pair of the form "<name> <alias>"
13-
sonic-cfggen -d --var-json "PORT" | python -c "import sys, json, os; [sys.stdout.write('%s %s\n' % (k, v['alias'] if 'alias' in v else k)) for (k, v) in json.load(sys.stdin).iteritems()]" > /tmp/port-name-alias-map.txt
18+
# Make the script that waits for all interfaces to come up executable
19+
chmod +x /usr/bin/wait_for_intf.sh
1420

1521
# The docker container should start this script as PID 1, so now that supervisord is
1622
# properly configured, we exec supervisord so that it runs as PID 1 for the
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{# Generate port name-alias map for isc-dhcp-relay to parse. Each line contains one #}
2+
{# name-alias pair of the form "<name> <alias>" #}
3+
{% for port, config in PORT.items() %}
4+
{{- port }} {% if "alias" in config %}{{ config["alias"] }}{% else %}{{ port }}{% endif %} {{- "\n" -}}
5+
{% endfor -%}

0 commit comments

Comments
 (0)