tests: Avoid nonportable "sed -i".
[cascardo/ovs.git] / tests / ovn-controller-vtep.at
index 82f6166..063feeb 100644 (file)
@@ -2,7 +2,8 @@ AT_BANNER([ovn_controller_vtep])
 
 # OVN_CONTROLLER_VTEP_START
 #
-# Starts the test with a setup with vtep device.
+# Starts the test with a setup with vtep device.  Each test case must first
+# call this macro.
 #
 # Uses vtep-ovs to simulate the vtep switch 'br-vtep' with two physical ports
 # 'p0', 'p1'.
@@ -11,7 +12,11 @@ AT_BANNER([ovn_controller_vtep])
 #
 #
 m4_define([OVN_CONTROLLER_VTEP_START],
-  [OVS_RUNDIR=`pwd`; export OVS_RUNDIR
+  [
+   # this will cause skip when 'make check' using Windows setup.
+   AT_SKIP_IF([test $HAVE_PYTHON = no])
+
+   OVS_RUNDIR=`pwd`; export OVS_RUNDIR
    OVS_LOGDIR=`pwd`; export OVS_LOGDIR
    OVS_DBDIR=`pwd`; export OVS_DBDIR
    OVS_SYSCONFDIR=`pwd`; export OVS_SYSCONFDIR
@@ -77,14 +82,36 @@ m4_define([OVN_CONTROLLER_VTEP_START],
 # So many exits... Yeah, we started a lot daemons~
 #
 m4_define([OVN_CONTROLLER_VTEP_STOP],
-  [AT_CHECK([check_logs $1])
+  [# removes all 'Broken pipe' warning logs from ovsdb-server.log.  this is in
+   # that *ctl command (e.g. ovn-nbctl) exits right after committing the change
+   # to database.  however, in reaction, some daemon (e.g. ovn-controller-vtep)
+   # may immediately update the database.  this later update may cause database
+   # sending update back to *ctl command if *ctl has not proceeded to exit yet.
+   # and if *ctl command exits before database calling send, the send from
+   # database will fail with 'Broken pipe' error.
+   AT_CHECK([check_logs "$1
+/Broken pipe/d"])
    AT_CHECK([ovs-appctl -t ovs-vtep exit])
    AT_CHECK([ovs-appctl -t ovn-northd exit])
-   AT_CHECK([ovs-appctl -t ovsdb-server exit])
    AT_CHECK([ovs-appctl -t ovn-controller-vtep exit])
+   # makes sure ovn-controller-vtep exits.
+   OVS_WAIT_UNTIL([test ! -f ovn-controller-vtep.pid])
+   AT_CHECK([ovs-appctl -t ovsdb-server exit])
    AT_CHECK([ovs-appctl -t ovs-vswitchd exit])])
 
+# Adds logical port for a vtep gateway chassis in ovn-nb database.
+#
+# $1: logical switch name in ovn-nb database
+# $2: logical port name
+# $3: physical vtep gateway name
+# $4: logical switch name on vtep gateway chassis
+m4_define([OVN_NB_ADD_VTEP_PORT], [
+AT_CHECK([ovn-nbctl lport-add $1 $2])
+AT_CHECK([ovn-nbctl lport-set-type $2 vtep])
+AT_CHECK([ovn-nbctl lport-set-options $2 vtep-physical-switch=$3 vtep-logical-switch=$4])
+])
 
+##############################################
 
 # tests chassis related updates.
 AT_SETUP([ovn-controller-vtep - test chassis])
@@ -148,5 +175,108 @@ AT_CHECK([ovn-sbctl --columns=vtep_logical_switches list Chassis | cut -d ':' -f
 [[]]
 ])
 
-OVN_CONTROLLER_VTEP_STOP(["/Chassis for VTEP physical switch (br-vtep) disappears/d"])
+OVN_CONTROLLER_VTEP_STOP([/Chassis for VTEP physical switch (br-vtep) disappears/d])
+AT_CLEANUP
+
+
+# Tests binding updates.
+AT_SETUP([ovn-controller-vtep - test binding 1])
+OVN_CONTROLLER_VTEP_START
+
+# adds logical switch 'lswitch0' and vlan_bindings.
+AT_CHECK([vtep-ctl add-ls lswitch0 -- bind-ls br-vtep p0 100 lswitch0 -- bind-ls br-vtep p1 300 lswitch0])
+# adds lport in ovn-nb database, and sets the type and options.
+OVN_NB_ADD_VTEP_PORT([br-test], [br-vtep_lswitch0], [br-vtep], [lswitch0])
+OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Port_Binding  | grep br-vtep_lswitch0`"])
+# should see one binding, associated to chassis of 'br-vtep'.
+chassis_uuid=$(ovn-sbctl --columns=_uuid list Chassis br-vtep | cut -d ':' -f2 | tr -d ' ')
+AT_CHECK_UNQUOTED([ovn-sbctl --columns=chassis list Port_Binding br-vtep_lswitch0 | cut -d ':' -f2 | tr -d ' '], [0], [dnl
+${chassis_uuid}
+])
+
+# adds another logical switch 'lswitch1' and vlan_bindings.
+AT_CHECK([vtep-ctl add-ls lswitch1 -- bind-ls br-vtep p0 200 lswitch1])
+# adds lport in ovn-nb database for lswitch1.
+OVN_NB_ADD_VTEP_PORT([br-test], [br-vtep_lswitch1], [br-vtep], [lswitch1])
+OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Port_Binding | grep -- br-vtep_lswitch1`"])
+# This is allowed, but not recommended, to have two vlan_bindings (to different vtep logical switches)
+# from one vtep gateway physical port in one ovn-nb logical swithch.
+AT_CHECK_UNQUOTED([ovn-sbctl --columns=chassis list Port_Binding | cut -d ':' -f2 | tr -d ' ' | sort -d], [0], [dnl
+
+${chassis_uuid}
+${chassis_uuid}
+])
+
+# adds another lport in ovn-nb database for lswitch0.
+OVN_NB_ADD_VTEP_PORT([br-test], [br-vtep_lswitch0_dup], [br-vtep], [lswitch0])
+OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Port_Binding | grep -- br-vtep_lswitch0_dup`"])
+# it is not allowed to have more than one ovn-nb logical port for the same
+# vtep logical switch on a vtep gateway chassis, so should still see only
+# two port_binding entries bound.
+AT_CHECK_UNQUOTED([ovn-sbctl --columns=chassis list Port_Binding | cut -d ':' -f2 | tr -d ' ' | sort -d], [0], [dnl
+
+
+[[]]
+${chassis_uuid}
+${chassis_uuid}
+])
+# confirms the warning log.
+AT_CHECK([sed -n 's/^.*\(|WARN|.*\)$/\1/p' ovn-controller-vtep.log | sed 's/([[-_0-9a-z]][[-_0-9a-z]]*)/()/g' | uniq], [0], [dnl
+|WARN|logical switch (), on vtep gateway chassis () has already been associated with logical port (), ignore logical port ()
+])
+
+# deletes physical ports from vtep.
+AT_CHECK([ovs-vsctl del-port p0 -- del-port p1])
+AT_CHECK([vtep-ctl del-port br-vtep p0 -- del-port br-vtep p1])
+OVS_WAIT_UNTIL([test -z "`ovn-sbctl list Chassis | grep -- br-vtep_lswitch`"])
+# should see empty chassis column in both binding entries.
+AT_CHECK_UNQUOTED([ovn-sbctl --columns=chassis list Port_Binding | cut -d ':' -f2 | tr -d ' ' | sort], [0], [dnl
+
+
+[[]]
+[[]]
+[[]]
+])
+
+OVN_CONTROLLER_VTEP_STOP([/has already been associated with logical port/d])
+AT_CLEANUP
+
+
+# Tests corner case: Binding the vtep logical switch from two different
+# datapath.
+AT_SETUP([ovn-controller-vtep - test binding 2])
+OVN_CONTROLLER_VTEP_START
+
+# adds logical switch 'lswitch0' and vlan_bindings.
+AT_CHECK([vtep-ctl add-ls lswitch0 -- bind-ls br-vtep p0 100 lswitch0])
+# adds lport in ovn-nb database, and sets the type and options.
+OVN_NB_ADD_VTEP_PORT([br-test], [br-vtep_lswitch0], [br-vtep], [lswitch0])
+OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Port_Binding  | grep br-vtep_lswitch0`"])
+
+# adds another lswitch 'br-void' in ovn-nb database.
+AT_CHECK([ovn-nbctl lswitch-add br-void])
+# adds another vtep pswitch 'br-vtep-void' in vtep database.
+AT_CHECK([vtep-ctl add-ps br-vtep-void -- add-port br-vtep-void p0-void -- bind-ls br-vtep-void p0-void 100 lswitch0])
+# adds a conflicting logical port (both br-vtep_lswitch0 and br-vtep-void_lswitch0
+# are bound to the same logical switch, but they are on different datapath).
+OVN_NB_ADD_VTEP_PORT([br-void], [br-vtep-void_lswitch0], [br-vtep-void], [lswitch0])
+OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Port_Binding  | grep br-vtep-void_lswitch0`"])
+OVS_WAIT_UNTIL([test -n "`grep WARN ovn-controller-vtep.log`"])
+# confirms the warning log.
+AT_CHECK([sed -n 's/^.*\(|WARN|.*\)$/\1/p' ovn-controller-vtep.log | sed 's/([[-_0-9a-z]][[-_0-9a-z]]*)/()/g;s/(with tunnel key [[0-9]][[0-9]]*)/()/g' | uniq], [0], [dnl
+|WARN|logical switch (), on vtep gateway chassis () has already been associated with logical datapath (), ignore logical port () which belongs to logical datapath ()
+])
+
+# then deletes 'br-void' and 'br-vtep-void', should see 'br-vtep_lswitch0'
+# bound correctly.
+AT_CHECK([ovn-nbctl lswitch-del br-void])
+# adds another vtep pswitch 'br-vtep-void' in vtep database.
+AT_CHECK([vtep-ctl del-ps br-vtep-void])
+OVS_WAIT_UNTIL([test -z "`ovn-sbctl list Port_Binding | grep br-vtep-void_lswitch0`"])
+chassis_uuid=$(ovn-sbctl --columns=_uuid list Chassis br-vtep | cut -d ':' -f2 | tr -d ' ')
+AT_CHECK_UNQUOTED([ovn-sbctl --columns=chassis list Port_Binding br-vtep_lswitch0 | cut -d ':' -f2 | tr -d ' '], [0], [dnl
+${chassis_uuid}
+])
+
+OVN_CONTROLLER_VTEP_STOP([/has already been associated with logical datapath/d])
 AT_CLEANUP