Skip to content

Commit bebb7a0

Browse files
taoyl-mslguohan
authored andcommitted
[zebra.conf] Fix template issue with multiple lo addresses (sonic-net#1662)
* [zebra.conf] Fix template issue with multiple lo addresses * Add unitest for Loopback1
1 parent 5817e99 commit bebb7a0

File tree

7 files changed

+171
-8
lines changed

7 files changed

+171
-8
lines changed

dockers/docker-fpm-quagga/zebra.conf.j2

+7-5
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200
4040
{% set lo_ipv6_addrs = [] %}
4141
{% if LOOPBACK_INTERFACE %}
4242
{% for (name, prefix) in LOOPBACK_INTERFACE %}
43-
{% if prefix | ipv6 %}
44-
{% if lo_ipv6_addrs.append(prefix) %}
45-
{% endif %}
46-
{% else %}
47-
{% if lo_ipv4_addrs.append(prefix) %}
43+
{% if name == 'Loopback0' %}
44+
{% if prefix | ipv6 %}
45+
{% if lo_ipv6_addrs.append(prefix) %}
46+
{% endif %}
47+
{% else %}
48+
{% if lo_ipv4_addrs.append(prefix) %}
49+
{% endif %}
4850
{% endif %}
4951
{% endif %}
5052
{% endfor %}

dockers/docker-orchagent/ipinip.json.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{# only IPv4 decapsulation is supported #}
22
{% set ipv4_loopback_addresses = [] %}
33
{% for (name, prefix) in LOOPBACK_INTERFACE %}
4-
{%- if prefix | ipv4 %}
4+
{%- if prefix | ipv4 and name == 'Loopback0' %}
55
{%- set ipv4_loopback_addresses = ipv4_loopback_addresses.append(prefix) %}
66
{%- endif %}
77
{% endfor %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
!
2+
! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
3+
! generated by templates/quagga/bgpd.conf.j2 with config DB data
4+
! file: bgpd.conf
5+
!
6+
!
7+
hostname switch-t0
8+
password zebra
9+
log syslog informational
10+
log facility local4
11+
! enable password !
12+
!
13+
! bgp multiple-instance
14+
!
15+
route-map FROM_BGP_SPEAKER_V4 permit 10
16+
!
17+
route-map TO_BGP_SPEAKER_V4 deny 10
18+
!
19+
router bgp 65100
20+
bgp log-neighbor-changes
21+
bgp bestpath as-path multipath-relax
22+
no bgp default ipv4-unicast
23+
bgp graceful-restart
24+
bgp router-id 10.1.0.32
25+
network 10.1.0.32/32
26+
address-family ipv6
27+
network fc00:1::32/64
28+
exit-address-family
29+
network 192.168.0.1/27
30+
neighbor 10.0.0.57 remote-as 64600
31+
neighbor 10.0.0.57 description ARISTA01T1
32+
address-family ipv4
33+
neighbor 10.0.0.57 allowas-in 1
34+
neighbor 10.0.0.57 activate
35+
maximum-paths 64
36+
exit-address-family
37+
neighbor 10.0.0.59 remote-as 64600
38+
neighbor 10.0.0.59 description ARISTA02T1
39+
address-family ipv4
40+
neighbor 10.0.0.59 allowas-in 1
41+
neighbor 10.0.0.59 activate
42+
maximum-paths 64
43+
exit-address-family
44+
neighbor 10.0.0.61 remote-as 64600
45+
neighbor 10.0.0.61 description ARISTA03T1
46+
address-family ipv4
47+
neighbor 10.0.0.61 allowas-in 1
48+
neighbor 10.0.0.61 activate
49+
maximum-paths 64
50+
exit-address-family
51+
neighbor 10.0.0.63 remote-as 64600
52+
neighbor 10.0.0.63 description ARISTA04T1
53+
address-family ipv4
54+
neighbor 10.0.0.63 allowas-in 1
55+
neighbor 10.0.0.63 activate
56+
maximum-paths 64
57+
exit-address-family
58+
neighbor fc00::7a remote-as 64600
59+
neighbor fc00::7a description ARISTA03T1
60+
address-family ipv6
61+
neighbor fc00::7a allowas-in 1
62+
neighbor fc00::7a activate
63+
maximum-paths 64
64+
exit-address-family
65+
neighbor fc00::7e remote-as 64600
66+
neighbor fc00::7e description ARISTA04T1
67+
address-family ipv6
68+
neighbor fc00::7e allowas-in 1
69+
neighbor fc00::7e activate
70+
maximum-paths 64
71+
exit-address-family
72+
neighbor fc00::72 remote-as 64600
73+
neighbor fc00::72 description ARISTA01T1
74+
address-family ipv6
75+
neighbor fc00::72 allowas-in 1
76+
neighbor fc00::72 activate
77+
maximum-paths 64
78+
exit-address-family
79+
neighbor fc00::76 remote-as 64600
80+
neighbor fc00::76 description ARISTA02T1
81+
address-family ipv6
82+
neighbor fc00::76 allowas-in 1
83+
neighbor fc00::76 activate
84+
maximum-paths 64
85+
exit-address-family
86+
!
87+
maximum-paths 64
88+
!
89+
route-map ISOLATE permit 10
90+
set as-path prepend 65100
91+
!

src/sonic-config-engine/tests/sample_output/interfaces

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ iface lo inet6 static
1515
address fc00:1::32
1616
netmask 128
1717
#
18+
iface lo inet static
19+
address 10.10.0.99
20+
netmask 255.255.255.255
21+
#
1822
# The management network interface
1923
auto eth0
2024
iface eth0 inet static
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
!
2+
! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
3+
! generated by templates/quagga/zebra.conf.j2 using config DB data
4+
! file: zebra.conf
5+
!
6+
!
7+
hostname switch-t0
8+
password zebra
9+
enable password zebra
10+
!
11+
! Enable link-detect (default disabled)
12+
interface PortChannel01
13+
link-detect
14+
!
15+
interface PortChannel02
16+
link-detect
17+
!
18+
interface PortChannel03
19+
link-detect
20+
!
21+
interface PortChannel04
22+
link-detect
23+
!
24+
!
25+
! set static default route to mgmt gateway as a backup to learned default
26+
ip route 0.0.0.0/0 10.0.0.1 200
27+
!
28+
! Set ip source to loopback for bgp learned routes
29+
route-map RM_SET_SRC permit 10
30+
set src 10.1.0.32
31+
!
32+
33+
route-map RM_SET_SRC6 permit 10
34+
set src fc00:1::32
35+
!
36+
ip protocol bgp route-map RM_SET_SRC
37+
!
38+
ipv6 protocol bgp route-map RM_SET_SRC6
39+
!
40+
!
41+
log syslog informational
42+
log facility local4
43+
!
44+

src/sonic-config-engine/tests/t0-sample-graph.xml

+9-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,15 @@
153153
</a:Prefix>
154154
<a:PrefixStr>FC00:1::32/128</a:PrefixStr>
155155
</a:LoopbackIPInterface>
156-
</LoopbackIPInterfaces>
156+
<a:LoopbackIPInterface>
157+
<Name>LoopbackIP1</Name>
158+
<AttachTo>Loopback1</AttachTo>
159+
<a:Prefix xmlns:b="Microsoft.Search.Autopilot.Evolution">
160+
<b:IPPrefix>10.10.0.99/32</b:IPPrefix>
161+
</a:Prefix>
162+
<a:PrefixStr>10.10.0.99/32</a:PrefixStr>
163+
</a:LoopbackIPInterface>
164+
</LoopbackIPInterfaces>
157165
<ManagementIPInterfaces xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution">
158166
<a:ManagementIPInterface>
159167
<Name>HostIP</Name>

src/sonic-config-engine/tests/test_j2files.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ def setUp(self):
2020
def run_script(self, argument):
2121
print 'CMD: sonic-cfggen ' + argument
2222
return subprocess.check_output(self.script_file + ' ' + argument, shell=True)
23+
24+
def run_diff(self, file1, file2, diff):
25+
return subprocess.check_output('diff {} {} >{}'.format(file1, file2, diff), shell=True)
2326

2427
def test_interfaces(self):
2528
interfaces_template = os.path.join(self.test_dir, '..', '..', '..', 'files', 'image_config', 'interfaces', 'interfaces.j2')
@@ -59,6 +62,18 @@ def test_lldp(self):
5962
self.run_script(argument)
6063
self.assertTrue(filecmp.cmp(os.path.join(self.test_dir, 'sample_output', 'lldpd.conf'), self.output_file))
6164

65+
def test_bgpd(self):
66+
conf_template = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-fpm-quagga', 'bgpd.conf.j2')
67+
argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -t ' + conf_template + ' > ' + self.output_file
68+
self.run_script(argument)
69+
self.assertTrue(filecmp.cmp(os.path.join(self.test_dir, 'sample_output', 'bgpd.conf'), self.output_file))
70+
71+
def test_zebra(self):
72+
conf_template = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-fpm-quagga', 'zebra.conf.j2')
73+
argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -t ' + conf_template + ' > ' + self.output_file
74+
self.run_script(argument)
75+
self.assertTrue(filecmp.cmp(os.path.join(self.test_dir, 'sample_output', 'zebra.conf'), self.output_file))
76+
6277
def test_teamd(self):
6378

6479
def test_render_teamd(self, pc, minigraph, sample_output):
@@ -94,7 +109,6 @@ def test_ipinip(self):
94109
self.run_script(argument)
95110

96111
sample_output_file = os.path.join(self.test_dir, 'sample_output', 'ipinip.json')
97-
98112
assert filecmp.cmp(sample_output_file, self.output_file)
99113

100114
def test_msn27xx_32ports_buffers(self):

0 commit comments

Comments
 (0)