Vault Automation d7d140a3a3
Backport Add kmip cluster tests. Also fix a bug in EnableDRSecondaryNoWait. into ce/main (#12059)
* no-op commit

* Apply CE changes from #12052

---------

Co-authored-by: ncabatoff <ncabatoff@hashicorp.com>
2026-01-29 10:38:19 -05:00

76 lines
2.5 KiB
Go

// Copyright IBM Corp. 2016, 2025
// SPDX-License-Identifier: BUSL-1.1
package replication
import (
"context"
"testing"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/helper/testhelpers/teststorage"
"github.com/hashicorp/vault/sdk/helper/logging"
"github.com/hashicorp/vault/sdk/helper/testcluster"
"github.com/hashicorp/vault/vault"
"github.com/stretchr/testify/require"
)
// SetCorePerf returns a ReplicationSet using NewTestCluster,
// i.e. core-based rather than subprocess- or docker-based clusters.
// The set will contain two clusters A and C connected using perf replication.
func SetCorePerf(t *testing.T, conf *vault.CoreConfig, opts *vault.TestClusterOptions) *testcluster.ReplicationSet {
r := NewReplicationSetCore(t, conf, opts, teststorage.InmemBackendSetup)
t.Cleanup(r.Cleanup)
// By default NewTestCluster will mount a kv under secret/. This isn't
// done by docker-based clusters, so remove this to make us more like that.
require.Nil(t, r.Clusters["A"].Nodes()[0].APIClient().Sys().Unmount("secret"))
err := r.StandardPerfReplication(context.Background())
if err != nil {
t.Fatal(err)
}
return r
}
func SetCoreDR(t *testing.T, conf *vault.CoreConfig, opts *vault.TestClusterOptions) *testcluster.ReplicationSet {
r := NewReplicationSetCore(t, conf, opts, teststorage.InmemBackendSetup)
t.Cleanup(r.Cleanup)
// By default NewTestCluster will mount a kv under secret/. This isn't
// done by docker-based clusters, so remove this to make us more like that.
require.Nil(t, r.Clusters["A"].Nodes()[0].APIClient().Sys().Unmount("secret"))
err := r.StandardDRReplication(context.Background())
if err != nil {
t.Fatal(err)
}
return r
}
func NewReplicationSetCore(t *testing.T, conf *vault.CoreConfig, opts *vault.TestClusterOptions, setup teststorage.ClusterSetupMutator) *testcluster.ReplicationSet {
r := &testcluster.ReplicationSet{
Clusters: map[string]testcluster.VaultCluster{},
Logger: logging.NewVaultLogger(hclog.Trace).Named(t.Name()),
}
r.Builder = func(ctx context.Context, name string, baseLogger hclog.Logger) (testcluster.VaultCluster, error) {
newconf, newopts := teststorage.ClusterSetup(conf, opts, setup)
newopts.Logger = baseLogger.Named(name)
if opts.NumCores > 0 {
opts.FirstCoreNumber += opts.NumCores
} else {
opts.FirstCoreNumber += 3
}
return vault.NewTestCluster(t, newconf, newopts), nil
}
a, err := r.Builder(context.TODO(), "A", r.Logger)
if err != nil {
t.Fatal(err)
}
r.Clusters["A"] = a
return r
}