ovn-controller: Add test for setting up and tearing down patch ports.
[cascardo/ovs.git] / tests / ovn-controller.at
diff --git a/tests/ovn-controller.at b/tests/ovn-controller.at
new file mode 100644 (file)
index 0000000..44206c1
--- /dev/null
@@ -0,0 +1,71 @@
+AT_BANNER([ovn-controller])
+
+AT_SETUP([ovn-controller - ovn-bridge-mappings])
+ovn_init_db ovn-sb
+net_add n1
+sim_add hv
+as hv
+ovs-vsctl \
+    -- add-br br-phys \
+    -- add-br br-eth0 \
+    -- add-br br-eth1 \
+    -- add-br br-eth2
+ovn_attach n1 br-phys 192.168.0.1
+
+# Waits until the OVS database contains exactly the specified patch ports.
+# Each argument should be of the form BRIDGE PORT PEER.
+check_patches () {
+    # Generate code to check that the set of patch ports is exactly as
+    # specified.
+    echo 'ovs-vsctl -f csv -d bare --no-headings --columns=name find Interface type=patch | sort' > query
+    for patch
+    do
+       echo $patch
+    done | cut -d' ' -f 2 | sort > expout
+
+    # Generate code to verify that the configuration of each patch
+    # port is correct.
+    for patch
+    do
+       set $patch; bridge=$1 port=$2 peer=$3
+        echo >>query "ovs-vsctl iface-to-br $port -- get Interface $port type options"
+        echo >>expout "$bridge
+patch
+{peer=$peer}"
+    done
+
+    # Run the query until we get the expected result (or until a timeout).
+    #
+    # (We use sed to drop all "s from output because ovs-vsctl quotes some
+    # of the port names but not others.)
+    AT_CAPTURE_FILE([query])
+    AT_CAPTURE_FILE([expout])
+    AT_CAPTURE_FILE([stdout])
+    OVS_WAIT_UNTIL([. ./query | sed 's/"//g' > stdout #"
+                    diff -u stdout expout >/dev/null])
+}
+
+# Initially there should be no patch ports.
+check_patches
+
+# Configure two ovn-bridge mappings to create two patch ports.
+AT_CHECK([ovs-vsctl set Open_vSwitch . external-ids:ovn-bridge-mappings=physnet1:br-eth0,physnet2:br-eth1])
+check_patches \
+    'br-eth0 patch-br-eth0-to-br-int patch-br-int-to-br-eth0' \
+    'br-int  patch-br-int-to-br-eth0 patch-br-eth0-to-br-int' \
+    'br-eth1 patch-br-eth1-to-br-int patch-br-int-to-br-eth1' \
+    'br-int  patch-br-int-to-br-eth1 patch-br-eth1-to-br-int'
+
+# Change the mapping and the patch ports should change.
+AT_CHECK([ovs-vsctl set Open_vSwitch . external-ids:ovn-bridge-mappings=physnet1:br-eth2,physnet2:br-eth1])
+check_patches \
+    'br-eth2 patch-br-eth2-to-br-int patch-br-int-to-br-eth2' \
+    'br-int  patch-br-int-to-br-eth2 patch-br-eth2-to-br-int' \
+    'br-eth1 patch-br-eth1-to-br-int patch-br-int-to-br-eth1' \
+    'br-int  patch-br-int-to-br-eth1 patch-br-eth1-to-br-int'
+
+# Delete the mapping and the patch ports should go away.
+AT_CHECK([ovs-vsctl remove Open_vSwitch . external-ids ovn-bridge-mappings])
+check_patches
+
+AT_CLEANUP