Skip to content

Commit c64e5e5

Browse files
pavel-shirshovlguohan
authored andcommitted
[vstest]: Test for quagga livelock fix (#2751)
* Test for quagga livelock fix * Create /usr/local/etc for the test * Add more debug info * Install specific version of exabgp * Update sonic-quagga
1 parent 9299a24 commit c64e5e5

File tree

6 files changed

+216
-1
lines changed

6 files changed

+216
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
router bgp 65501
2+
bgp router-id 1.1.1.1
3+
bgp graceful-restart restart-time 180
4+
bgp graceful-restart
5+
neighbor 10.0.0.1 remote-as 65502
6+
address-family ipv4
7+
neighbor 10.0.0.1 activate
8+
maximum-paths 64
9+
exit-address-family
10+
neighbor 10.0.0.3 remote-as 65503
11+
address-family ipv4
12+
neighbor 10.0.0.3 activate
13+
maximum-paths 64
14+
exit-address-family
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
neighbor 10.0.0.0 {
2+
router-id 1.1.1.2;
3+
local-address 10.0.0.1;
4+
local-as 65502;
5+
peer-as 65501;
6+
group-updates false;
7+
8+
family{
9+
ipv4 unicast;
10+
}
11+
12+
static {
13+
route 1.1.1.1/32{
14+
next-hop 10.0.0.1;
15+
community no-export;
16+
}
17+
route 2.2.2.2/32{
18+
next-hop 10.0.0.1;
19+
}
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
neighbor 10.0.0.0 {
2+
router-id 1.1.1.2;
3+
local-address 10.0.0.1;
4+
local-as 65502;
5+
peer-as 65501;
6+
group-updates false;
7+
manual-eor true;
8+
9+
family{
10+
ipv4 unicast;
11+
}
12+
13+
capability {
14+
graceful-restart 360;
15+
}
16+
17+
static {
18+
route 1.1.1.1/32{
19+
next-hop 10.0.0.1;
20+
community no-export;
21+
}
22+
route 2.2.2.2/32{
23+
next-hop 10.0.0.1;
24+
}
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
neighbor 10.0.0.2 {
2+
router-id 1.1.1.3;
3+
local-address 10.0.0.3;
4+
local-as 65503;
5+
peer-as 65501;
6+
group-updates false;
7+
8+
family {
9+
ipv4 unicast;
10+
}
11+
}
+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
from swsscommon import swsscommon
2+
import os
3+
import re
4+
import time
5+
import json
6+
import random
7+
8+
def output(dvs, title):
9+
print "=========================== %s ===========================" % title
10+
exit_cod, sum_res = dvs.runcmd(["vtysh", "-c", "show ip bgp sum"])
11+
exit_code, all_route = dvs.runcmd(["vtysh", "-c", "show ip bgp"])
12+
exit_code, neig_1 = dvs.runcmd(["vtysh", "-c", "show ip bgp neighbors 10.0.0.1"])
13+
exit_code, announce_route_1 = dvs.runcmd(["vtysh", "-c", "show ip bgp neighbors 10.0.0.1 advertised-routes"])
14+
exit_code, received_route_1 = dvs.runcmd(["vtysh", "-c", "show ip bgp neighbors 10.0.0.1 routes"])
15+
exit_code, announce_route_3 = dvs.runcmd(["vtysh", "-c", "show ip bgp neighbors 10.0.0.3 advertised-routes"])
16+
exit_code, received_route_3 = dvs.runcmd(["vtysh", "-c", "show ip bgp neighbors 10.0.0.3 routes"])
17+
print "Summary:"
18+
print sum_res
19+
print "Received routes:"
20+
print "10.0.0.1"
21+
print received_route_1
22+
print "10.0.0.3"
23+
print received_route_3
24+
print "Announces routes:"
25+
print "10.0.0.1"
26+
print announce_route_1
27+
print "10.0.0.3"
28+
print announce_route_3
29+
print "Neighbors"
30+
print "10.0.0.1"
31+
print neig_1
32+
print "======================================================"
33+
34+
def mkdir(path):
35+
if not os.path.exists(path):
36+
os.makedirs(path)
37+
38+
def remove(path):
39+
if os.path.exists(path):
40+
os.unlink(path)
41+
42+
def get_target_env(idx):
43+
return '/usr/local/etc/exabgp/exabgp_%d.env' % idx
44+
45+
def prepare_exa_env(dvs, idx):
46+
mkdir('/usr/local/etc')
47+
mkdir('/usr/local/etc/exabgp')
48+
tmp_name = '/tmp/env.%d.%d' % (random.randint(0, 10000000), os.getpid())
49+
dvs.servers[idx].runcmd("exabgp --fi > %s" % tmp_name)
50+
with open(tmp_name) as r_fp:
51+
with open(get_target_env(idx), 'w') as w_fp:
52+
for line in r_fp:
53+
if line.startswith('pipename'):
54+
line = "pipename = 'exabgp.%d'\n" % idx
55+
w_fp.write(line)
56+
os.unlink(tmp_name)
57+
58+
59+
def run_exa(dvs, idx, cfg):
60+
prepare_exa_env(dvs, idx)
61+
run_dir = "/var/run/exabgp"
62+
mkdir(run_dir)
63+
fifo_in_path = "%s/exabgp.%d.in" % (run_dir, idx)
64+
fifo_out_path = "%s/exabgp.%d.out" % (run_dir, idx)
65+
remove(fifo_in_path)
66+
remove(fifo_out_path)
67+
os.mkfifo(fifo_in_path)
68+
os.mkfifo(fifo_out_path)
69+
os.chmod(fifo_in_path, 0666)
70+
os.chmod(fifo_out_path, 0666)
71+
print "!!! Start exabgp instance %d" % idx
72+
cmd = "exabgp -d --env %s %s" % (get_target_env(idx), cfg)
73+
print "Cmd is ___ %s ___" % cmd
74+
return dvs.servers[idx].runcmd_async(cmd)
75+
76+
def run_exacli(dvs, idx, cmd):
77+
return dvs.servers[idx].runcmd('exabgpcli --env %s %s' % (get_target_env(idx), cmd))
78+
79+
def test_gr_livelock(dvs, testlog):
80+
# update exabgp to version 4.0.10
81+
dvs.servers[0].runcmd("pip install 'exabgp==4.0.10' --force-reinstall ")
82+
#
83+
dvs.copy_file("/etc/quagga/", "bgp/files/gr_livelock/bgpd.conf")
84+
dvs.servers[0].runcmd("pkill exabgp") # In case previous test didn't stop exa
85+
dvs.runcmd("supervisorctl stop bgpd")
86+
time.sleep(5)
87+
dvs.runcmd("supervisorctl start bgpd")
88+
dvs.runcmd("ip addr add 10.0.0.0/31 dev Ethernet0")
89+
dvs.runcmd("ifconfig Ethernet0 up")
90+
91+
dvs.runcmd("ip addr add 10.0.0.2/31 dev Ethernet4")
92+
dvs.runcmd("ifconfig Ethernet4 up")
93+
94+
dvs.servers[0].runcmd("ip addr add 10.0.0.1/31 dev eth0")
95+
dvs.servers[0].runcmd("ifconfig eth0 up")
96+
97+
dvs.servers[1].runcmd("ip addr add 10.0.0.3/31 dev eth0")
98+
dvs.servers[1].runcmd("ifconfig eth0 up")
99+
100+
time.sleep(5)
101+
102+
# Run two bgp neighbors
103+
p1 = run_exa(dvs, 0, "bgp/files/gr_livelock/exabgp1.conf")
104+
p2 = run_exa(dvs, 1, "bgp/files/gr_livelock/exabgp2.conf")
105+
106+
time.sleep(30)
107+
108+
output(dvs, "First neighbor doesn't have GR enabled")
109+
110+
# Check that we announce routes from the 1st neigbbor to 2nd, if 1st neighbor doesn't support graceful restart
111+
_, announced_routes = dvs.runcmd(["vtysh", "-c", "show ip bgp neighbors 10.0.0.3 advertised-routes"])
112+
assert '2.2.2.2/32' in announced_routes
113+
114+
# Stop 1st neighbor
115+
run_exacli(dvs, 0, 'shutdown')
116+
p1 = p1.wait()
117+
118+
# Wait until quagga thinks that 1st neighbor was shut down
119+
time.sleep(300)
120+
121+
# Start the 1st neighbor again with graceful restart enabled
122+
p1 = run_exa(dvs, 0, "bgp/files/gr_livelock/exabgp1.graceful.conf")
123+
124+
time.sleep(60)
125+
126+
output(dvs, "First neighbor has GR enalbed")
127+
128+
run_exacli(dvs, 0, 'announce route 1.10.0.0/24 next-hop self')
129+
130+
time.sleep(60)
131+
132+
output(dvs, "Announced a new route from the first neighbor")
133+
134+
# Check that we announce all routes from the 1st neighbor
135+
_, announced_routes = dvs.runcmd(["vtysh", "-c", "show ip bgp neighbors 10.0.0.3 advertised-routes"])
136+
assert '2.2.2.2/32' in announced_routes
137+
assert '1.10.0.0/24' in announced_routes
138+
139+
run_exacli(dvs, 0, 'shutdown')
140+
p1 = p1.wait()
141+
142+
run_exacli(dvs, 1, 'shutdown')
143+
p2 = p2.wait()

src/sonic-quagga

0 commit comments

Comments
 (0)