From 71b40b3abf53125f2d0431162b36d7087c825cac Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Sun, 23 Oct 2022 09:08:30 +0200 Subject: [PATCH] tests: Extend common test to run previous release Signed-off-by: Marek Siarkowicz --- tests/common/e2e_test.go | 47 ++++++++++++++++++++++ tests/common/integration_test.go | 26 ++++++++++++ tests/common/kv_test.go | 6 +-- tests/common/lease_test.go | 10 ++--- tests/common/main_test.go | 28 ++----------- tests/common/member_test.go | 6 +-- tests/common/role_test.go | 2 +- tests/common/status_test.go | 2 +- tests/common/txn_test.go | 4 +- tests/common/user_test.go | 10 ++--- tests/common/wait_leader_test.go | 2 +- tests/common/watch_test.go | 2 +- tests/e2e/cluster_downgrade_test.go | 5 +-- tests/e2e/ctl_v3_test.go | 6 --- tests/e2e/discovery_test.go | 8 ++-- tests/e2e/etcd_release_upgrade_test.go | 15 ++++--- tests/e2e/utl_migrate_test.go | 17 ++++---- tests/e2e/v2store_deprecation_test.go | 37 +++++++---------- tests/framework/config/cluster.go | 16 +++++++- tests/framework/e2e/cluster.go | 29 ++++++++++--- tests/framework/e2e/e2e.go | 3 ++ tests/framework/integration/integration.go | 3 ++ 22 files changed, 180 insertions(+), 104 deletions(-) diff --git a/tests/common/e2e_test.go b/tests/common/e2e_test.go index 1284714b1..2f68c66af 100644 --- a/tests/common/e2e_test.go +++ b/tests/common/e2e_test.go @@ -18,6 +18,7 @@ package common import ( + "go.etcd.io/etcd/client/pkg/v3/fileutil" "go.etcd.io/etcd/tests/v3/framework" "go.etcd.io/etcd/tests/v3/framework/config" "go.etcd.io/etcd/tests/v3/framework/e2e" @@ -25,6 +26,52 @@ import ( func init() { testRunner = framework.E2eTestRunner + clusterTestCases = e2eClusterTestCases +} + +func e2eClusterTestCases() []testCase { + tcs := []testCase{ + { + name: "NoTLS", + config: config.ClusterConfig{ClusterSize: 1}, + }, + { + name: "PeerTLS", + config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.ManualTLS}, + }, + { + name: "PeerAutoTLS", + config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.AutoTLS}, + }, + { + name: "ClientTLS", + config: config.ClusterConfig{ClusterSize: 1, ClientTLS: config.ManualTLS}, + }, + { + name: "ClientAutoTLS", + config: config.ClusterConfig{ClusterSize: 1, ClientTLS: config.AutoTLS}, + }, + } + if fileutil.Exist(e2e.BinPath.EtcdLastRelease) { + tcs = append(tcs, testCase{ + name: "MinorityLastVersion", + config: config.ClusterConfig{ + ClusterSize: 3, + E2eConfig: &config.E2eClusterConfig{ + Version: config.MinorityLastVersion, + }, + }, + }, testCase{ + name: "QuorumLastVersion", + config: config.ClusterConfig{ + ClusterSize: 3, + E2eConfig: &config.E2eClusterConfig{ + Version: config.QuorumLastVersion, + }, + }, + }) + } + return tcs } func WithAuth(userName, password string) config.ClientOption { diff --git a/tests/common/integration_test.go b/tests/common/integration_test.go index d875dbc82..c69ade5f6 100644 --- a/tests/common/integration_test.go +++ b/tests/common/integration_test.go @@ -25,6 +25,32 @@ import ( func init() { testRunner = framework.IntegrationTestRunner + clusterTestCases = integrationClusterTestCases +} + +func integrationClusterTestCases() []testCase { + return []testCase{ + { + name: "NoTLS", + config: config.ClusterConfig{ClusterSize: 1}, + }, + { + name: "PeerTLS", + config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.ManualTLS}, + }, + { + name: "PeerAutoTLS", + config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.AutoTLS}, + }, + { + name: "ClientTLS", + config: config.ClusterConfig{ClusterSize: 1, ClientTLS: config.ManualTLS}, + }, + { + name: "ClientAutoTLS", + config: config.ClusterConfig{ClusterSize: 1, ClientTLS: config.AutoTLS}, + }, + } } func WithAuth(userName, password string) config.ClientOption { diff --git a/tests/common/kv_test.go b/tests/common/kv_test.go index 2acf29291..f894131ce 100644 --- a/tests/common/kv_test.go +++ b/tests/common/kv_test.go @@ -27,7 +27,7 @@ import ( func TestKVPut(t *testing.T) { testRunner.BeforeTest(t) - for _, tc := range clusterTestCases { + for _, tc := range clusterTestCases() { t.Run(tc.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() @@ -61,7 +61,7 @@ func TestKVPut(t *testing.T) { func TestKVGet(t *testing.T) { testRunner.BeforeTest(t) - for _, tc := range clusterTestCases { + for _, tc := range clusterTestCases() { t.Run(tc.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() @@ -121,7 +121,7 @@ func TestKVGet(t *testing.T) { func TestKVDelete(t *testing.T) { testRunner.BeforeTest(t) - for _, tc := range clusterTestCases { + for _, tc := range clusterTestCases() { t.Run(tc.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) defer cancel() diff --git a/tests/common/lease_test.go b/tests/common/lease_test.go index 972f52c9b..61157f0d7 100644 --- a/tests/common/lease_test.go +++ b/tests/common/lease_test.go @@ -28,7 +28,7 @@ import ( func TestLeaseGrantTimeToLive(t *testing.T) { testRunner.BeforeTest(t) - for _, tc := range clusterTestCases { + for _, tc := range clusterTestCases() { t.Run(tc.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() @@ -52,7 +52,7 @@ func TestLeaseGrantTimeToLive(t *testing.T) { func TestLeaseGrantAndList(t *testing.T) { testRunner.BeforeTest(t) - for _, tc := range clusterTestCases { + for _, tc := range clusterTestCases() { nestedCases := []struct { name string leaseCount int @@ -119,7 +119,7 @@ func TestLeaseGrantAndList(t *testing.T) { func TestLeaseGrantTimeToLiveExpired(t *testing.T) { testRunner.BeforeTest(t) - for _, tc := range clusterTestCases { + for _, tc := range clusterTestCases() { t.Run(tc.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() @@ -156,7 +156,7 @@ func TestLeaseGrantTimeToLiveExpired(t *testing.T) { func TestLeaseGrantKeepAliveOnce(t *testing.T) { testRunner.BeforeTest(t) - for _, tc := range clusterTestCases { + for _, tc := range clusterTestCases() { t.Run(tc.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() @@ -185,7 +185,7 @@ func TestLeaseGrantKeepAliveOnce(t *testing.T) { func TestLeaseGrantRevoke(t *testing.T) { testRunner.BeforeTest(t) - for _, tc := range clusterTestCases { + for _, tc := range clusterTestCases() { t.Run(tc.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() diff --git a/tests/common/main_test.go b/tests/common/main_test.go index 14f5641fe..1bce798a4 100644 --- a/tests/common/main_test.go +++ b/tests/common/main_test.go @@ -15,36 +15,14 @@ package common import ( + "go.etcd.io/etcd/tests/v3/framework" "testing" "go.etcd.io/etcd/tests/v3/framework/config" - intf "go.etcd.io/etcd/tests/v3/framework/interfaces" ) -var testRunner intf.TestRunner - -var clusterTestCases = []testCase{ - { - name: "NoTLS", - config: config.NewClusterConfig(config.WithClusterSize(1)), - }, - { - name: "PeerTLS", - config: config.NewClusterConfig(config.WithPeerTLS(config.ManualTLS)), - }, - { - name: "PeerAutoTLS", - config: config.NewClusterConfig(config.WithPeerTLS(config.AutoTLS)), - }, - { - name: "ClientTLS", - config: config.NewClusterConfig(config.WithClusterSize(1), config.WithClientTLS(config.ManualTLS)), - }, - { - name: "ClientAutoTLS", - config: config.NewClusterConfig(config.WithClusterSize(1), config.WithClientTLS(config.AutoTLS)), - }, -} +var testRunner = framework.UnitTestRunner +var clusterTestCases = func() []testCase { return nil } func TestMain(m *testing.M) { testRunner.TestMain(m) diff --git a/tests/common/member_test.go b/tests/common/member_test.go index 281e846ed..b7953226a 100644 --- a/tests/common/member_test.go +++ b/tests/common/member_test.go @@ -30,7 +30,7 @@ import ( func TestMemberList(t *testing.T) { testRunner.BeforeTest(t) - for _, tc := range clusterTestCases { + for _, tc := range clusterTestCases() { t.Run(tc.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() @@ -102,7 +102,7 @@ func TestMemberAdd(t *testing.T) { for _, learnerTc := range learnerTcs { for _, quorumTc := range quorumTcs { - for _, clusterTc := range clusterTestCases { + for _, clusterTc := range clusterTestCases() { t.Run(learnerTc.name+"/"+quorumTc.name+"/"+clusterTc.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() @@ -178,7 +178,7 @@ func TestMemberRemove(t *testing.T) { } for _, quorumTc := range tcs { - for _, clusterTc := range clusterTestCases { + for _, clusterTc := range clusterTestCases() { if !quorumTc.strictReconfigCheck && clusterTc.config.ClusterSize == 1 { // skip these test cases // when strictReconfigCheck is disabled, calling MemberRemove will cause the single node to panic diff --git a/tests/common/role_test.go b/tests/common/role_test.go index 62177e7cf..84e35d183 100644 --- a/tests/common/role_test.go +++ b/tests/common/role_test.go @@ -28,7 +28,7 @@ import ( func TestRoleAdd_Simple(t *testing.T) { testRunner.BeforeTest(t) - for _, tc := range clusterTestCases { + for _, tc := range clusterTestCases() { t.Run(tc.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() diff --git a/tests/common/status_test.go b/tests/common/status_test.go index 5ce0751fb..a6a984439 100644 --- a/tests/common/status_test.go +++ b/tests/common/status_test.go @@ -27,7 +27,7 @@ func TestStatus(t *testing.T) { testRunner.BeforeTest(t) - for _, tc := range clusterTestCases { + for _, tc := range clusterTestCases() { t.Run(tc.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() diff --git a/tests/common/txn_test.go b/tests/common/txn_test.go index 413e6086b..8e3942925 100644 --- a/tests/common/txn_test.go +++ b/tests/common/txn_test.go @@ -54,7 +54,7 @@ func TestTxnSucc(t *testing.T) { results: []string{"SUCCESS", `key "with" space`, "value \x23"}, }, } - for _, cfg := range clusterTestCases { + for _, cfg := range clusterTestCases() { t.Run(cfg.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() @@ -98,7 +98,7 @@ func TestTxnFail(t *testing.T) { results: []string{"FAILURE", "OK"}, }, } - for _, cfg := range clusterTestCases { + for _, cfg := range clusterTestCases() { t.Run(cfg.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() diff --git a/tests/common/user_test.go b/tests/common/user_test.go index bcc0d1e56..d921f8dd6 100644 --- a/tests/common/user_test.go +++ b/tests/common/user_test.go @@ -61,7 +61,7 @@ func TestUserAdd_Simple(t *testing.T) { password: "bar", }, } - for _, tc := range clusterTestCases { + for _, tc := range clusterTestCases() { for _, nc := range tcs { t.Run(tc.name+"/"+nc.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) @@ -96,7 +96,7 @@ func TestUserAdd_Simple(t *testing.T) { func TestUserAdd_DuplicateUserNotAllowed(t *testing.T) { testRunner.BeforeTest(t) - for _, tc := range clusterTestCases { + for _, tc := range clusterTestCases() { t.Run(tc.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() @@ -125,7 +125,7 @@ func TestUserAdd_DuplicateUserNotAllowed(t *testing.T) { func TestUserList(t *testing.T) { testRunner.BeforeTest(t) - for _, tc := range clusterTestCases { + for _, tc := range clusterTestCases() { t.Run(tc.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() @@ -166,7 +166,7 @@ func TestUserList(t *testing.T) { func TestUserDelete(t *testing.T) { testRunner.BeforeTest(t) - for _, tc := range clusterTestCases { + for _, tc := range clusterTestCases() { t.Run(tc.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() @@ -218,7 +218,7 @@ func TestUserDelete(t *testing.T) { func TestUserChangePassword(t *testing.T) { testRunner.BeforeTest(t) - for _, tc := range clusterTestCases { + for _, tc := range clusterTestCases() { t.Run(tc.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() diff --git a/tests/common/wait_leader_test.go b/tests/common/wait_leader_test.go index aa3958df4..faa1f716c 100644 --- a/tests/common/wait_leader_test.go +++ b/tests/common/wait_leader_test.go @@ -25,7 +25,7 @@ import ( func TestWaitLeader(t *testing.T) { testRunner.BeforeTest(t) - for _, tc := range clusterTestCases { + for _, tc := range clusterTestCases() { t.Run(tc.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() diff --git a/tests/common/watch_test.go b/tests/common/watch_test.go index 0893f4561..43b6dbcc3 100644 --- a/tests/common/watch_test.go +++ b/tests/common/watch_test.go @@ -13,7 +13,7 @@ import ( func TestWatch(t *testing.T) { testRunner.BeforeTest(t) watchTimeout := 1 * time.Second - for _, tc := range clusterTestCases { + for _, tc := range clusterTestCases() { t.Run(tc.name, func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) defer cancel() diff --git a/tests/e2e/cluster_downgrade_test.go b/tests/e2e/cluster_downgrade_test.go index 579c73cc9..3b84fb825 100644 --- a/tests/e2e/cluster_downgrade_test.go +++ b/tests/e2e/cluster_downgrade_test.go @@ -57,7 +57,7 @@ func testDowngradeUpgrade(t *testing.T, clusterSize int) { e2e.BeforeTest(t) t.Logf("Create cluster with version %s", currentVersionStr) - epc := newCluster(t, currentEtcdBinary, clusterSize) + epc := newCluster(t, clusterSize) for i := 0; i < len(epc.Procs); i++ { validateVersion(t, epc.Cfg, epc.Procs[i], version.Versions{ Cluster: currentVersionStr, @@ -119,9 +119,8 @@ func testDowngradeUpgrade(t *testing.T, clusterSize int) { t.Log("Upgrade complete") } -func newCluster(t *testing.T, execPath string, clusterSize int) *e2e.EtcdProcessCluster { +func newCluster(t *testing.T, clusterSize int) *e2e.EtcdProcessCluster { epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, &e2e.EtcdProcessClusterConfig{ - ExecPath: execPath, ClusterSize: clusterSize, InitialToken: "new", KeepDataDir: true, diff --git a/tests/e2e/ctl_v3_test.go b/tests/e2e/ctl_v3_test.go index 9f898245a..978ea741c 100644 --- a/tests/e2e/ctl_v3_test.go +++ b/tests/e2e/ctl_v3_test.go @@ -24,7 +24,6 @@ import ( "github.com/stretchr/testify/assert" "go.etcd.io/etcd/api/v3/version" - "go.etcd.io/etcd/client/pkg/v3/fileutil" "go.etcd.io/etcd/client/pkg/v3/testutil" "go.etcd.io/etcd/pkg/v3/flags" "go.etcd.io/etcd/tests/v3/framework/e2e" @@ -51,13 +50,8 @@ func TestClusterVersion(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - binary := e2e.BinPath.Etcd - if !fileutil.Exist(binary) { - t.Skipf("%q does not exist", binary) - } e2e.BeforeTest(t) cfg := e2e.NewConfigNoTLS() - cfg.ExecPath = binary cfg.SnapshotCount = 3 cfg.BaseScheme = "unix" // to avoid port conflict cfg.RollingStart = tt.rollingStart diff --git a/tests/e2e/discovery_test.go b/tests/e2e/discovery_test.go index 8bfa199e6..3fc2d2d97 100644 --- a/tests/e2e/discovery_test.go +++ b/tests/e2e/discovery_test.go @@ -27,6 +27,7 @@ import ( "go.etcd.io/etcd/client/pkg/v3/transport" "go.etcd.io/etcd/client/v2" "go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp" + "go.etcd.io/etcd/tests/v3/framework/config" "go.etcd.io/etcd/tests/v3/framework/e2e" "go.etcd.io/etcd/tests/v3/framework/integration" ) @@ -38,14 +39,13 @@ func TestTLSClusterOf3UsingDiscovery(t *testing.T) { testClusterUsingDiscovery(t func testClusterUsingDiscovery(t *testing.T, size int, peerTLS bool) { e2e.BeforeTest(t) - lastReleaseBinary := e2e.BinPath.EtcdLastRelease - if !fileutil.Exist(lastReleaseBinary) { - t.Skipf("%q does not exist", lastReleaseBinary) + if !fileutil.Exist(e2e.BinPath.EtcdLastRelease) { + t.Skipf("%q does not exist", e2e.BinPath.EtcdLastRelease) } dc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, &e2e.EtcdProcessClusterConfig{ BasePort: 2000, - ExecPath: lastReleaseBinary, + Version: config.LastVersion, ClusterSize: 1, EnableV2: true, }) diff --git a/tests/e2e/etcd_release_upgrade_test.go b/tests/e2e/etcd_release_upgrade_test.go index 1f65afd56..34a911704 100644 --- a/tests/e2e/etcd_release_upgrade_test.go +++ b/tests/e2e/etcd_release_upgrade_test.go @@ -23,21 +23,21 @@ import ( "go.etcd.io/etcd/api/v3/version" "go.etcd.io/etcd/client/pkg/v3/fileutil" + "go.etcd.io/etcd/tests/v3/framework/config" "go.etcd.io/etcd/tests/v3/framework/e2e" ) // TestReleaseUpgrade ensures that changes to master branch does not affect // upgrade from latest etcd releases. func TestReleaseUpgrade(t *testing.T) { - lastReleaseBinary := e2e.BinPath.EtcdLastRelease - if !fileutil.Exist(lastReleaseBinary) { - t.Skipf("%q does not exist", lastReleaseBinary) + if !fileutil.Exist(e2e.BinPath.EtcdLastRelease) { + t.Skipf("%q does not exist", e2e.BinPath.EtcdLastRelease) } e2e.BeforeTest(t) copiedCfg := e2e.NewConfigNoTLS() - copiedCfg.ExecPath = lastReleaseBinary + copiedCfg.Version = config.LastVersion copiedCfg.SnapshotCount = 3 copiedCfg.BaseScheme = "unix" // to avoid port conflict @@ -113,15 +113,14 @@ func TestReleaseUpgrade(t *testing.T) { } func TestReleaseUpgradeWithRestart(t *testing.T) { - lastReleaseBinary := e2e.BinPath.EtcdLastRelease - if !fileutil.Exist(lastReleaseBinary) { - t.Skipf("%q does not exist", lastReleaseBinary) + if !fileutil.Exist(e2e.BinPath.EtcdLastRelease) { + t.Skipf("%q does not exist", e2e.BinPath.EtcdLastRelease) } e2e.BeforeTest(t) copiedCfg := e2e.NewConfigNoTLS() - copiedCfg.ExecPath = lastReleaseBinary + copiedCfg.Version = config.LastVersion copiedCfg.SnapshotCount = 10 copiedCfg.BaseScheme = "unix" diff --git a/tests/e2e/utl_migrate_test.go b/tests/e2e/utl_migrate_test.go index a6236991c..b2903bfcf 100644 --- a/tests/e2e/utl_migrate_test.go +++ b/tests/e2e/utl_migrate_test.go @@ -27,6 +27,7 @@ import ( "go.etcd.io/etcd/client/pkg/v3/fileutil" "go.etcd.io/etcd/server/v3/storage/backend" "go.etcd.io/etcd/server/v3/storage/schema" + "go.etcd.io/etcd/tests/v3/framework/config" "go.etcd.io/etcd/tests/v3/framework/e2e" "go.uber.org/zap/zaptest" ) @@ -35,10 +36,10 @@ func TestEtctlutlMigrate(t *testing.T) { lastReleaseBinary := e2e.BinPath.EtcdLastRelease tcs := []struct { - name string - targetVersion string - binary string - force bool + name string + targetVersion string + clusterVersion config.ClusterVersion + force bool expectLogsSubString string expectStorageVersion *semver.Version @@ -69,13 +70,13 @@ func TestEtctlutlMigrate(t *testing.T) { }, { name: "Migrate v3.5 to v3.5 is no-op", - binary: lastReleaseBinary, + clusterVersion: config.LastVersion, targetVersion: "3.5", expectLogsSubString: "storage version up-to-date\t" + `{"storage-version": "3.5"}`, }, { name: "Upgrade v3.5 to v3.6 should work", - binary: lastReleaseBinary, + clusterVersion: config.LastVersion, targetVersion: "3.6", expectStorageVersion: &version.V3_6, }, @@ -109,13 +110,13 @@ func TestEtctlutlMigrate(t *testing.T) { t.Run(tc.name, func(t *testing.T) { e2e.BeforeTest(t) lg := zaptest.NewLogger(t) - if tc.binary != "" && !fileutil.Exist(tc.binary) { + if tc.clusterVersion != config.CurrentVersion && !fileutil.Exist(e2e.BinPath.EtcdLastRelease) { t.Skipf("%q does not exist", lastReleaseBinary) } dataDirPath := t.TempDir() epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, &e2e.EtcdProcessClusterConfig{ - ExecPath: tc.binary, + Version: tc.clusterVersion, DataDirPath: dataDirPath, ClusterSize: 1, InitialToken: "new", diff --git a/tests/e2e/v2store_deprecation_test.go b/tests/e2e/v2store_deprecation_test.go index 13d329937..3a45a96f8 100644 --- a/tests/e2e/v2store_deprecation_test.go +++ b/tests/e2e/v2store_deprecation_test.go @@ -32,10 +32,10 @@ import ( "go.uber.org/zap/zaptest" ) -func createV2store(t testing.TB, lastReleaseBinary string, dataDirPath string) { +func createV2store(t testing.TB, dataDirPath string) { t.Log("Creating not-yet v2-deprecated etcd") - cfg := e2e.ConfigStandalone(e2e.EtcdProcessClusterConfig{ExecPath: lastReleaseBinary, EnableV2: true, DataDirPath: dataDirPath, SnapshotCount: 5}) + cfg := e2e.ConfigStandalone(e2e.EtcdProcessClusterConfig{Version: config.LastVersion, EnableV2: true, DataDirPath: dataDirPath, SnapshotCount: 5}) epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, cfg) assert.NoError(t, err) @@ -75,13 +75,12 @@ func TestV2DeprecationFlags(t *testing.T) { e2e.BeforeTest(t) dataDirPath := t.TempDir() - lastReleaseBinary := e2e.BinPath.EtcdLastRelease - if !fileutil.Exist(lastReleaseBinary) { - t.Skipf("%q does not exist", lastReleaseBinary) + if !fileutil.Exist(e2e.BinPath.EtcdLastRelease) { + t.Skipf("%q does not exist", e2e.BinPath.EtcdLastRelease) } t.Run("create-storev2-data", func(t *testing.T) { - createV2store(t, lastReleaseBinary, dataDirPath) + createV2store(t, dataDirPath) }) t.Run("--v2-deprecation=not-yet fails", func(t *testing.T) { @@ -101,19 +100,16 @@ func TestV2DeprecationSnapshotMatches(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - lastReleaseBinary := e2e.BinPath.EtcdLastRelease - currentReleaseBinary := e2e.BinPath.Etcd - - if !fileutil.Exist(lastReleaseBinary) { - t.Skipf("%q does not exist", lastReleaseBinary) + if !fileutil.Exist(e2e.BinPath.EtcdLastRelease) { + t.Skipf("%q does not exist", e2e.BinPath.EtcdLastRelease) } snapshotCount := 10 - epc := runEtcdAndCreateSnapshot(t, lastReleaseBinary, lastReleaseData, snapshotCount) + epc := runEtcdAndCreateSnapshot(t, config.LastVersion, lastReleaseData, snapshotCount) cc1, err := e2e.NewEtcdctl(epc.Cfg, epc.EndpointsV3()) assert.NoError(t, err) members1 := addAndRemoveKeysAndMembers(ctx, t, cc1, snapshotCount) assert.NoError(t, epc.Close()) - epc = runEtcdAndCreateSnapshot(t, currentReleaseBinary, currentReleaseData, snapshotCount) + epc = runEtcdAndCreateSnapshot(t, config.CurrentVersion, currentReleaseData, snapshotCount) cc2, err := e2e.NewEtcdctl(epc.Cfg, epc.EndpointsV3()) assert.NoError(t, err) members2 := addAndRemoveKeysAndMembers(ctx, t, cc2, snapshotCount) @@ -140,13 +136,10 @@ func TestV2DeprecationSnapshotRecover(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - lastReleaseBinary := e2e.BinPath.EtcdLastRelease - currentReleaseBinary := e2e.BinPath.Etcd - - if !fileutil.Exist(lastReleaseBinary) { - t.Skipf("%q does not exist", lastReleaseBinary) + if !fileutil.Exist(e2e.BinPath.EtcdLastRelease) { + t.Skipf("%q does not exist", e2e.BinPath.EtcdLastRelease) } - epc := runEtcdAndCreateSnapshot(t, lastReleaseBinary, dataDir, 10) + epc := runEtcdAndCreateSnapshot(t, config.LastVersion, dataDir, 10) cc, err := e2e.NewEtcdctl(epc.Cfg, epc.EndpointsV3()) assert.NoError(t, err) @@ -158,7 +151,7 @@ func TestV2DeprecationSnapshotRecover(t *testing.T) { assert.NoError(t, err) assert.NoError(t, epc.Close()) - cfg := e2e.ConfigStandalone(e2e.EtcdProcessClusterConfig{ExecPath: currentReleaseBinary, DataDirPath: dataDir}) + cfg := e2e.ConfigStandalone(e2e.EtcdProcessClusterConfig{Version: config.CurrentVersion, DataDirPath: dataDir}) epc, err = e2e.NewEtcdProcessCluster(context.TODO(), t, cfg) assert.NoError(t, err) @@ -175,8 +168,8 @@ func TestV2DeprecationSnapshotRecover(t *testing.T) { assert.NoError(t, epc.Close()) } -func runEtcdAndCreateSnapshot(t testing.TB, binary, dataDir string, snapshotCount int) *e2e.EtcdProcessCluster { - cfg := e2e.ConfigStandalone(e2e.EtcdProcessClusterConfig{ExecPath: binary, DataDirPath: dataDir, SnapshotCount: snapshotCount, KeepDataDir: true}) +func runEtcdAndCreateSnapshot(t testing.TB, serverVersion config.ClusterVersion, dataDir string, snapshotCount int) *e2e.EtcdProcessCluster { + cfg := e2e.ConfigStandalone(e2e.EtcdProcessClusterConfig{Version: serverVersion, DataDirPath: dataDir, SnapshotCount: snapshotCount, KeepDataDir: true}) epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, cfg) assert.NoError(t, err) return epc diff --git a/tests/framework/config/cluster.go b/tests/framework/config/cluster.go index 013eac6cd..a494c3842 100644 --- a/tests/framework/config/cluster.go +++ b/tests/framework/config/cluster.go @@ -14,15 +14,23 @@ package config -import "time" +import ( + "time" +) type TLSConfig string +type ClusterVersion string const ( NoTLS TLSConfig = "" AutoTLS TLSConfig = "auto-tls" ManualTLS TLSConfig = "manual-tls" + CurrentVersion ClusterVersion = "" + MinorityLastVersion ClusterVersion = "minority-last-version" + QuorumLastVersion ClusterVersion = "quorum-last-version" + LastVersion ClusterVersion = "last-version" + TickDuration = 10 * time.Millisecond ) @@ -34,6 +42,12 @@ type ClusterConfig struct { StrictReconfigCheck bool AuthToken string SnapshotCount int + + E2eConfig *E2eClusterConfig +} + +type E2eClusterConfig struct { + Version ClusterVersion } func DefaultClusterConfig() ClusterConfig { diff --git a/tests/framework/e2e/cluster.go b/tests/framework/e2e/cluster.go index d7d30c286..e49d7f560 100644 --- a/tests/framework/e2e/cluster.go +++ b/tests/framework/e2e/cluster.go @@ -138,7 +138,7 @@ type EtcdProcessCluster struct { type EtcdProcessClusterConfig struct { Logger *zap.Logger - ExecPath string + Version config.ClusterVersion DataDirPath string KeepDataDir bool EnvVars map[string]string @@ -208,9 +208,6 @@ func InitEtcdProcessCluster(t testing.TB, cfg *EtcdProcessClusterConfig) (*EtcdP if cfg.BasePort == 0 { cfg.BasePort = EtcdProcessBasePort } - if cfg.ExecPath == "" { - cfg.ExecPath = BinPath.Etcd - } if cfg.SnapshotCount == 0 { cfg.SnapshotCount = etcdserver.DefaultSnapshotCount } @@ -400,9 +397,31 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in envVars["GOFAIL_HTTP"] = fmt.Sprintf("127.0.0.1:%d", gofailPort) } + var execPath string + switch cfg.Version { + case config.CurrentVersion: + execPath = BinPath.Etcd + case config.MinorityLastVersion: + if i <= cfg.ClusterSize/2 { + execPath = BinPath.Etcd + } else { + execPath = BinPath.EtcdLastRelease + } + case config.QuorumLastVersion: + if i <= cfg.ClusterSize/2 { + execPath = BinPath.EtcdLastRelease + } else { + execPath = BinPath.Etcd + } + case config.LastVersion: + execPath = BinPath.EtcdLastRelease + default: + panic(fmt.Sprintf("Unknown cluster version %v", cfg.Version)) + } + return &EtcdServerProcessConfig{ lg: cfg.Logger, - ExecPath: cfg.ExecPath, + ExecPath: execPath, Args: args, EnvVars: envVars, TlsArgs: cfg.TlsArgs(), diff --git a/tests/framework/e2e/e2e.go b/tests/framework/e2e/e2e.go index 5704b74d1..87e5f5235 100644 --- a/tests/framework/e2e/e2e.go +++ b/tests/framework/e2e/e2e.go @@ -56,6 +56,9 @@ func (e e2eRunner) NewCluster(ctx context.Context, t testing.TB, opts ...config. AuthTokenOpts: cfg.AuthToken, SnapshotCount: cfg.SnapshotCount, } + if cfg.E2eConfig != nil { + e2eConfig.Version = cfg.E2eConfig.Version + } switch cfg.ClientTLS { case config.NoTLS: e2eConfig.ClientTLS = ClientNonTLS diff --git a/tests/framework/integration/integration.go b/tests/framework/integration/integration.go index df9db28b8..ff546939d 100644 --- a/tests/framework/integration/integration.go +++ b/tests/framework/integration/integration.go @@ -50,6 +50,9 @@ func (e integrationRunner) BeforeTest(t testing.TB) { func (e integrationRunner) NewCluster(ctx context.Context, t testing.TB, opts ...config.ClusterOption) intf.Cluster { var err error cfg := config.NewClusterConfig(opts...) + if cfg.E2eConfig != nil { + t.Fatalf("E2e configuration not expected during integration tests, config: %+v", cfg) + } integrationCfg := ClusterConfig{ Size: cfg.ClusterSize, QuotaBackendBytes: cfg.QuotaBackendBytes,