]> git.proxmox.com Git - ovs.git/blob - tests/ovn-controller.at
ovn-controller: Drop most uses of OVS patch ports.
[ovs.git] / tests / ovn-controller.at
1 AT_BANNER([ovn-controller])
2
3 AT_SETUP([ovn-controller - ovn-bridge-mappings])
4 AT_KEYWORDS([ovn])
5 ovn_init_db ovn-sb
6 net_add n1
7 sim_add hv
8 as hv
9 ovs-vsctl \
10 -- add-br br-phys \
11 -- add-br br-eth0 \
12 -- add-br br-eth1 \
13 -- add-br br-eth2
14 ovn_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.
18 check_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
24 echo $patch
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
31 set $patch; bridge=$1 port=$2 peer=$3
32 echo >>query "ovs-vsctl iface-to-br $port -- get Interface $port type options"
33 echo >>expout "$bridge
34 patch
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
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.
51 check_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
60 # Initially there should be no patch ports.
61 check_patches
62
63 # Configure two ovn-bridge mappings, but no patch ports should be created yet
64 AT_CHECK([ovs-vsctl set Open_vSwitch . external-ids:ovn-bridge-mappings=physnet1:br-eth0,physnet2:br-eth1])
65 check_bridge_mappings "physnet1:br-eth0,physnet2:br-eth1"
66 check_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.
71 ovn-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
75 check_patches
76
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.
79 ovn-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
84 ovs-vsctl add-port br-int localvif2 -- set Interface localvif2 external_ids:iface-id=localvif2
85 check_patches \
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'
88
89 # Add logical patch ports to connect new logical datapath.
90 #
91 # OVN no longer uses OVS patch ports to implement logical patch ports, so
92 # the set of OVS patch ports doesn't change.
93 AT_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 \
98 -- create Port_Binding datapath=@dp1 logical_port=dp1vif tunnel_key=3 \
99 | ${PERL} $srcdir/uuidfilt.pl], [0], [<0>
100 <1>
101 <2>
102 <3>
103 <4>
104 ])
105 ovs-vsctl add-port br-int dp1vif -- set Interface dp1vif external_ids:iface-id=dp1vif
106 check_patches \
107 'br-int patch-br-int-to-localnet2 patch-localnet2-to-br-int' \
108 'br-eth0 patch-localnet2-to-br-int patch-br-int-to-localnet2'
109
110 # Delete the mapping and the ovn-bridge-mapping patch ports should go away.
111 AT_CHECK([ovs-vsctl remove Open_vSwitch . external-ids ovn-bridge-mappings])
112 check_bridge_mappings
113 check_patches
114
115 # Gracefully terminate daemons
116 OVN_CLEANUP_SBOX([hv])
117 OVN_CLEANUP_VSWITCH([main])
118 as ovn-sb
119 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
120
121 AT_CLEANUP
122
123 # Checks that ovn-controller populates datapath-type and iface-types
124 # correctly in the Chassis external-ids column.
125 AT_SETUP([ovn-controller - Chassis external_ids])
126 AT_KEYWORDS([ovn])
127 ovn_init_db ovn-sb
128
129 net_add n1
130 sim_add hv
131 as hv
132 ovs-vsctl \
133 -- add-br br-phys \
134 -- add-br br-eth0 \
135 -- add-br br-eth1 \
136 -- add-br br-eth2
137 ovn_attach n1 br-phys 192.168.0.1
138
139 sysid=$(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.
143 check_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
149 OVS_WAIT_UNTIL([check_datapath_type ""])
150
151 ovs-vsctl set Bridge br-int datapath-type=foo
152 OVS_WAIT_UNTIL([check_datapath_type foo])
153
154 # Change "ovn-bridge-mappings" value. It should not change the "datapath-type".
155 ovs-vsctl set Open_vSwitch . external_ids:ovn-bridge-mappings=foo-mapping
156 check_datapath_type foo
157
158 ovs-vsctl set Bridge br-int datapath-type=bar
159 OVS_WAIT_UNTIL([check_datapath_type bar])
160
161 ovs-vsctl set Bridge br-int datapath-type=\"\"
162 OVS_WAIT_UNTIL([check_datapath_type ""])
163
164 expected_iface_types=$(ovs-vsctl get Open_vSwitch . iface_types|sed 's/[[]][[ ]]//g')
165 chassis_iface_types=$(ovn-sbctl get Chassis ${sysid} external_ids:iface-types | sed -e 's/\"//g')
166 echo "chassis_iface_types = ${chassis_iface_types}"
167 AT_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.
171 ovn-sbctl set Chassis ${sysid} external_ids:iface-types="foo"
172 OVS_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
179 OVN_CLEANUP_SBOX([hv])
180 OVN_CLEANUP_VSWITCH([main])
181 as ovn-sb
182 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
183
184 AT_CLEANUP
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
188 AT_SETUP([ovn-controller - change Encap properties])
189 AT_KEYWORDS([ovn])
190 ovn_init_db ovn-sb
191
192 net_add n1
193 sim_add hv
194 as hv
195 ovs-vsctl \
196 -- add-br br-phys \
197 -- add-br br-eth0 \
198 -- add-br br-eth1 \
199 -- add-br br-eth2
200 ovn_attach n1 br-phys 192.168.0.1
201
202 check_tunnel_property () {
203 test "`ovs-vsctl get interface ovn-fakech-0 $1`" = "$2"
204 }
205
206 # Start off with a remote chassis supporting STT
207 ovn-sbctl chassis-add fakechassis stt 192.168.0.2
208 OVS_WAIT_UNTIL([check_tunnel_property type stt])
209
210 # See if we switch to Geneve as the first choice when it is available
211 encap_uuid=$(ovn-sbctl add chassis fakechassis encaps @encap -- --id=@encap create encap type=geneve ip="127.0.0.1")
212 OVS_WAIT_UNTIL([check_tunnel_property type geneve])
213
214 # Check that changes within an encap row are propagated
215 ovn-sbctl set encap ${encap_uuid} ip=192.168.0.2
216 OVS_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
219 ovs-vsctl set interface ovn-fakech-0 type=vxlan
220 OVS_WAIT_UNTIL([check_tunnel_property type geneve])
221
222 # Delete the port entirely and it should be resurrected
223 ovs-vsctl del-port ovn-fakech-0
224 OVS_WAIT_UNTIL([check_tunnel_property type geneve])
225
226 # Gracefully terminate daemons
227 OVN_CLEANUP_SBOX([hv])
228 OVN_CLEANUP_VSWITCH([main])
229 as ovn-sb
230 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
231
232 AT_CLEANUP