1
1
package systemtests
2
2
3
3
import (
4
+ "errors"
4
5
"fmt"
5
6
"github.com/Sirupsen/logrus"
6
7
"github.com/contiv/contivmodel/client"
@@ -56,7 +57,7 @@ func (s *systemtestSuite) TestBgpContainerToContainerPing(c *C) {
56
57
allcontainers = append (allcontainers , containers [name ]... )
57
58
}
58
59
59
- time . Sleep ( 5 * time . Second )
60
+ s . CheckBgpRouteDistribution ( c , s . vagrant . GetNode ( "quagga1" ), allcontainers )
60
61
endChan := make (chan error )
61
62
62
63
logrus .Infof ("Running ping test " )
@@ -118,7 +119,7 @@ func (s *systemtestSuite) TestBgpContainerToNonContainerPing(c *C) {
118
119
c .Assert (err , IsNil )
119
120
}
120
121
121
- time .Sleep (5 * time .Second )
122
+ time .Sleep (15 * time .Second )
122
123
endChan := make (chan error )
123
124
124
125
//FIXME make it variable number of quagga instances
@@ -187,7 +188,7 @@ func (s *systemtestSuite) TestBgpTriggerPeerAddDelete(c *C) {
187
188
for i := 0 ; i < s .iterations ; i ++ {
188
189
s .SetupBgp (c , false )
189
190
s .CheckBgpConnection (c )
190
- time . Sleep ( 5 * time . Second )
191
+ s . CheckBgpRouteDistribution ( c , s . vagrant . GetNode ( "quagga1" ), allcontainers )
191
192
logrus .Infof ("Running ping test" )
192
193
c .Assert (s .pingTest (allcontainers ), IsNil )
193
194
@@ -243,7 +244,7 @@ func (s *systemtestSuite) TestBgpTriggerLinkUpDown(c *C) {
243
244
c .Assert (err , IsNil )
244
245
allcontainers = append (allcontainers , containers [name ]... )
245
246
}
246
- time . Sleep ( 5 * time . Second )
247
+ s . CheckBgpRouteDistribution ( c , s . vagrant . GetNode ( "quagga1" ), allcontainers )
247
248
endChan := make (chan error )
248
249
249
250
logrus .Infof ("Running ping test" )
@@ -253,7 +254,7 @@ func (s *systemtestSuite) TestBgpTriggerLinkUpDown(c *C) {
253
254
s .CheckBgpNoConnectionForaNode (c , s .vagrant .GetNode ("netplugin-node1" ))
254
255
s .vagrant .GetNode ("netplugin-node1" ).RunCommand ("sudo ip link set eth2 up" )
255
256
s .CheckBgpConnectionForaNode (c , s .vagrant .GetNode ("netplugin-node1" ))
256
- time . Sleep ( 5 * time . Second )
257
+ s . CheckBgpRouteDistribution ( c , s . vagrant . GetNode ( "quagga1" ), allcontainers )
257
258
logrus .Infof ("Running ping test" )
258
259
c .Assert (s .pingTest (allcontainers ), IsNil )
259
260
@@ -320,7 +321,7 @@ func (s *systemtestSuite) TestBgpTriggerLoopbackDownUp(c *C) {
320
321
s .SetupBgp (c , false )
321
322
s .CheckBgpConnection (c )
322
323
323
- time . Sleep ( 5 * time . Second )
324
+ s . CheckBgpRouteDistribution ( c , s . vagrant . GetNode ( "quagga1" ), allcontainers )
324
325
325
326
logrus .Infof ("Running ping test" )
326
327
c .Assert (s .pingTest (allcontainers ), IsNil )
@@ -331,7 +332,7 @@ func (s *systemtestSuite) TestBgpTriggerLoopbackDownUp(c *C) {
331
332
s .vagrant .GetNode ("netplugin-node1" ).RunCommand ("sudo ip link set inb01 up" )
332
333
s .vagrant .GetNode ("netplugin-node1" ).RunCommand ("sudo ip addr add 50.1.1.2/24 dev inb01" )
333
334
s .CheckBgpConnectionForaNode (c , s .vagrant .GetNode ("netplugin-node1" ))
334
- time . Sleep ( 5 * time . Second )
335
+ s . CheckBgpRouteDistribution ( c , s . vagrant . GetNode ( "quagga1" ), allcontainers )
335
336
336
337
logrus .Infof ("Running ping test" )
337
338
c .Assert (s .pingTest (allcontainers ), IsNil )
@@ -403,7 +404,7 @@ func (s *systemtestSuite) TestBgpTriggerContainerAddDelete(c *C) {
403
404
allcontainers = append (allcontainers , containers [name ]... )
404
405
}
405
406
406
- time . Sleep ( 5 * time . Second )
407
+ s . CheckBgpRouteDistribution ( c , s . vagrant . GetNode ( "quagga1" ), allcontainers )
407
408
408
409
endChan := make (chan error )
409
410
@@ -434,7 +435,7 @@ func (s *systemtestSuite) TestBgpTriggerContainerAddDelete(c *C) {
434
435
}
435
436
}
436
437
437
- time . Sleep ( 5 * time . Second )
438
+ s . CheckBgpRouteDistribution ( c , s . vagrant . GetNode ( "quagga1" ), allcontainers )
438
439
439
440
logrus .Infof ("Running ping test" )
440
441
c .Assert (s .pingTest (allcontainers ), IsNil )
@@ -497,7 +498,7 @@ func (s *systemtestSuite) TestBgpTriggerNetpluginRestart(c *C) {
497
498
allcontainers = append (allcontainers , containers [name ]... )
498
499
}
499
500
500
- time . Sleep ( 5 * time . Second )
501
+ s . CheckBgpRouteDistribution ( c , s . vagrant . GetNode ( "quagga1" ), allcontainers )
501
502
502
503
endChan := make (chan error )
503
504
@@ -514,7 +515,7 @@ func (s *systemtestSuite) TestBgpTriggerNetpluginRestart(c *C) {
514
515
c .Assert (node .runCommandUntilNoError ("pgrep netplugin" ), IsNil )
515
516
time .Sleep (15 * time .Second )
516
517
s .CheckBgpConnection (c )
517
- time . Sleep ( 5 * time . Second )
518
+ s . CheckBgpRouteDistribution ( c , s . vagrant . GetNode ( "quagga1" ), allcontainers )
518
519
519
520
logrus .Infof ("Running ping test" )
520
521
c .Assert (s .pingTest (allcontainers ), IsNil )
@@ -675,7 +676,7 @@ func (s *systemtestSuite) TestBgpMultiTrigger(c *C) {
675
676
allcontainers = append (allcontainers , containers [name ]... )
676
677
}
677
678
678
- time . Sleep ( 5 * time . Second )
679
+ s . CheckBgpRouteDistribution ( c , s . vagrant . GetNode ( "quagga1" ), allcontainers )
679
680
680
681
endChan := make (chan error )
681
682
@@ -750,7 +751,7 @@ func (s *systemtestSuite) TestBgpSequencePeerAddLinkDown(c *C) {
750
751
c .Assert (err , IsNil )
751
752
allcontainers = append (allcontainers , containers [name ]... )
752
753
}
753
- time . Sleep ( 5 * time . Second )
754
+ s . CheckBgpRouteDistribution ( c , s . vagrant . GetNode ( "quagga1" ), allcontainers )
754
755
755
756
logrus .Infof ("Running ping test" )
756
757
c .Assert (s .pingTest (allcontainers ), IsNil )
@@ -805,7 +806,7 @@ func (s *systemtestSuite) TestBgpMisconfigRecovery(c *C) {
805
806
c .Assert (err , IsNil )
806
807
allcontainers = append (allcontainers , containers [name ]... )
807
808
}
808
- time . Sleep ( 5 * time . Second )
809
+ s . CheckBgpRouteDistribution ( c , s . vagrant . GetNode ( "quagga1" ), allcontainers )
809
810
endChan := make (chan error )
810
811
811
812
logrus .Infof ("Running ping test" )
@@ -872,12 +873,12 @@ func (s *systemtestSuite) TearDownBgp(c *C) {
872
873
func (s * systemtestSuite ) CheckBgpConnection (c * C ) error {
873
874
874
875
count := 0
875
- for {
876
+ for i := 0 ; i < 100 ; i ++ {
876
877
if count == len (s .nodes ) {
877
878
return nil
878
879
}
879
880
count = 0
880
- time .Sleep (5 * time .Second )
881
+ time .Sleep (3 * time .Second )
881
882
for _ , node := range s .nodes {
882
883
out , _ := node .tbnode .RunCommandWithOutput ("/opt/gopath/bin/gobgp neighbor" )
883
884
fmt .Println (out )
@@ -886,17 +887,18 @@ func (s *systemtestSuite) CheckBgpConnection(c *C) error {
886
887
}
887
888
}
888
889
}
890
+ return errors .New ("BGP connection not established" )
889
891
}
890
892
891
893
func (s * systemtestSuite ) CheckBgpNoConnection (c * C ) error {
892
894
893
895
count := 0
894
- for {
896
+ for i := 0 ; i < 100 ; i ++ {
895
897
if count == len (s .nodes ) {
896
898
return nil
897
899
}
898
900
count = 0
899
- time .Sleep (2 * time .Second )
901
+ time .Sleep (3 * time .Second )
900
902
for _ , node := range s .nodes {
901
903
out , _ := node .tbnode .RunCommandWithOutput ("/opt/gopath/bin/gobgp neighbor" )
902
904
fmt .Println (out )
@@ -905,26 +907,48 @@ func (s *systemtestSuite) CheckBgpNoConnection(c *C) error {
905
907
}
906
908
}
907
909
}
910
+ return errors .New ("BGP connection persists" )
908
911
}
909
912
910
913
func (s * systemtestSuite ) CheckBgpConnectionForaNode (c * C , node vagrantssh.TestbedNode ) error {
911
- for {
912
- time .Sleep (2 * time .Second )
914
+ for i := 0 ; i < 100 ; i ++ {
915
+ time .Sleep (3 * time .Second )
913
916
out , _ := node .RunCommandWithOutput ("/opt/gopath/bin/gobgp neighbor" )
914
917
fmt .Println (out )
915
918
if strings .Contains (out , "Establ" ) {
916
919
return nil
917
920
}
918
921
}
922
+ return errors .New ("BGP connection not established" )
919
923
}
920
924
921
925
func (s * systemtestSuite ) CheckBgpNoConnectionForaNode (c * C , node vagrantssh.TestbedNode ) error {
922
- for {
923
- time .Sleep (2 * time .Second )
926
+ for i := 0 ; i < 100 ; i ++ {
927
+ time .Sleep (3 * time .Second )
924
928
out , _ := node .RunCommandWithOutput ("/opt/gopath/bin/gobgp neighbor" )
925
929
fmt .Println (out )
926
930
if ! strings .Contains (out , "Establ" ) {
927
931
return nil
928
932
}
929
933
}
934
+ return errors .New ("BGP connection persists" )
935
+ }
936
+
937
+ func (s * systemtestSuite ) CheckBgpRouteDistribution (c * C , node vagrantssh.TestbedNode , containers []* container ) error {
938
+ count := 0
939
+ for i := 0 ; i < 10 ; i ++ {
940
+ time .Sleep (2 * time .Second )
941
+ logrus .Infof ("Checking Bgp container route distribution" )
942
+ out , _ := node .RunCommandWithOutput ("ip route" )
943
+ for _ , cont := range containers {
944
+ if strings .Contains (out , cont .eth0 ) {
945
+ count ++
946
+ }
947
+ if count == len (containers ) {
948
+ return nil
949
+ }
950
+ }
951
+ time .Sleep (2 * time .Second )
952
+ }
953
+ return errors .New ("Routes not distributed by BGP" )
930
954
}
0 commit comments