[teamd]: Add teammgrd in docker-teamd (#2064)

Remove the teamd.j2 templates used for starting the teamd. Add
teammgrd instead to manage all port channel related configuration
changes. Remove front panel port related configurations in
interfaces.j2 templates as well.

Remove teamd.sh script and use teammgrd to start all the teamd
processes. Remove all the logics in the start.sh script as well.

Update the sonic-swss submodule.

Signed-off-by: Shu0T1an ChenG <shuche@microsoft.com>
This commit is contained in:
Shuotian Cheng 2018-10-19 03:41:53 -07:00 committed by lguohan
parent 890baedeb6
commit 7313e7d9bc
12 changed files with 26 additions and 183 deletions

View File

@ -25,9 +25,8 @@ RUN dpkg -i \
debs/{{ deb }}{{' '}} debs/{{ deb }}{{' '}}
{%- endfor %} {%- endfor %}
COPY ["start.sh", "teamd.sh", "/usr/bin/"] COPY ["start.sh", "/usr/bin/"]
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"] COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
COPY ["teamd.j2", "/usr/share/sonic/templates/"]
RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y
RUN rm -rf /debs RUN rm -rf /debs

View File

@ -1,40 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
TEAMD_CONF_PATH=/etc/teamd
rm -rf $TEAMD_CONF_PATH
mkdir -p $TEAMD_CONF_PATH
SONIC_ASIC_TYPE=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)
if [ "$SONIC_ASIC_TYPE" == "mellanox" ]; then
MAC_ADDRESS=$(sonic-cfggen -d -v DEVICE_METADATA.localhost.mac)
else
MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}')
fi
# Align last byte
if [ "$SONIC_ASIC_TYPE" == "mellanox" -o "$SONIC_ASIC_TYPE" == "centec" ]; then
last_byte=$(python -c "print '$MAC_ADDRESS'[-2:]")
aligned_last_byte=$(python -c "print format(int(int('$last_byte', 16) & 0b11000000), '02x')") # put mask and take away the 0x prefix
MAC_ADDRESS=$(python -c "print '$MAC_ADDRESS'[:-2] + '$aligned_last_byte'") # put aligned byte into the end of MAC
fi
for pc in `sonic-cfggen -d -v "PORTCHANNEL.keys() | join(' ') if PORTCHANNEL"`; do
sonic-cfggen -d -a '{"pc":"'$pc'","hwaddr":"'$MAC_ADDRESS'"}' -t /usr/share/sonic/templates/teamd.j2 > $TEAMD_CONF_PATH/$pc.conf
# bring down all member ports before starting teamd
for member in $(sonic-cfggen -d -v "PORTCHANNEL['$pc']['members'] | join(' ')" ); do
if [ -L /sys/class/net/$member ]; then
ip link set $member down
fi
done
done
mkdir -p /var/sonic
echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status
rm -f /var/run/rsyslogd.pid rm -f /var/run/rsyslogd.pid
rm -f /var/run/teamd/*
supervisorctl start rsyslogd supervisorctl start rsyslogd
supervisorctl start teamd supervisorctl start teammgrd
supervisorctl start teamsyncd

View File

@ -19,8 +19,16 @@ autorestart=false
stdout_logfile=syslog stdout_logfile=syslog
stderr_logfile=syslog stderr_logfile=syslog
[program:teamd] [program:teammgrd]
command=/usr/bin/teamd.sh command=/usr/bin/teammgrd
priority=3
autostart=false
autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog
[program:teamsyncd]
command=/usr/bin/teamsyncd
priority=3 priority=3
autostart=false autostart=false
autorestart=false autorestart=false

View File

@ -1,25 +0,0 @@
{
"device": "{{ pc }}",
"hwaddr": "{{ hwaddr }}",
"runner": {
"name": "lacp",
"active": true,
{% if PORTCHANNEL[pc]['fallback'] and ((PORTCHANNEL[pc]['members'] | length) == 1) %}
"fallback": {{ PORTCHANNEL[pc]['fallback'] }},
{% else %}
{# Use 75% links upperbound as min-links #}
"min_ports": {{ (PORTCHANNEL[pc]['members'] | length * 0.75) | round(0, 'ceil') | int }},
{% endif %}
"tx_hash": ["eth", "ipv4", "ipv6"]
},
"link_watch": {
"name": "ethtool"
},
"ports": {
{% for member in PORTCHANNEL[pc]['members'] %}
"{{ member }}": {}{% if not loop.last %},{% endif %}
{% endfor %}
}
}

View File

@ -1,28 +0,0 @@
#!/usr/bin/env bash
TEAMD_CONF_PATH=/etc/teamd
function start_app {
rm -f /var/run/teamd/*
if [ "$(ls -A $TEAMD_CONF_PATH)" ]; then
for f in $TEAMD_CONF_PATH/*; do
teamd -f $f -d -r
done
fi
teamsyncd &
}
function clean_up {
if [ "$(ls -A $TEAMD_CONF_PATH)" ]; then
for f in $TEAMD_CONF_PATH/*; do
teamd -f $f -k
done
fi
pkill -9 teamsyncd
exit
}
trap clean_up SIGTERM SIGKILL
start_app
read

View File

@ -48,19 +48,3 @@ iface eth0 inet dhcp
{% endif %} {% endif %}
# #
{% endblock mgmt_interface %} {% endblock mgmt_interface %}
{% block front_panel_interfaces %}
{% if PORTCHANNEL %}
# "|| true" is added to suppress the error when interface is already a member of LAG
# "ip link show | grep -q master" is added to ensure interface is enslaved
{% for pc in PORTCHANNEL.keys()|sort %}
{% for member in PORTCHANNEL[pc]['members'] %}
allow-hotplug {{ member }}
iface {{ member }} inet manual
pre-up teamdctl {{ pc }} port add {{ member }} || true
post-up ip link show {{ member }} | grep -q master && ifconfig {{ member }} up
post-down ifconfig {{ member }} down
#
{% endfor %}
{% endfor %}
{% endif %}
{% endblock front_panel_interfaces %}

View File

@ -43,6 +43,8 @@ supervisorctl start teamsyncd
supervisorctl start fpmsyncd supervisorctl start fpmsyncd
supervisorctl start teammgrd
supervisorctl start portmgrd supervisorctl start portmgrd
supervisorctl start intfmgrd supervisorctl start intfmgrd

View File

@ -99,6 +99,14 @@ autorestart=false
stdout_logfile=syslog stdout_logfile=syslog
stderr_logfile=syslog stderr_logfile=syslog
[program:teammgrd]
command=/usr/bin/teammgrd
priority=12
autostart=false
autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog
[program:zebra] [program:zebra]
command=/usr/lib/quagga/zebra -A 127.0.0.1 command=/usr/lib/quagga/zebra -A 127.0.0.1
priority=13 priority=13

View File

@ -47,30 +47,4 @@ iface eth0 inet6 static
down ip -6 route delete 2603:10e2:0:2902::/64 dev eth0 table default down ip -6 route delete 2603:10e2:0:2902::/64 dev eth0 table default
down ip -6 rule delete from 2603:10e2:0:2902::8/128 table default down ip -6 rule delete from 2603:10e2:0:2902::8/128 table default
# #
# "|| true" is added to suppress the error when interface is already a member of LAG
# "ip link show | grep -q master" is added to ensure interface is enslaved
allow-hotplug fortyGigE0/112
iface fortyGigE0/112 inet manual
pre-up teamdctl PortChannel01 port add fortyGigE0/112 || true
post-up ip link show fortyGigE0/112 | grep -q master && ifconfig fortyGigE0/112 up
post-down ifconfig fortyGigE0/112 down
#
allow-hotplug fortyGigE0/116
iface fortyGigE0/116 inet manual
pre-up teamdctl PortChannel02 port add fortyGigE0/116 || true
post-up ip link show fortyGigE0/116 | grep -q master && ifconfig fortyGigE0/116 up
post-down ifconfig fortyGigE0/116 down
#
allow-hotplug fortyGigE0/120
iface fortyGigE0/120 inet manual
pre-up teamdctl PortChannel03 port add fortyGigE0/120 || true
post-up ip link show fortyGigE0/120 | grep -q master && ifconfig fortyGigE0/120 up
post-down ifconfig fortyGigE0/120 down
#
allow-hotplug fortyGigE0/124
iface fortyGigE0/124 inet manual
pre-up teamdctl PortChannel04 port add fortyGigE0/124 || true
post-up ip link show fortyGigE0/124 | grep -q master && ifconfig fortyGigE0/124 up
post-down ifconfig fortyGigE0/124 down
#

View File

@ -1,20 +0,0 @@
{
"device": "PortChannel01",
"hwaddr": "e4:1d:2d:a5:f3:ad",
"runner": {
"name": "lacp",
"active": true,
"min_ports": 3,
"tx_hash": ["eth", "ipv4", "ipv6"]
},
"link_watch": {
"name": "ethtool"
},
"ports": {
"Ethernet112": {},
"Ethernet116": {},
"Ethernet120": {},
"Ethernet124": {}
}
}

View File

@ -75,35 +75,6 @@ class TestJ2Files(TestCase):
self.run_script(argument) self.run_script(argument)
self.assertTrue(filecmp.cmp(os.path.join(self.test_dir, 'sample_output', 'frr.conf'), self.output_file)) self.assertTrue(filecmp.cmp(os.path.join(self.test_dir, 'sample_output', 'frr.conf'), self.output_file))
def test_teamd(self):
def test_render_teamd(self, pc, minigraph, sample_output):
teamd_file = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-teamd', 'teamd.j2')
argument = '-m ' + minigraph + ' -p ' + self.t0_port_config + ' -a \'{\"pc\":\"' + pc + '\",\"hwaddr\":\"e4:1d:2d:a5:f3:ad\"}\' -t ' + teamd_file + ' > ' + self.output_file
self.run_script(argument)
self.assertTrue(filecmp.cmp(sample_output, self.output_file))
# Test T0 minigraph
argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -v "PORTCHANNEL.keys() | join(\' \') if PORTCHANNEL"'
output = self.run_script(argument) # Mock the output via config.sh in docker-teamd
pc_list = output.split()
for i in range(1, 5):
pc_name = 'PortChannel0' + str(i)
self.assertTrue(pc_name in pc_list)
sample_output = os.path.join(self.test_dir, 'sample_output', 't0_sample_output', pc_name + '.conf')
test_render_teamd(self, pc_name, self.t0_minigraph, sample_output)
# Test port channel test minigraph
argument = '-m ' + self.pc_minigraph + ' -p ' + self.t0_port_config + ' -v "PORTCHANNEL.keys() | join(\' \') if PORTCHANNEL"'
output = self.run_script(argument) # Mock the output via config.sh in docker-teamd
pc_list = output.split()
pc_name = 'PortChannel01'
self.assertTrue(pc_name in pc_list)
sample_output = os.path.join(self.test_dir, 'sample_output', 'pc_sample_output', pc_name + '.conf')
test_render_teamd(self, pc_name, self.pc_minigraph, sample_output)
def test_ipinip(self): def test_ipinip(self):
ipinip_file = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-orchagent', 'ipinip.json.j2') ipinip_file = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-orchagent', 'ipinip.json.j2')
argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -t ' + ipinip_file + ' > ' + self.output_file argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -t ' + ipinip_file + ' > ' + self.output_file

@ -1 +1 @@
Subproject commit e1cc0de6159d03bd3def4d4715ae1c93cd12a1e8 Subproject commit 68a962903ae227d76c5367a7a3cacd4063893922