From b7892539acfa8724385dfd2277d0de593c7149cf Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Sat, 30 Dec 2023 13:24:58 -0500 Subject: [PATCH] E2E testing of DNS clustering with non-voters --- cluster/bootstrap.go | 3 ++- cmd/rqlited/flags.go | 4 ++-- cmd/rqlited/main.go | 3 +-- system_test/e2e/auto_clustering.py | 21 ++++++++++++++++++++- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/cluster/bootstrap.go b/cluster/bootstrap.go index 4ca6f2d8..70ee3276 100644 --- a/cluster/bootstrap.go +++ b/cluster/bootstrap.go @@ -137,7 +137,8 @@ func (b *Bootstrapper) SetCredentials(creds *Credentials) { // - joining an existing cluster by explicitly joining it through a node returned // by the AddressProvider, or // - if it's a Voting node, notifying all nodes returned by the AddressProvider -// that it exists, allowing a cluster-wide bootstrap take place. +// that it exists, potentially allowing a cluster-wide bootstrap take place +// which will include this node. // // Returns nil if the boot operation was successful, or if done() ever returns // true. done() is periodically polled by the boot process. Returns an error diff --git a/cmd/rqlited/flags.go b/cmd/rqlited/flags.go index d75bfbcb..ef3ddfbd 100644 --- a/cmd/rqlited/flags.go +++ b/cmd/rqlited/flags.go @@ -322,8 +322,8 @@ func (c *Config) Validate() error { return fmt.Errorf("bootstrapping not applicable when using %s", c.DiscoMode) } case DiscoModeDNS, DiscoModeDNSSRV: - if c.BootstrapExpect == 0 { - return fmt.Errorf("bootstrap-expect value required when using %s", c.DiscoMode) + if c.BootstrapExpect == 0 && !c.RaftNonVoter { + return fmt.Errorf("bootstrap-expect value required when using %s with a voting node", c.DiscoMode) } default: return fmt.Errorf("disco mode must be one of %s, %s, %s, or %s", diff --git a/cmd/rqlited/main.go b/cmd/rqlited/main.go index 066397be..c56db449 100644 --- a/cmd/rqlited/main.go +++ b/cmd/rqlited/main.go @@ -26,7 +26,6 @@ import ( "github.com/rqlite/rqlite/v8/cmd" "github.com/rqlite/rqlite/v8/db" "github.com/rqlite/rqlite/v8/disco" - "github.com/rqlite/rqlite/v8/http" httpd "github.com/rqlite/rqlite/v8/http" "github.com/rqlite/rqlite/v8/rtls" "github.com/rqlite/rqlite/v8/store" @@ -559,7 +558,7 @@ func createCluster(cfg *Config, hasPeers bool, client *cluster.Client, str *stor func networkCheckJoinAddrs(joinAddrs []string) error { log.Println("checking that any supplied join addresses don't serve HTTP(S)") - if addr, ok := http.AnyServingHTTP(joinAddrs); ok { + if addr, ok := httpd.AnyServingHTTP(joinAddrs); ok { return fmt.Errorf("join address %s appears to be serving HTTP when it should be Raft", addr) } return nil diff --git a/system_test/e2e/auto_clustering.py b/system_test/e2e/auto_clustering.py index 213cc61d..55b27cad 100644 --- a/system_test/e2e/auto_clustering.py +++ b/system_test/e2e/auto_clustering.py @@ -132,7 +132,7 @@ class TestBootstrappingRestartLeaveOnRemove(unittest.TestCase): deprovision_node(n2) class TestAutoClusteringDNS(unittest.TestCase): - def test(self): + def test_3_voters(self): os.environ['RQLITE_DISCO_DNS_HOSTS'] = 'localhost:4002,localhost:4004,localhost:4006' filename = write_random_file('{"name":"rqlite.cluster"}') # Anything, doesn't matter. @@ -151,6 +151,25 @@ class TestAutoClusteringDNS(unittest.TestCase): deprovision_node(n1) deprovision_node(n2) + def test_3_voters_1_nonvoter(self): + os.environ['RQLITE_DISCO_DNS_HOSTS'] = 'localhost:4002,localhost:4004,localhost:4006' + filename = write_random_file('{"name":"rqlite.cluster"}') # Anything, doesn't matter. + + n0 = Node(RQLITED_PATH, '0', raft_addr='localhost:4002', bootstrap_expect=3) + n1 = Node(RQLITED_PATH, '1', raft_addr='localhost:4004', bootstrap_expect=3) + n2 = Node(RQLITED_PATH, '2', raft_addr='localhost:4006', bootstrap_expect=3) + + n0.start(disco_mode='dns', disco_config=filename) + n1.start(disco_mode='dns', disco_config=filename) + n2.start(disco_mode='dns', disco_config=filename) + + self.assertEqual(n0.wait_for_leader(), n1.wait_for_leader()) + self.assertEqual(n0.wait_for_leader(), n2.wait_for_leader()) + + n3 = Node(RQLITED_PATH, '3', raft_voter=False) + n3.start(disco_mode='dns', disco_config=filename) + self.assertEqual(n0.wait_for_leader(), n3.wait_for_leader()) + def tearDown(self): del os.environ['RQLITE_DISCO_DNS_HOSTS']