Skip to content

sonic-cfggen with sonicv2 dockers #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jan 20, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions dockers/docker-fpm/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ debs/{{ deb }}{{' '}}
RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y
RUN rm -rf /debs

COPY ["start.sh", "/usr/bin/"]
COPY ["*.j2", "/etc/swss/bgp"]
COPY ["start.sh", "config.sh", "/usr/bin/"]

ENTRYPOINT /usr/bin/start.sh \
ENTRYPOINT /usr/bin/config.sh \
&& /usr/bin/start.sh \
&& /bin/bash
63 changes: 63 additions & 0 deletions dockers/docker-fpm/bgpd.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
!
{% block banner %}
! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/quagga/bgpd.conf.j2 using minigraph_facts.py
! file: bgpd.conf
!
{% endblock banner %}
!
{% block system_init %}
hostname {{ inventory_hostname }}
password zebra
log syslog informational
log facility local4
! enable password {# {{ en_passwd }} TODO: param needed #}
{% endblock system_init %}
!
{% block bgp_init %}
!
! bgp multiple-instance
!
router bgp {{ minigraph_bgp_asn }}
bgp log-neighbor-changes
bgp bestpath as-path multipath-relax
{# TODO: use lo[0] for backward compatibility, will revisit the case with multiple lo interfaces #}
bgp router-id {{ minigraph_lo_interfaces[0]['addr'] }}
{# advertise loopback #}
{% for lo in minigraph_lo_interfaces %}
{% if lo['addr'] | ipv4 %}
network {{ lo['addr'] }}/32
{% elif lo['addr'] | ipv6 %}
address-family ipv6
network {{ lo['addr'] }}/128
exit-address-family
{% endif %}
{% endfor %}
{% endblock bgp_init %}
{% block vlan_advertisement %}
{% for interface in minigraph_interfaces %}
{% if interface['name'].startswith('Vlan') %}
network {{ interface['subnet'] }}
{% endif %}
{% endfor %}
{% endblock vlan_advertisement %}
{% block bgp_sessions %}
{% for bgp_session in minigraph_bgp %}
{% if bgp_session['asn'] != 0 %}
neighbor {{ bgp_session['addr'] }} remote-as {{ bgp_session['asn'] }}
neighbor {{ bgp_session['addr'] }} description {{ bgp_session['name'] }}
{% if bgp_session['addr'] | ipv6 %}
address-family ipv6
neighbor {{ bgp_session['addr'] }} activate
maximum-paths 64
exit-address-family
{% endif %}
{% endif %}
{% endfor %}
{% endblock bgp_sessions %}
!
maximum-paths 64
!
route-map ISOLATE permit 10
set as-path prepend {{ minigraph_bgp_asn }}
!
13 changes: 13 additions & 0 deletions dockers/docker-fpm/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
Copy link
Collaborator

@qiluo-msft qiluo-msft Jan 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bash [](start = 7, length = 4)

Replace this shell script by a makefile, so it will not update after reboot. #Pending

Copy link
Contributor Author

@taoyl-ms taoyl-ms Jan 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will consider performance issue in later stage. #Closed

Copy link
Collaborator

@lguohan lguohan Jan 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this maybe a good idea, currently it is not clear when the configuration in the docker should be updated and what should happen in the docker. #Closed


sonic-cfggen -m /etc/sonic/minigraph.xml -t /etc/swss/bgp/bgpd.conf.j2 >/etc/quagga/bgpd.conf
sonic-cfggen -m /etc/sonic/minigraph.xml -t /etc/swss/bgp/zebra.conf.j2 >etc/quagga/zebra.conf

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add -e?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think python will return none-zero value itself upon exceptions?

Copy link
Collaborator

@lguohan lguohan Jan 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but if return non zero, what will your config.sh do? goes on?

-e allows you Automatic exit from bash shell script on error


In reply to: 96070348 [](ancestors = 96070348)

sonic-cfggen -m /etc/sonic/minigraph.xml -t /etc/swss/bgp/isolate.j2 >/usr/sbin/bgp-isolate
chown root:root /usr/sbin/bgp-isolate
chmod 0755 /usr/sbin/bgp-isolate

sonic-cfggen -m /etc/sonic/minigraph.xml -t /etc/swss/bgp/unisolate.j2 >/usr/sbin/bgp-unisolate
chown root:root /usr/sbin/bgp-unisolate
chmod 0755 /usr/sbin/bgp-unisolate

20 changes: 20 additions & 0 deletions dockers/docker-fpm/isolate.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
## vtysh only accepts script in stdin, so cannot be directly used in shebang
## Cut the tail of this script and feed vtysh stdin
sed -n -e '9,$p' < "$0" | vtysh "$@"
## Exit with vtysh return code
exit $?

## vtysh script start from next line, which line number MUST eqaul in 'sed' command above

configure terminal
router bgp {{ minigraph_bgp_asn }}
{% for bgp_session in minigraph_bgp %}
neighbor {{ bgp_session['addr'] }} route-map ISOLATE out
{% endfor %}
exit
exit

{% for bgp_session in minigraph_bgp %}
clear ip bgp {{ bgp_session['addr'] }} soft out
{% endfor %}
20 changes: 20 additions & 0 deletions dockers/docker-fpm/unisolate.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
## vtysh only accepts script in stdin, so cannot be directly used in shebang
## Cut the tail of this script and feed vtysh stdin
sed -n -e '9,$p' < "$0" | vtysh "$@"
## Exit with vtysh return code
exit $?

## vtysh script start from next line, which line number MUST eqaul in 'sed' command above

configure terminal
router bgp {{ minigraph_bgp_asn }}
{% for bgp_session in minigraph_bgp %}
no neighbor {{ bgp_session['addr'] }} route-map ISOLATE out
{% endfor %}
exit
exit

{% for bgp_session in minigraph_bgp %}
clear ip bgp {{ bgp_session['addr'] }} soft out
{% endfor %}
61 changes: 61 additions & 0 deletions dockers/docker-fpm/zebra.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
!
{% block banner %}
! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/quagga/zebra.conf.j2 using minigraph_facts.py
! file: zebra.conf
!
{% endblock banner %}
!
{% block sys_init %}
hostname {{ inventory_hostname }}
password zebra
enable password zebra
{% endblock sys_init %}
!
{% block interfaces %}
! Enable link-detect (default disabled)
{% for interface in minigraph_interfaces %}
interface {{ interface['alias'] }}
link-detect
!
{% endfor %}
{% endblock interfaces %}
!
{% block default_route %}
! set static default route to mgmt gateway as a backup to learned default
ip route 0.0.0.0/0 {{ minigraph_mgmt_interface['gwaddr'] }} 200
{% endblock default_route %}
!
{% block source_loopback %}
! Set ip source to loopback for bgp learned routes
route-map RM_SET_SRC permit 10
set src {{ minigraph_lo_interfaces[0]['addr'] }}
!
{% set lo_ipv6_addrs = [] %}
{% if minigraph_lo_interfaces is defined %}
{% for interface in minigraph_lo_interfaces %}
{% if interface['addr'] is defined and interface['addr']|ipv6 %}
{% if lo_ipv6_addrs.append(interface['addr']) %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% if lo_ipv6_addrs|length > 0 %}
route-map RM_SET_SRC6 permit 10
set src {{ lo_ipv6_addrs[0] }}
!
{% endif %}
ip protocol bgp route-map RM_SET_SRC
!
{% if lo_ipv6_addrs|length > 0 %}
ipv6 protocol bgp route-map RM_SET_SRC6
!
{% endif %}
{% endblock source_loopback %}
!
{% block logging %}
log syslog informational
log facility local4
{% endblock logging %}
!

4 changes: 3 additions & 1 deletion dockers/docker-lldp-sv2/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ RUN pip install /python-wheels/sswsdk-2.0.1-py2-none-any.whl && \

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY reconfigure.sh /opt/reconfigure.sh
COPY ["config.sh", "/usr/bin/"]
COPY ["lldpd.j2", "lldpd.conf.j2", "/etc/swss/lldp"]
Copy link
Collaborator

@lguohan lguohan Jan 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add '/' at the end of it so that it is clear this is a directory. #Resolved

Copy link
Contributor Author

@taoyl-ms taoyl-ms Jan 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. #Closed


ENTRYPOINT ["/usr/bin/supervisord"]
ENTRYPOINT /usr/bin/config.sh && /usr/bin/supervisord
6 changes: 6 additions & 0 deletions dockers/docker-lldp-sv2/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

/bin/cp -rf /etc/swss/lldp/lldpd.j2 /etc/default/lldpd
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why replace lldpd with a j2 file?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably just rename lldpd.j2 to lldpd


In reply to: 96061953 [](ancestors = 96061953)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add -e, to exit when there is failure. otherwise this script will always just return success.


In reply to: 96062158 [](ancestors = 96062158,96061953)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


sonic-cfggen -m /etc/sonic/minigraph.xml -t /etc/swss/lldp/lldpd.conf.j2 >etc/lldpd.conf
Copy link
Collaborator

@lguohan lguohan Jan 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tc/lldpd.conf [](start = 75, length = 13)

use abs path here? #Resolved

Copy link
Contributor Author

@taoyl-ms taoyl-ms Jan 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. #Closed


3 changes: 3 additions & 0 deletions dockers/docker-lldp-sv2/lldpd.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% for member in alias_map %}
configure ports {{member['sonic']}} lldp portidsubtype local {{member['hardware']}}
Copy link
Collaborator

@lguohan lguohan Jan 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not hardware name, it is ngs interface name. maybe we can name it as "origin"? #Resolved

Copy link
Contributor Author

@taoyl-ms taoyl-ms Jan 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. #Closed

{% endfor %}
6 changes: 6 additions & 0 deletions dockers/docker-lldp-sv2/lldpd.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
###############################################################################
# Managed by sonic-cfggen
###############################################################################

# Uncomment to start SNMP subagent and enable CDP, SONMP and EDP protocol
DAEMON_ARGS=""
6 changes: 5 additions & 1 deletion dockers/docker-platform-monitor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ RUN apt-get update &&
apt-get -y install \
smartmontools \
sensord \
debs/sonic-config-engine_1.0-1_all.deb \
&& \
apt-get clean -y && apt-get autoclean -y && apt-get autoremove -y

ENTRYPOINT service rsyslog start \
COPY ["config.sh", "/usr/bin/"]

ENTRYPOINT /usr/bin/config.sh \
&& service rsyslog start \
&& service lm-sensors start \
&& service smartmontools start \
&& service sensord start \
Expand Down
5 changes: 5 additions & 0 deletions dockers/docker-platform-monitor/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

hwsku=`sonic-cfggen -m /etc/sonic/minigraph.xml -v minigraph_hwsku`
/bin/cp -rf /usr/share/sonic/$hwsku/sensors.conf /etc/sensors.d/
Copy link
Collaborator

@qiluo-msft qiluo-msft Jan 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sensors [](start = 36, length = 7)

Move to Dockerfile? #Closed

Copy link
Contributor Author

@taoyl-ms taoyl-ms Jan 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run-time determined variable in source path, thus Dockerfile won't work #Closed


4 changes: 3 additions & 1 deletion dockers/docker-snmp-sv2/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ RUN apt-get -y install build-essential wget libssl-dev openssl supervisor && \
rm -rf ~/.cache

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY ["*.j2", "/etc/swss/snmp/"]
COPY ["config.sh", "/usr/bin/"]

## Although exposing ports is not need for host net mode, keep it for possible bridge mode
EXPOSE 161/udp 162/udp

ENTRYPOINT ["/usr/bin/supervisord"]
ENTRYPOINT /usr/bin/config.sh && /usr/bin/supervisord
18 changes: 18 additions & 0 deletions dockers/docker-snmp-sv2/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
if dpkg-query -W --showformat='${Version}' snmp |grep -q "5.7.2"; then
snmp_user=snmp
else
snmp_uesr=Debian-snmp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

snmp_uesr [](start = 2, length = 9)

snmp_user

fi
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do not need this "if" as the snmp version is embedded in the buildimage, we know which snmp version we are using.

just use snmp_user=snmp


#TODO: check with sasha whether this file will be generated by base image or in container
Copy link
Collaborator

@qiluo-msft qiluo-msft Jan 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file [](start = 32, length = 9)

Do you mean var.yml?
Would you also change sonic-mgmt before this PR? #Closed

sonic-cfggen -m /etc/sonic/minigraph.xml -v /etc/sonic/var/yml -t /etc/swss/snmp/sysDescription.j2 >etc/ssw/sysDescription
Copy link
Collaborator

@lguohan lguohan Jan 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ar/yml [](start = 56, length = 7)

var.yml #Resolved


sonic-cfggen -a '{"snmp_user":"'$snmp_user'"}' -t /etc/swss/snmp/snmpd.j2 >/etc/default/snmpd

sonic-cfggen -m /etc/sonic/minigraph.xml -v /etc/sonic/var.yml -t /etc/swss/snmp/snmpd.conf.j2 >etc/snmp/snmpd.conf
Copy link
Collaborator

@lguohan lguohan Jan 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

etc/snmp/snmpd.con [](start = 96, length = 18)

use abs path all for generated file #Resolved


hwsku=`sonic-cfggen -m /etc/sonic/minigraph.xml -v minigraph_hwsku`
/bin/cp -rf /usr/share/sonic/$hwsku/alias_map.json /etc/snmp/
Copy link
Collaborator

@lguohan lguohan Jan 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r [](start = 9, length = 1)

you do not need -r here. #Resolved



Loading