ovn-nbctl: Update basic router commands.
[cascardo/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.
90 AT_CHECK([ovn-sbctl \
91     -- --id=@dp1 create Datapath_Binding tunnel_key=1 \
92     -- --id=@dp2 create Datapath_Binding tunnel_key=2 \
93     -- create Port_Binding datapath=@dp1 logical_port=foo tunnel_key=1 type=patch options:peer=bar \
94     -- create Port_Binding datapath=@dp2 logical_port=bar tunnel_key=2 type=patch options:peer=foo \
95 | ${PERL} $srcdir/uuidfilt.pl], [0], [<0>
96 <1>
97 <2>
98 <3>
99 ])
100 check_patches \
101     'br-int  patch-br-int-to-localnet2 patch-localnet2-to-br-int' \
102     'br-eth0 patch-localnet2-to-br-int patch-br-int-to-localnet2' \
103     'br-int  patch-foo-to-bar        patch-bar-to-foo' \
104     'br-int  patch-bar-to-foo        patch-foo-to-bar'
105
106 # Delete the mapping and the ovn-bridge-mapping patch ports should go away;
107 # the ones from the logical patch port remain.
108 AT_CHECK([ovs-vsctl remove Open_vSwitch . external-ids ovn-bridge-mappings])
109 check_bridge_mappings
110 check_patches \
111     'br-int patch-foo-to-bar patch-bar-to-foo' \
112     'br-int patch-bar-to-foo patch-foo-to-bar'
113
114 # Change name of logical patch port, check that the OVS patch ports
115 # get updated.
116 AT_CHECK([ovn-sbctl \
117     -- set Port_Binding foo logical_port=quux options:peer=baz \
118     -- set Port_Binding bar logical_port=baz  options:peer=quux])
119 check_patches \
120     'br-int patch-quux-to-baz patch-baz-to-quux' \
121     'br-int patch-baz-to-quux patch-quux-to-baz'
122
123 # Create an empty database, serve it and switch to it
124 # and verify that the OVS patch ports disappear
125 # then put it back and verify that they reappear
126
127 on_exit 'kill `cat $ovs_base/ovn-sb/ovsdb-server-2.pid`'
128
129 ovsdb-tool create $ovs_base/ovn-sb/ovn-sb1.db "$abs_top_srcdir"/ovn/ovn-sb.ovsschema
130 as ovn-sb ovsdb-server --detach --pidfile=$ovs_base/ovn-sb/ovsdb-server-2.pid --remote=punix:$ovs_base/ovn-sb/ovn-sb1.sock $ovs_base/ovn-sb/ovn-sb1.db
131 AT_CHECK([ovs-vsctl -- set Open_vSwitch . external-ids:ovn-remote=unix:$ovs_base/ovn-sb/ovn-sb1.sock])
132 check_patches
133 AT_CHECK([ovs-vsctl -- set Open_vSwitch . external-ids:ovn-remote=unix:$ovs_base/ovn-sb/ovn-sb.sock])
134 check_patches \
135     'br-int patch-quux-to-baz patch-baz-to-quux' \
136     'br-int patch-baz-to-quux patch-quux-to-baz'
137
138 # Change the logical patch ports to VIFs and verify that the OVS patch
139 # ports disappear.
140 AT_CHECK([ovn-sbctl \
141     -- set Port_Binding quux type='""' options='{}' \
142     -- set Port_Binding baz type='""' options='{}'])
143 check_patches
144
145 # Gracefully terminate daemons
146 as hv
147 OVS_APP_EXIT_AND_WAIT([ovn-controller])
148 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
149 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
150
151 as main
152 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
153 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
154
155 as ovn-sb
156 OVS_APP_EXIT_AND_WAIT_BY_TARGET([ovsdb-server-2])
157 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
158
159 AT_CLEANUP