Skip to content

Commit

Permalink
stub out transit join
Browse files Browse the repository at this point in the history
  • Loading branch information
mjarmy committed Jun 12, 2020
1 parent f7536c2 commit f3039df
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 74 deletions.
43 changes: 8 additions & 35 deletions helper/testhelpers/testhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,14 +412,6 @@ func (p *TestRaftServerAddressProvider) ServerAddr(id raftlib.ServerID) (raftlib
}

func RaftClusterJoinNodes(t testing.T, cluster *vault.TestCluster) {
raftClusterJoinNodes(t, cluster, false)
}

func RaftClusterJoinNodesWithStoredKeys(t testing.T, cluster *vault.TestCluster) {
raftClusterJoinNodes(t, cluster, true)
}

func raftClusterJoinNodes(t testing.T, cluster *vault.TestCluster, useStoredKeys bool) {

addressProvider := &TestRaftServerAddressProvider{Cluster: cluster}
atomic.StoreUint32(&vault.UpdateClusterAddrForTests, 1)
Expand All @@ -430,19 +422,13 @@ func raftClusterJoinNodes(t testing.T, cluster *vault.TestCluster, useStoredKeys
{
EnsureCoreSealed(t, leader)
leader.UnderlyingRawStorage.(*raft.RaftBackend).SetServerAddressProvider(addressProvider)
if useStoredKeys {
cluster.UnsealCoreWithStoredKeys(t, leader)
} else {
cluster.UnsealCore(t, leader)
}
cluster.UnsealCore(t, leader)
vault.TestWaitActive(t, leader.Core)
}

leaderInfos := []*raft.LeaderJoinInfo{
&raft.LeaderJoinInfo{
LeaderAPIAddr: leader.Client.Address(),
TLSConfig: leader.TLSConfig,
},
leaderInfo := &raft.LeaderJoinInfo{
LeaderAPIAddr: leader.Client.Address(),
TLSConfig: leader.TLSConfig,
}

for i := 1; i < len(cluster.Cores); i++ {
Expand All @@ -465,23 +451,10 @@ func raftClusterJoinNodes(t testing.T, cluster *vault.TestCluster, useStoredKeys
WaitForNCoresUnsealed(t, cluster, len(cluster.Cores))
}

func awaitUnsealWithStoredKeys(t testing.T, core *vault.TestClusterCore) {
func RaftClusterJoinNodesWithStoredKeys(t testing.T, cluster *vault.TestCluster) {

timeout := time.Now().Add(30 * time.Second)
for {
if time.Now().After(timeout) {
t.Fatal("raft join: timeout waiting for core to unseal")
}
// Its actually ok for an error to happen here the first couple of
// times -- it means the raft join hasn't gotten around to initializing
// the backend yet.
err := core.UnsealWithStoredKeys(context.Background())
if err == nil {
return
}
core.Logger().Warn("raft join: failed to unseal core", "error", err)
time.Sleep(time.Second)
}
leader := cluster.Cores[0]
debugRaftConfiguration(t, leader)
}

// HardcodedServerAddressProvider is a ServerAddressProvider that uses
Expand Down Expand Up @@ -533,7 +506,7 @@ func SetRaftAddressProviders(t testing.T, cluster *vault.TestCluster, provider r
// VerifyRaftConfiguration checks that we have a valid raft configuration, i.e.
// the correct number of servers, having the correct NodeIDs, and exactly one
// leader.
func VerifyRaftConfiguration(t testing.T, core *vault.TestClusterCore, numCores int) error {
func VerifyRaftConfiguration(core *vault.TestClusterCore, numCores int) error {

backend := core.UnderlyingRawStorage.(*raft.RaftBackend)
ctx := namespace.RootContext(context.Background())
Expand Down
73 changes: 35 additions & 38 deletions vault/external_tests/seal_migration/seal_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,35 @@ func testVariousBackends(t *testing.T, tf testFunc) {

logger := logging.NewVaultLogger(hclog.Debug).Named(t.Name())

t.Run("inmem", func(t *testing.T) {
t.Parallel()

logger := logger.Named("inmem")
storage, cleanup := teststorage.MakeReusableStorage(
t, logger, teststorage.MakeInmemBackend(t, logger))
defer cleanup()
tf(t, logger, storage, 51000)
})

t.Run("file", func(t *testing.T) {
t.Parallel()

logger := logger.Named("file")
storage, cleanup := teststorage.MakeReusableStorage(
t, logger, teststorage.MakeFileBackend(t, logger))
defer cleanup()
tf(t, logger, storage, 52000)
})

t.Run("consul", func(t *testing.T) {
t.Parallel()

logger := logger.Named("consul")
storage, cleanup := teststorage.MakeReusableStorage(
t, logger, teststorage.MakeConsulBackend(t, logger))
defer cleanup()
tf(t, logger, storage, 53000)
})
//t.Run("inmem", func(t *testing.T) {
// t.Parallel()

// logger := logger.Named("inmem")
// storage, cleanup := teststorage.MakeReusableStorage(
// t, logger, teststorage.MakeInmemBackend(t, logger))
// defer cleanup()
// tf(t, logger, storage, 51000)
//})

//t.Run("file", func(t *testing.T) {
// t.Parallel()

// logger := logger.Named("file")
// storage, cleanup := teststorage.MakeReusableStorage(
// t, logger, teststorage.MakeFileBackend(t, logger))
// defer cleanup()
// tf(t, logger, storage, 52000)
//})

//t.Run("consul", func(t *testing.T) {
// t.Parallel()

// logger := logger.Named("consul")
// storage, cleanup := teststorage.MakeReusableStorage(
// t, logger, teststorage.MakeConsulBackend(t, logger))
// defer cleanup()
// tf(t, logger, storage, 53000)
//})

t.Run("raft", func(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -95,7 +95,6 @@ func testTransit(

rootToken, recoveryKeys, transitSeal := initializeTransit(t, logger, storage, basePort, tss)
println("rootToken, recoveryKeys, transitSeal", rootToken, recoveryKeys, transitSeal)
//reuseShamir(t, logger, storage, basePort, rootToken, barrierKeys)
}

// initializeShamir initializes a brand new backend storage with Shamir.
Expand Down Expand Up @@ -129,7 +128,7 @@ func initializeShamir(
// Unseal
if storage.IsRaft {
testhelpers.RaftClusterJoinNodes(t, cluster)
if err := testhelpers.VerifyRaftConfiguration(t, leader, numTestCores); err != nil {
if err := testhelpers.VerifyRaftConfiguration(leader, numTestCores); err != nil {
t.Fatal(err)
}
} else {
Expand Down Expand Up @@ -193,7 +192,7 @@ func reuseShamir(
}
time.Sleep(15 * time.Second)

if err := testhelpers.VerifyRaftConfiguration(t, leader, numTestCores); err != nil {
if err := testhelpers.VerifyRaftConfiguration(leader, numTestCores); err != nil {
t.Fatal(err)
}
} else {
Expand Down Expand Up @@ -254,12 +253,10 @@ func initializeTransit(

// Unseal
if storage.IsRaft {
testhelpers.RaftClusterJoinNodes(t, cluster)
if err := testhelpers.VerifyRaftConfiguration(t, leader, numTestCores); err != nil {
t.Fatal(err)
}
} else {
cluster.UnsealCores(t)
testhelpers.RaftClusterJoinNodesWithStoredKeys(t, cluster)
//if err := testhelpers.VerifyRaftConfiguration(leader, numTestCores); err != nil {
// t.Fatal(err)
//}
}
testhelpers.WaitForNCoresUnsealed(t, cluster, numTestCores)

Expand Down
3 changes: 2 additions & 1 deletion vault/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,8 @@ func (c *TestCluster) UnsealCore(t testing.T, core *TestClusterCore) {
}

func (c *TestCluster) UnsealCoreWithStoredKeys(t testing.T, core *TestClusterCore) {
if err := core.UnsealWithStoredKeys(context.Background()); err != nil {
err := core.UnsealWithStoredKeys(context.Background())
if err != nil {
t.Fatal(err)
}
}
Expand Down

0 comments on commit f3039df

Please sign in to comment.