git: 847b0d07c43c - main - carp tests: negative demotion

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Mon, 01 Nov 2021 17:08:52 UTC
The branch main has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=847b0d07c43c1190f0015c4c93a9e8fd953e3ab5

commit 847b0d07c43c1190f0015c4c93a9e8fd953e3ab5
Author:     Marius Halden <marius.halden@modirum.com>
AuthorDate: 2021-10-31 20:22:10 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2021-11-01 16:08:23 +0000

    carp tests: negative demotion
    
    PR:             259528
    Reviewed by:    donner
    MFC after:      3 weeks
    Sponsored by:   Modirum MDPay
    Differential Revision:  https://reviews.freebsd.org/D32760
---
 tests/sys/netinet/carp.sh | 67 +++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 59 insertions(+), 8 deletions(-)

diff --git a/tests/sys/netinet/carp.sh b/tests/sys/netinet/carp.sh
index 30ae79c93c8d..267e70ebf0dc 100755
--- a/tests/sys/netinet/carp.sh
+++ b/tests/sys/netinet/carp.sh
@@ -48,6 +48,15 @@ wait_for_carp()
 	done
 }
 
+carp_init()
+{
+	if ! kldstat -q -m carp; then
+		atf_skip "This test requires carp"
+	fi
+
+	vnet_init
+}
+
 atf_test_case "basic_v4" "cleanup"
 basic_v4_head()
 {
@@ -57,11 +66,8 @@ basic_v4_head()
 
 basic_v4_body()
 {
-	if ! kldstat -q -m carp; then
-		atf_skip "This test requires carp"
-	fi
+	carp_init
 
-	vnet_init
 	bridge=$(vnet_mkbridge)
 	epair_one=$(vnet_mkepair)
 	epair_two=$(vnet_mkepair)
@@ -104,11 +110,8 @@ basic_v6_head()
 
 basic_v6_body()
 {
-	if ! kldstat -q -m carp; then
-		atf_skip "This test requires carp"
-	fi
+	carp_init
 
-	vnet_init
 	bridge=$(vnet_mkbridge)
 	epair_one=$(vnet_mkepair)
 	epair_two=$(vnet_mkepair)
@@ -145,8 +148,56 @@ basic_v6_cleanup()
 	vnet_cleanup
 }
 
+atf_test_case "negative_demotion" "cleanup"
+negative_demotion_head()
+{
+	atf_set descr 'Test PR #259528'
+	atf_set require.user root
+}
+
+negative_demotion_body()
+{
+	carp_init
+
+	epair=$(vnet_mkepair)
+
+	vnet_mkjail one ${epair}a
+	jexec one sysctl net.inet.carp.preempt=1
+	jexec one ifconfig ${epair}a 192.0.2.1/24 up
+	jexec one ifconfig ${epair}a add vhid 1 192.0.2.254/24 \
+	    advskew 0 pass foobar
+
+	vnet_mkjail two ${epair}b
+	jexec two sysctl net.inet.carp.preempt=1
+	jexec two ifconfig ${epair}b 192.0.2.2/24 up
+	jexec two ifconfig ${epair}b add vhid 1 192.0.2.254/24 \
+	    advskew 100 pass foobar
+
+	# Allow things to settle
+	wait_for_carp one ${epair}a two ${epair}b
+
+	if is_master one ${epair}a && is_master two ${epair}b
+	then
+		atf_fail "Two masters!"
+	fi
+
+	jexec one sysctl net.inet.carp.demotion=-1
+	sleep 3
+
+	if is_master one ${epair}a && is_master two ${epair}b
+	then
+		atf_fail "Two masters!"
+	fi
+}
+
+negative_demotion_cleanup()
+{
+	vnet_cleanup
+}
+
 atf_init_test_cases()
 {
 	atf_add_test_case "basic_v4"
 	atf_add_test_case "basic_v6"
+	atf_add_test_case "negative_demotion"
 }