ovn-controller: Add test for setting up and tearing down patch ports.
authorBen Pfaff <blp@nicira.com>
Wed, 7 Oct 2015 21:24:17 +0000 (14:24 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 7 Oct 2015 21:30:09 +0000 (14:30 -0700)
The initial plan for OVN logical routers will make more extensive use of
patch ports, so it seems like a good idea to add some tests to avoid
regressions before messing with them.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Justin Pettit <jpettit@nicira.com>
tests/automake.mk
tests/ovn-controller.at [new file with mode: 0644]
tests/testsuite.at

index d183a1d..95edda3 100644 (file)
@@ -89,6 +89,7 @@ TESTSUITE_AT = \
        tests/ovn.at \
        tests/ovn-nbctl.at \
        tests/ovn-sbctl.at \
+       tests/ovn-controller.at \
        tests/ovn-controller-vtep.at
 
 SYSTEM_KMOD_TESTSUITE_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
index cb2e098..8f915fa 100644 (file)
@@ -70,4 +70,5 @@ m4_include([tests/auto-attach.at])
 m4_include([tests/ovn.at])
 m4_include([tests/ovn-nbctl.at])
 m4_include([tests/ovn-sbctl.at])
+m4_include([tests/ovn-controller.at])
 m4_include([tests/ovn-controller-vtep.at])