mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
test: Create a subdirectory for each member when DataDirPath is specified
When e2e test cases specify the DataDirPath and there are more than one member in the cluster, we need to create a subdirectory for each member. Otherwise all members share the same directory and accordingly lead to conflict. Signed-off-by: Benjamin Wang <wachao@vmware.com>
This commit is contained in:
parent
2f558ca0db
commit
dbc7204610
@ -17,6 +17,7 @@ package e2e
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -148,7 +149,8 @@ func TestEtctlutlMigrate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.Log("etcdutl migrate...")
|
t.Log("etcdutl migrate...")
|
||||||
args := []string{e2e.BinPath.Etcdutl, "migrate", "--data-dir", dataDirPath, "--target-version", tc.targetVersion}
|
memberDataDir := epc.Procs[0].Config().DataDirPath
|
||||||
|
args := []string{e2e.BinPath.Etcdutl, "migrate", "--data-dir", memberDataDir, "--target-version", tc.targetVersion}
|
||||||
if tc.force {
|
if tc.force {
|
||||||
args = append(args, "--force")
|
args = append(args, "--force")
|
||||||
}
|
}
|
||||||
@ -158,7 +160,7 @@ func TestEtctlutlMigrate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.Log("etcdutl migrate...")
|
t.Log("etcdutl migrate...")
|
||||||
be := backend.NewDefaultBackend(lg, dataDirPath+"/member/snap/db")
|
be := backend.NewDefaultBackend(lg, filepath.Join(memberDataDir, "member/snap/db"))
|
||||||
defer be.Close()
|
defer be.Close()
|
||||||
|
|
||||||
ver := schema.ReadStorageVersion(be.ReadTx())
|
ver := schema.ReadStorageVersion(be.ReadTx())
|
||||||
|
@ -32,12 +32,13 @@ import (
|
|||||||
"go.uber.org/zap/zaptest"
|
"go.uber.org/zap/zaptest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func createV2store(t testing.TB, dataDirPath string) {
|
func createV2store(t testing.TB, dataDirPath string) string {
|
||||||
t.Log("Creating not-yet v2-deprecated etcd")
|
t.Log("Creating not-yet v2-deprecated etcd")
|
||||||
|
|
||||||
cfg := e2e.ConfigStandalone(e2e.EtcdProcessClusterConfig{Version: e2e.LastVersion, EnableV2: true, DataDirPath: dataDirPath, SnapshotCount: 5})
|
cfg := e2e.ConfigStandalone(e2e.EtcdProcessClusterConfig{Version: e2e.LastVersion, EnableV2: true, DataDirPath: dataDirPath, SnapshotCount: 5})
|
||||||
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, cfg)
|
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, cfg)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
memberDataDir := epc.Procs[0].Config().DataDirPath
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
assert.NoError(t, epc.Stop())
|
assert.NoError(t, epc.Stop())
|
||||||
@ -51,6 +52,7 @@ func createV2store(t testing.TB, dataDirPath string) {
|
|||||||
t.Fatalf("failed put with curl (%v)", err)
|
t.Fatalf("failed put with curl (%v)", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return memberDataDir
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertVerifyCannotStartV2deprecationWriteOnly(t testing.TB, dataDirPath string) {
|
func assertVerifyCannotStartV2deprecationWriteOnly(t testing.TB, dataDirPath string) {
|
||||||
@ -79,16 +81,17 @@ func TestV2DeprecationFlags(t *testing.T) {
|
|||||||
t.Skipf("%q does not exist", e2e.BinPath.EtcdLastRelease)
|
t.Skipf("%q does not exist", e2e.BinPath.EtcdLastRelease)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var memberDataDir string
|
||||||
t.Run("create-storev2-data", func(t *testing.T) {
|
t.Run("create-storev2-data", func(t *testing.T) {
|
||||||
createV2store(t, dataDirPath)
|
memberDataDir = createV2store(t, dataDirPath)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("--v2-deprecation=not-yet fails", func(t *testing.T) {
|
t.Run("--v2-deprecation=not-yet fails", func(t *testing.T) {
|
||||||
assertVerifyCannotStartV2deprecationNotYet(t, dataDirPath)
|
assertVerifyCannotStartV2deprecationNotYet(t, memberDataDir)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("--v2-deprecation=write-only fails", func(t *testing.T) {
|
t.Run("--v2-deprecation=write-only fails", func(t *testing.T) {
|
||||||
assertVerifyCannotStartV2deprecationWriteOnly(t, dataDirPath)
|
assertVerifyCannotStartV2deprecationWriteOnly(t, memberDataDir)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -105,17 +108,19 @@ func TestV2DeprecationSnapshotMatches(t *testing.T) {
|
|||||||
}
|
}
|
||||||
snapshotCount := 10
|
snapshotCount := 10
|
||||||
epc := runEtcdAndCreateSnapshot(t, e2e.LastVersion, lastReleaseData, snapshotCount)
|
epc := runEtcdAndCreateSnapshot(t, e2e.LastVersion, lastReleaseData, snapshotCount)
|
||||||
|
oldMemberDataDir := epc.Procs[0].Config().DataDirPath
|
||||||
cc1, err := e2e.NewEtcdctl(epc.Cfg, epc.EndpointsV3())
|
cc1, err := e2e.NewEtcdctl(epc.Cfg, epc.EndpointsV3())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
members1 := addAndRemoveKeysAndMembers(ctx, t, cc1, snapshotCount)
|
members1 := addAndRemoveKeysAndMembers(ctx, t, cc1, snapshotCount)
|
||||||
assert.NoError(t, epc.Close())
|
assert.NoError(t, epc.Close())
|
||||||
epc = runEtcdAndCreateSnapshot(t, e2e.CurrentVersion, currentReleaseData, snapshotCount)
|
epc = runEtcdAndCreateSnapshot(t, e2e.CurrentVersion, currentReleaseData, snapshotCount)
|
||||||
|
newMemberDataDir := epc.Procs[0].Config().DataDirPath
|
||||||
cc2, err := e2e.NewEtcdctl(epc.Cfg, epc.EndpointsV3())
|
cc2, err := e2e.NewEtcdctl(epc.Cfg, epc.EndpointsV3())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
members2 := addAndRemoveKeysAndMembers(ctx, t, cc2, snapshotCount)
|
members2 := addAndRemoveKeysAndMembers(ctx, t, cc2, snapshotCount)
|
||||||
assert.NoError(t, epc.Close())
|
assert.NoError(t, epc.Close())
|
||||||
|
|
||||||
assertSnapshotsMatch(t, lastReleaseData, currentReleaseData, func(data []byte) []byte {
|
assertSnapshotsMatch(t, oldMemberDataDir, newMemberDataDir, func(data []byte) []byte {
|
||||||
// Patch cluster version
|
// Patch cluster version
|
||||||
data = bytes.Replace(data, []byte("3.5.0"), []byte("X.X.X"), -1)
|
data = bytes.Replace(data, []byte("3.5.0"), []byte("X.X.X"), -1)
|
||||||
data = bytes.Replace(data, []byte("3.6.0"), []byte("X.X.X"), -1)
|
data = bytes.Replace(data, []byte("3.6.0"), []byte("X.X.X"), -1)
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -121,8 +122,13 @@ type EtcdProcessCluster struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type EtcdProcessClusterConfig struct {
|
type EtcdProcessClusterConfig struct {
|
||||||
Logger *zap.Logger
|
Logger *zap.Logger
|
||||||
Version ClusterVersion
|
Version ClusterVersion
|
||||||
|
// DataDirPath specifies the data-dir for the members. If test cases
|
||||||
|
// do not specify `DataDirPath`, then e2e framework creates a
|
||||||
|
// temporary directory for each member; otherwise, it creates a
|
||||||
|
// subdirectory (e.g. member-0, member-1 and member-2) under the given
|
||||||
|
// `DataDirPath` for each member.
|
||||||
DataDirPath string
|
DataDirPath string
|
||||||
KeepDataDir bool
|
KeepDataDir bool
|
||||||
EnvVars map[string]string
|
EnvVars map[string]string
|
||||||
@ -423,9 +429,17 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in
|
|||||||
purl := url.URL{Scheme: cfg.PeerScheme(), Host: fmt.Sprintf("localhost:%d", port+1)}
|
purl := url.URL{Scheme: cfg.PeerScheme(), Host: fmt.Sprintf("localhost:%d", port+1)}
|
||||||
|
|
||||||
name := fmt.Sprintf("%s-test-%d", testNameCleanRegex.ReplaceAllString(tb.Name(), ""), i)
|
name := fmt.Sprintf("%s-test-%d", testNameCleanRegex.ReplaceAllString(tb.Name(), ""), i)
|
||||||
|
|
||||||
dataDirPath := cfg.DataDirPath
|
dataDirPath := cfg.DataDirPath
|
||||||
if cfg.DataDirPath == "" {
|
if cfg.DataDirPath == "" {
|
||||||
dataDirPath = tb.TempDir()
|
dataDirPath = tb.TempDir()
|
||||||
|
} else {
|
||||||
|
// When test cases specify the DataDirPath and there are more than
|
||||||
|
// one member in the cluster, we need to create a subdirectory for
|
||||||
|
// each member to avoid conflict.
|
||||||
|
// We also create a subdirectory for one-member cluster, because we
|
||||||
|
// support dynamically adding new member.
|
||||||
|
dataDirPath = filepath.Join(cfg.DataDirPath, fmt.Sprintf("member-%d", i))
|
||||||
}
|
}
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user