12d0134a8540b4bfd9c93de16227b8885a0f52ac
[cascardo/ovs.git] / tests / ovn-controller-vtep.at
1 AT_BANNER([ovn_controller_vtep])
2
3 # OVN_CONTROLLER_VTEP_START
4 #
5 # Starts the test with a setup with vtep device.
6 #
7 # Uses vtep-ovs to simulate the vtep switch 'br-vtep' with two physical ports
8 # 'p0', 'p1'.
9 #
10 # Configures ovn-nb with a logical switch 'br-test'.
11 #
12 #
13 m4_define([OVN_CONTROLLER_VTEP_START],
14   [OVS_RUNDIR=`pwd`; export OVS_RUNDIR
15    OVS_LOGDIR=`pwd`; export OVS_LOGDIR
16    OVS_DBDIR=`pwd`; export OVS_DBDIR
17    OVS_SYSCONFDIR=`pwd`; export OVS_SYSCONFDIR
18
19    dnl Create databases (ovn-nb, ovn-sb, vtep).
20    AT_CHECK([ovsdb-tool create vswitchd.db $abs_top_srcdir/vswitchd/vswitch.ovsschema])
21    for daemon in ovn-nb ovn-sb vtep; do
22       AT_CHECK([ovsdb-tool create $daemon.db $abs_top_srcdir/${daemon%%-*}/${daemon}.ovsschema])
23    done
24
25    dnl Start ovsdb-server.
26    AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:$OVS_RUNDIR/db.sock vswitchd.db vtep.db ovn-nb.db ovn-sb.db], [0], [], [stderr])
27     ON_EXIT_UNQUOTED([kill `cat ovsdb-server.pid`])
28    AT_CHECK([[sed < stderr '
29 /vlog|INFO|opened log file/d
30 /ovsdb_server|INFO|ovsdb-server (Open vSwitch)/d']])
31    AT_CAPTURE_FILE([ovsdb-server.log])
32
33    dnl Start ovs-vswitchd.
34    AT_CHECK([ovs-vswitchd --enable-dummy --disable-system --detach --no-chdir --pidfile --log-file -vvconn -vofproto_dpif], [0], [], [stderr])
35    AT_CAPTURE_FILE([ovs-vswitchd.log])
36    ON_EXIT_UNQUOTED([kill `cat ovs-vswitchd.pid`])
37    AT_CHECK([[sed < stderr '
38 /ovs_numa|INFO|Discovered /d
39 /vlog|INFO|opened log file/d
40 /vswitchd|INFO|ovs-vswitchd (Open vSwitch)/d
41 /reconnect|INFO|/d
42 /ofproto|INFO|using datapath ID/d
43 /ofproto|INFO|datapath ID changed to fedcba9876543210/d']])
44    AT_CHECK([ovs-vsctl -- add-br br-vtep \
45               -- set bridge br-vtep datapath-type=dummy other-config:datapath-id=fedcba9876543210 other-config:hwaddr=aa:55:aa:55:00:00 protocols=[[OpenFlow10,OpenFlow11,OpenFlow12,OpenFlow13,OpenFlow14,OpenFlow15]] fail-mode=secure \
46               -- add-port br-vtep p0 -- set Interface p0 type=dummy ofport_request=1 \
47               -- add-port br-vtep p1 -- set Interface p1 type=dummy ofport_request=2])
48
49    dnl Start ovs-vtep.
50    AT_CHECK([vtep-ctl add-ps br-vtep -- set Physical_Switch br-vtep tunnel_ips=1.2.3.4])
51    AT_CHECK([ovs-vtep --log-file=ovs-vtep.log --pidfile=ovs-vtep.pid --detach br-vtep \], [0], [], [stderr])
52    ON_EXIT_UNQUOTED([kill `cat ovs-vtep.pid`])
53    AT_CHECK([[sed < stderr '
54 /vlog|INFO|opened log file/d']])
55    # waits until ovs-vtep starts up.
56    OVS_WAIT_UNTIL([test -n "`vtep-ctl show | grep Physical_Port`"])
57
58    dnl Start ovn-northd.
59    AT_CHECK([ovn-nbctl lswitch-add br-test])
60    AT_CHECK([ovn-northd --detach --pidfile --log-file --ovnnb-db=unix:$OVS_RUNDIR/db.sock --ovnsb-db=unix:$OVS_RUNDIR/db.sock], [0], [], [stderr])
61    ON_EXIT_UNQUOTED([kill `cat ovn-northd.pid`])
62    AT_CHECK([[sed < stderr '
63 /vlog|INFO|opened log file/d']])
64    AT_CAPTURE_FILE([ovn-northd.log])
65
66    dnl Start ovn-controllger-vtep.
67    AT_CHECK([ovn-controller-vtep --detach --pidfile --log-file --vtep-db=unix:$OVS_RUNDIR/db.sock --ovnsb-db=unix:$OVS_RUNDIR/db.sock], [0], [], [stderr])
68    AT_CAPTURE_FILE([ovn-controller-vtep.log])
69    ON_EXIT_UNQUOTED([kill `cat ovn-controller-vtep.pid`])
70    AT_CHECK([[sed < stderr '
71 /vlog|INFO|opened log file/d
72 /reconnect|INFO|/d']])
73 ])
74
75 # OVN_CONTROLLER_VTEP_STOP
76 #
77 # So many exits... Yeah, we started a lot daemons~
78 #
79 m4_define([OVN_CONTROLLER_VTEP_STOP],
80   [AT_CHECK([check_logs $1])
81    AT_CHECK([ovs-appctl -t ovs-vtep exit])
82    AT_CHECK([ovs-appctl -t ovn-northd exit])
83    AT_CHECK([ovs-appctl -t ovsdb-server exit])
84    AT_CHECK([ovs-appctl -t ovn-controller-vtep exit])
85    AT_CHECK([ovs-appctl -t ovs-vswitchd exit])])
86
87
88
89 # tests chassis related updates.
90 AT_SETUP([ovn-controller-vtep - test chassis])
91 OVN_CONTROLLER_VTEP_START
92
93 # verifies the initial ovn-sb db configuration.
94 AT_CHECK([ovn-sbctl show], [0], [dnl
95 Chassis br-vtep
96     Encap vxlan
97         ip: "1.2.3.4"
98 ])
99
100 # deletes the chassis via ovn-sbctl and check that it is readded back
101 # with the log.
102 AT_CHECK([ovn-sbctl chassis-del br-vtep])
103 OVS_WAIT_UNTIL([test -n "`grep WARN ovn-controller-vtep.log`"])
104 AT_CHECK([sed -n 's/^.*\(|WARN|.*\)$/\1/p' ovn-controller-vtep.log], [0], [dnl
105 |WARN|Chassis for VTEP physical switch (br-vtep) disappears, maybe deleted by ovn-sbctl, adding it back
106 ])
107 # this removal of chassis could cause 'Broken pipe' warning in the ovsdb-server.log,
108 # due to the race between 'ovn-sbctl' exiting and 'ovn-controller-vtep' adding
109 # the chassis back.  so just removes the 'Broken pipe' warning from ovsdb-server.log.
110 AT_CHECK([sed -i '/Broken pipe/d' ovsdb-server.log])
111
112 # changes the tunnel_ip on physical switch, watches the update of chassis's
113 # encap.
114 AT_CHECK([vtep-ctl set Physical_Switch br-vtep tunnel_ips=1.2.3.5])
115 OVS_WAIT_UNTIL([test -n "`ovn-sbctl show | grep 1\.2\.3\.5`"])
116 AT_CHECK([ovn-sbctl --columns=ip list Encap | cut -d ':' -f2 | tr -d ' '], [0], [dnl
117 "1.2.3.5"
118 ])
119
120 # adds vlan_bindings to physical ports.
121 AT_CHECK([vtep-ctl add-ls lswitch0 -- bind-ls br-vtep p0 100 lswitch0 -- bind-ls br-vtep p0 200 lswitch0 -- bind-ls br-vtep p1 300 lswitch0])
122 OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Chassis | grep -- lswitch0`"])
123 AT_CHECK([ovn-sbctl --columns=vtep_logical_switches list Chassis | cut -d ':' -f2 | tr -d ' ' ], [0], [dnl
124 [["lswitch0"]]
125 ])
126
127 # adds another logical switch and new vlan_bindings.
128 AT_CHECK([vtep-ctl add-ls lswitch1 -- bind-ls br-vtep p0 300 lswitch1])
129 OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Chassis | grep -- lswitch1`"])
130 AT_CHECK([ovn-sbctl --columns=vtep_logical_switches list Chassis | cut -d ':' -f2 | tr -d ' '], [0], [dnl
131 [["lswitch0","lswitch1"]]
132 ])
133
134 # unbinds one port from lswitch0, nothing should change.
135 AT_CHECK([vtep-ctl unbind-ls br-vtep p0 200])
136 OVS_WAIT_UNTIL([test -z "`vtep-ctl --columns=vlan_bindings list physical_port p0 | grep -- '200='`"])
137 AT_CHECK([ovn-sbctl --columns=vtep_logical_switches list Chassis | cut -d ':' -f2 | tr -d ' ' ], [0], [dnl
138 [["lswitch0","lswitch1"]]
139 ])
140
141 # unbinds all ports from lswitch0.
142 AT_CHECK([vtep-ctl unbind-ls br-vtep p0 100 -- unbind-ls br-vtep p1 300])
143 OVS_WAIT_UNTIL([test -z "`ovn-sbctl list Chassis | grep -- br-vtep_lswitch0`"])
144 AT_CHECK([ovn-sbctl --columns=vtep_logical_switches list Chassis | cut -d ':' -f2 | tr -d ' ' ], [0], [dnl
145 [["lswitch1"]]
146 ])
147
148 # unbinds all ports from lswitch1.
149 AT_CHECK([vtep-ctl unbind-ls br-vtep p0 300])
150 OVS_WAIT_UNTIL([test -z "`ovn-sbctl list Chassis | grep -- br-vtep_lswitch1`"])
151 AT_CHECK([ovn-sbctl --columns=vtep_logical_switches list Chassis | cut -d ':' -f2 | tr -d ' '], [0], [dnl
152 [[]]
153 ])
154
155 OVN_CONTROLLER_VTEP_STOP(["/Chassis for VTEP physical switch (br-vtep) disappears/d"])
156 AT_CLEANUP