]> git.proxmox.com Git - ovs.git/blame - tests/ovn-controller.at
tests: Convert ovsdb-monitor-sort utility from Perl to Python.
[ovs.git] / tests / ovn-controller.at
CommitLineData
caad1387
BP
1AT_BANNER([ovn-controller])
2
3AT_SETUP([ovn-controller - ovn-bridge-mappings])
dfef14ee 4AT_KEYWORDS([ovn])
caad1387
BP
5ovn_init_db ovn-sb
6net_add n1
7sim_add hv
8as hv
9ovs-vsctl \
10 -- add-br br-phys \
11 -- add-br br-eth0 \
12 -- add-br br-eth1 \
13 -- add-br br-eth2
14ovn_attach n1 br-phys 192.168.0.1
15
16# Waits until the OVS database contains exactly the specified patch ports.
17# Each argument should be of the form BRIDGE PORT PEER.
18check_patches () {
19 # Generate code to check that the set of patch ports is exactly as
20 # specified.
21 echo 'ovs-vsctl -f csv -d bare --no-headings --columns=name find Interface type=patch | sort' > query
22 for patch
23 do
269ecccc 24 echo $patch
caad1387
BP
25 done | cut -d' ' -f 2 | sort > expout
26
27 # Generate code to verify that the configuration of each patch
28 # port is correct.
29 for patch
30 do
269ecccc 31 set $patch; bridge=$1 port=$2 peer=$3
caad1387
BP
32 echo >>query "ovs-vsctl iface-to-br $port -- get Interface $port type options"
33 echo >>expout "$bridge
34patch
35{peer=$peer}"
36 done
37
38 # Run the query until we get the expected result (or until a timeout).
39 #
40 # (We use sed to drop all "s from output because ovs-vsctl quotes some
41 # of the port names but not others.)
42 AT_CAPTURE_FILE([query])
43 AT_CAPTURE_FILE([expout])
44 AT_CAPTURE_FILE([stdout])
45 OVS_WAIT_UNTIL([. ./query | sed 's/"//g' > stdout #"
46 diff -u stdout expout >/dev/null])
47}
48
4250ee37
RB
49# Make sure that the configured bridge mappings in the Open_vSwitch db
50# is mirrored into the Chassis record in the OVN_Southbound db.
51check_bridge_mappings () {
52 local_mappings=$1
53 sysid=$(ovs-vsctl get Open_vSwitch . external_ids:system-id)
54 chassis_mappings=$(ovn-sbctl get Chassis ${sysid} external_ids:ovn-bridge-mappings | sed -e 's/\"//g')
55 echo $local_mappings
56 echo $chassis_mappings
57 AT_CHECK([test "${local_mappings}" = "${chassis_mappings}"])
58}
59
caad1387
BP
60# Initially there should be no patch ports.
61check_patches
62
e90aeb57 63# Configure two ovn-bridge mappings, but no patch ports should be created yet
caad1387 64AT_CHECK([ovs-vsctl set Open_vSwitch . external-ids:ovn-bridge-mappings=physnet1:br-eth0,physnet2:br-eth1])
4250ee37 65check_bridge_mappings "physnet1:br-eth0,physnet2:br-eth1"
e90aeb57
RB
66check_patches
67
68# Create a localnet port, but we should still have no patch ports, as they
69# won't be created until there's a localnet port on a logical switch with
70# another logical port bound to this chassis.
71ovn-sbctl \
72 -- --id=@dp101 create Datapath_Binding tunnel_key=101 \
73 -- create Port_Binding datapath=@dp101 logical_port=localnet1 tunnel_key=1 \
74 type=localnet options:network_name=physnet1
75check_patches
caad1387 76
e90aeb57
RB
77# Create a localnet port on a logical switch with a port bound to this chassis.
78# Now we should get some patch ports created.
79ovn-sbctl \
80 -- --id=@dp102 create Datapath_Binding tunnel_key=102 \
81 -- create Port_Binding datapath=@dp102 logical_port=localnet2 tunnel_key=1 \
82 type=localnet options:network_name=physnet1 \
83 -- create Port_Binding datapath=@dp102 logical_port=localvif2 tunnel_key=2
84ovs-vsctl add-port br-int localvif2 -- set Interface localvif2 external_ids:iface-id=localvif2
caad1387 85check_patches \
e90aeb57
RB
86 'br-int patch-br-int-to-localnet2 patch-localnet2-to-br-int' \
87 'br-eth0 patch-localnet2-to-br-int patch-br-int-to-localnet2'
caad1387 88
1ea9b847
BP
89# Add logical patch ports to connect new logical datapath.
90#
f1a8bd06
BP
91# OVN no longer uses OVS patch ports to implement logical patch ports, so
92# the set of OVS patch ports doesn't change.
d387d24d
BP
93AT_CHECK([ovn-sbctl \
94 -- --id=@dp1 create Datapath_Binding tunnel_key=1 \
95 -- --id=@dp2 create Datapath_Binding tunnel_key=2 \
96 -- create Port_Binding datapath=@dp1 logical_port=foo tunnel_key=1 type=patch options:peer=bar \
97 -- create Port_Binding datapath=@dp2 logical_port=bar tunnel_key=2 type=patch options:peer=foo \
1ea9b847 98 -- create Port_Binding datapath=@dp1 logical_port=dp1vif tunnel_key=3 \
c724bd67 99| uuidfilt], [0], [<0>
d387d24d
BP
100<1>
101<2>
102<3>
1ea9b847 103<4>
d387d24d 104])
1ea9b847 105ovs-vsctl add-port br-int dp1vif -- set Interface dp1vif external_ids:iface-id=dp1vif
d387d24d 106check_patches \
e90aeb57 107 'br-int patch-br-int-to-localnet2 patch-localnet2-to-br-int' \
f1a8bd06 108 'br-eth0 patch-localnet2-to-br-int patch-br-int-to-localnet2'
d387d24d 109
f1a8bd06 110# Delete the mapping and the ovn-bridge-mapping patch ports should go away.
caad1387 111AT_CHECK([ovs-vsctl remove Open_vSwitch . external-ids ovn-bridge-mappings])
4250ee37 112check_bridge_mappings
caad1387
BP
113check_patches
114
d9c8c57c 115# Gracefully terminate daemons
7a8f15e0
LR
116OVN_CLEANUP_SBOX([hv])
117OVN_CLEANUP_VSWITCH([main])
d9c8c57c
LR
118as ovn-sb
119OVS_APP_EXIT_AND_WAIT([ovsdb-server])
120
caad1387 121AT_CLEANUP
5236c73a
NS
122
123# Checks that ovn-controller populates datapath-type and iface-types
124# correctly in the Chassis external-ids column.
125AT_SETUP([ovn-controller - Chassis external_ids])
126AT_KEYWORDS([ovn])
127ovn_init_db ovn-sb
128
129net_add n1
130sim_add hv
131as hv
132ovs-vsctl \
133 -- add-br br-phys \
134 -- add-br br-eth0 \
135 -- add-br br-eth1 \
136 -- add-br br-eth2
137ovn_attach n1 br-phys 192.168.0.1
138
139sysid=$(ovs-vsctl get Open_vSwitch . external_ids:system-id)
140
141# Make sure that the datapath_type set in the Bridge table
142# is mirrored into the Chassis record in the OVN_Southbound db.
143check_datapath_type () {
144 datapath_type=$1
145 chassis_datapath_type=$(ovn-sbctl get Chassis ${sysid} external_ids:datapath-type | sed -e 's/"//g') #"
146 test "${datapath_type}" = "${chassis_datapath_type}"
147}
148
149OVS_WAIT_UNTIL([check_datapath_type ""])
150
151ovs-vsctl set Bridge br-int datapath-type=foo
152OVS_WAIT_UNTIL([check_datapath_type foo])
153
154# Change "ovn-bridge-mappings" value. It should not change the "datapath-type".
155ovs-vsctl set Open_vSwitch . external_ids:ovn-bridge-mappings=foo-mapping
156check_datapath_type foo
157
158ovs-vsctl set Bridge br-int datapath-type=bar
159OVS_WAIT_UNTIL([check_datapath_type bar])
160
161ovs-vsctl set Bridge br-int datapath-type=\"\"
162OVS_WAIT_UNTIL([check_datapath_type ""])
163
8d2b85be 164expected_iface_types=$(ovs-vsctl get Open_vSwitch . iface_types|sed 's/[[]][[ ]]//g')
5236c73a
NS
165chassis_iface_types=$(ovn-sbctl get Chassis ${sysid} external_ids:iface-types | sed -e 's/\"//g')
166echo "chassis_iface_types = ${chassis_iface_types}"
167AT_CHECK([test "${expected_iface_types}" = "${chassis_iface_types}"])
168
169# Change the value of external_ids:iface-types using ovn-sbctl.
170# ovn-controller should again set it back to proper one.
171ovn-sbctl set Chassis ${sysid} external_ids:iface-types="foo"
172OVS_WAIT_UNTIL([
173 chassis_iface_types=$(ovn-sbctl get Chassis ${sysid} external_ids:iface-types | sed -e 's/\"//g')
174 echo "chassis_iface_types = ${chassis_iface_types}"
175 test "${expected_iface_types}" = "${chassis_iface_types}"
176])
177
178# Gracefully terminate daemons
179OVN_CLEANUP_SBOX([hv])
180OVN_CLEANUP_VSWITCH([main])
181as ovn-sb
182OVS_APP_EXIT_AND_WAIT([ovsdb-server])
183
184AT_CLEANUP
9263ceaf
JG
185
186# Checks that ovn-controller correctly maintains the mapping from the Encap
187# table in the Southbound database to OVS in the face of changes on both sides
188AT_SETUP([ovn-controller - change Encap properties])
189AT_KEYWORDS([ovn])
190ovn_init_db ovn-sb
191
192net_add n1
193sim_add hv
194as hv
195ovs-vsctl \
196 -- add-br br-phys \
197 -- add-br br-eth0 \
198 -- add-br br-eth1 \
199 -- add-br br-eth2
200ovn_attach n1 br-phys 192.168.0.1
201
202check_tunnel_property () {
203 test "`ovs-vsctl get interface ovn-fakech-0 $1`" = "$2"
204}
205
206# Start off with a remote chassis supporting STT
207ovn-sbctl chassis-add fakechassis stt 192.168.0.2
208OVS_WAIT_UNTIL([check_tunnel_property type stt])
209
210# See if we switch to Geneve as the first choice when it is available
211encap_uuid=$(ovn-sbctl add chassis fakechassis encaps @encap -- --id=@encap create encap type=geneve ip="127.0.0.1")
212OVS_WAIT_UNTIL([check_tunnel_property type geneve])
213
214# Check that changes within an encap row are propagated
215ovn-sbctl set encap ${encap_uuid} ip=192.168.0.2
216OVS_WAIT_UNTIL([check_tunnel_property options:remote_ip "\"192.168.0.2\""])
217
218# Change the type on the OVS side and check than OVN fixes it
219ovs-vsctl set interface ovn-fakech-0 type=vxlan
220OVS_WAIT_UNTIL([check_tunnel_property type geneve])
221
222# Delete the port entirely and it should be resurrected
223ovs-vsctl del-port ovn-fakech-0
224OVS_WAIT_UNTIL([check_tunnel_property type geneve])
225
226# Gracefully terminate daemons
227OVN_CLEANUP_SBOX([hv])
228OVN_CLEANUP_VSWITCH([main])
229as ovn-sb
230OVS_APP_EXIT_AND_WAIT([ovsdb-server])
231
232AT_CLEANUP