diff --git a/nomad/rpc_test.go b/nomad/rpc_test.go index e307f2a30e2..a4548ada1cb 100644 --- a/nomad/rpc_test.go +++ b/nomad/rpc_test.go @@ -15,6 +15,7 @@ import ( "testing" "time" + "github.com/hashicorp/go-hclog" "github.com/hashicorp/go-msgpack/codec" "github.com/hashicorp/go-sockaddr" msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc" @@ -1346,9 +1347,9 @@ type tlsTestHelper struct { nodeID int mtlsServer1 *Server - mtlsServer1Cleanup func() + mtlsServerCleanup1 func() mtlsServer2 *Server - mtlsServer2Cleanup func() + mtlsServerCleanup2 func() nonVerifyServer *Server nonVerifyServerCleanup func() @@ -1375,46 +1376,32 @@ func newTLSTestHelper(t *testing.T) tlsTestHelper { // Generate servers and their certificate. h.serverCert = h.newCert(t, "server.global.nomad") - h.mtlsServer1, h.mtlsServer1Cleanup = TestServer(t, func(c *Config) { - c.BootstrapExpect = 2 - c.TLSConfig = &config.TLSConfig{ - EnableRPC: true, - VerifyServerHostname: true, - CAFile: filepath.Join(h.dir, "ca.pem"), - CertFile: h.serverCert + ".pem", - KeyFile: h.serverCert + ".key", - } - }) - h.mtlsServer2, h.mtlsServer2Cleanup = TestServer(t, func(c *Config) { - c.BootstrapExpect = 2 - c.TLSConfig = &config.TLSConfig{ - EnableRPC: true, - VerifyServerHostname: true, - CAFile: filepath.Join(h.dir, "ca.pem"), - CertFile: h.serverCert + ".pem", - KeyFile: h.serverCert + ".key", - } - }) - TestJoin(t, h.mtlsServer1, h.mtlsServer2) - testutil.WaitForLeaders(t, h.mtlsServer1.RPC, h.mtlsServer2.RPC) + makeServer := func(bootstrapExpect int, verifyServerHostname bool) (*Server, func()) { + return TestServer(t, func(c *Config) { + c.Logger.SetLevel(hclog.Off) + c.BootstrapExpect = bootstrapExpect + c.TLSConfig = &config.TLSConfig{ + EnableRPC: true, + VerifyServerHostname: verifyServerHostname, + CAFile: filepath.Join(h.dir, "ca.pem"), + CertFile: h.serverCert + ".pem", + KeyFile: h.serverCert + ".key", + } + }) + } - h.nonVerifyServer, h.nonVerifyServerCleanup = TestServer(t, func(c *Config) { - c.TLSConfig = &config.TLSConfig{ - EnableRPC: true, - VerifyServerHostname: false, - CAFile: filepath.Join(h.dir, "ca.pem"), - CertFile: h.serverCert + ".pem", - KeyFile: h.serverCert + ".key", - } - }) - testutil.WaitForLeaders(t, h.nonVerifyServer.RPC) + h.mtlsServer1, h.mtlsServerCleanup1 = makeServer(3, true) + h.mtlsServer2, h.mtlsServerCleanup2 = makeServer(3, true) + h.nonVerifyServer, h.nonVerifyServerCleanup = makeServer(3, false) + TestJoin(t, h.mtlsServer1, h.mtlsServer2, h.nonVerifyServer) + testutil.WaitForLeaders(t, h.mtlsServer1.RPC, h.mtlsServer2.RPC, h.nonVerifyServer.RPC) return h } func (h tlsTestHelper) cleanup() { - h.mtlsServer1Cleanup() - h.mtlsServer2Cleanup() + h.mtlsServerCleanup1() + h.mtlsServerCleanup2() h.nonVerifyServerCleanup() }