[docker-radv] Fix startup issues (#5230)

**- Why I did it**

PR https://github.com/Azure/sonic-buildimage/pull/4599 introduced two bugs in the startup of the router advertiser container:

1. References to the `wait_for_intf.sh` script were changed to `wait_for_link.sh`, but the actual script was not renamed
2. The `ipv6_found` Jinja2 variable added to the supervisor config file goes out of scope before it is read.

**- How I did it**
1. Rename the `wait_for_intf.sh` script to `wait_for_link.sh`
2. Use the Jinja2 "namespace" construct to fix the scope issue

**- How to verify it**

Ensure all processes in the radv container start properly under the correct conditions (i.e., whether or not there is at least one VLAN with an IPv6 address assigned).
This commit is contained in:
Joe LeVeque 2020-08-21 13:12:01 -07:00 committed by Abhishek Dosi
parent 61d5ac0fbd
commit 1ee4fa5a40
4 changed files with 17 additions and 18 deletions

View File

@ -25,7 +25,7 @@ RUN apt-get clean -y && \
rm -rf /debs
COPY ["docker-init.sh", "/usr/bin/"]
COPY ["radvd.conf.j2", "wait_for_intf.sh.j2", "docker-router-advertiser.supervisord.conf.j2", "/usr/share/sonic/templates/"]
COPY ["radvd.conf.j2", "wait_for_link.sh.j2", "docker-router-advertiser.supervisord.conf.j2", "/usr/share/sonic/templates/"]
COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
COPY ["critical_processes", "/etc/supervisor"]

View File

@ -7,7 +7,7 @@ sonic-cfggen -d -t /usr/share/sonic/templates/docker-router-advertiser.superviso
sonic-cfggen -d -t /usr/share/sonic/templates/radvd.conf.j2 > /etc/radvd.conf
# Generate the script that waits for pertinent interfaces to come up and make it executable
sonic-cfggen -d -t /usr/share/sonic/templates/wait_for_intf.sh.j2 > /usr/bin/wait_for_intf.sh
chmod +x /usr/bin/wait_for_intf.sh
sonic-cfggen -d -t /usr/share/sonic/templates/wait_for_link.sh.j2 > /usr/bin/wait_for_link.sh
chmod +x /usr/bin/wait_for_link.sh
exec /usr/bin/supervisord

View File

@ -26,20 +26,21 @@ stdout_logfile=syslog
stderr_logfile=syslog
dependent_startup=true
{# Router advertiser should only run on ToR (T0) devices #}
{% if DEVICE_METADATA.localhost.type == "ToRRouter" %}
{% if VLAN_INTERFACE %}
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
{# Router advertiser should only run on ToR (T0) devices which have #}
{# at least one VLAN interface which has an IPv6 address asigned #}
{%- set vlan_v6 = namespace(count=0) -%}
{%- if DEVICE_METADATA.localhost.type == "ToRRouter" -%}
{%- if VLAN_INTERFACE -%}
{%- for (name, prefix) in VLAN_INTERFACE|pfx_filter -%}
{# If this VLAN has an IPv6 address... #}
{% if prefix | ipv6 %}
{% set ipv6_found = true %}
{% endif %}
{% endfor %}
{% endif %}
{%- if prefix | ipv6 -%}
{%- set vlan_v6.count = vlan_v6.count + 1 -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endif -%}
{# Enusre at least one ipv6 vlan interface #}
{% if ipv6_found == true %}
{%- if vlan_v6.count > 0 %}
[program:wait_for_link]
command=/usr/bin/wait_for_link.sh
priority=3
@ -60,6 +61,4 @@ stdout_logfile=syslog
stderr_logfile=syslog
dependent_startup=true
dependent_startup_wait_for=wait_for_link:exited
{% endif %}
{% endif %}
{% endif -%}