From a53074542bdd62e139fc2c268e17c77caf16ef45 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Wed, 19 Jan 2022 15:52:36 +0100 Subject: [PATCH] test: Run v2 discovery tests on previous version binary --- tests/e2e/discovery_test.go | 78 ++++++++++++++++++++++++++ tests/framework/e2e/cluster.go | 16 ++++-- tests/framework/integration/cluster.go | 2 +- tests/integration/cluster_test.go | 43 -------------- 4 files changed, 91 insertions(+), 48 deletions(-) create mode 100644 tests/e2e/discovery_test.go diff --git a/tests/e2e/discovery_test.go b/tests/e2e/discovery_test.go new file mode 100644 index 000000000..6f6a5e150 --- /dev/null +++ b/tests/e2e/discovery_test.go @@ -0,0 +1,78 @@ +// Copyright 2022 The etcd Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package e2e + +import ( + "context" + "fmt" + "strings" + "testing" + + "go.etcd.io/etcd/client/pkg/v3/fileutil" + "go.etcd.io/etcd/client/v2" + "go.etcd.io/etcd/tests/v3/framework/e2e" + "go.etcd.io/etcd/tests/v3/framework/integration" +) + +func TestClusterOf1UsingDiscovery(t *testing.T) { testClusterUsingDiscovery(t, 1, false) } +func TestClusterOf3UsingDiscovery(t *testing.T) { testClusterUsingDiscovery(t, 3, false) } +func TestTLSClusterOf3UsingDiscovery(t *testing.T) { testClusterUsingDiscovery(t, 3, true) } + +func testClusterUsingDiscovery(t *testing.T, size int, peerTLS bool) { + e2e.BeforeTest(t) + + lastReleaseBinary := e2e.BinDir + "/etcd-last-release" + if !fileutil.Exist(lastReleaseBinary) { + t.Skipf("%q does not exist", lastReleaseBinary) + } + + dc, err := e2e.NewEtcdProcessCluster(t, &e2e.EtcdProcessClusterConfig{ + BasePort: 2000, + ExecPath: lastReleaseBinary, + ClusterSize: 1, + EnableV2: true, + }) + if err != nil { + t.Fatalf("could not start etcd process cluster (%v)", err) + } + defer dc.Close() + + dcc := integration.MustNewHTTPClient(t, dc.EndpointsV2(), nil) + dkapi := client.NewKeysAPI(dcc) + ctx, cancel := context.WithTimeout(context.Background(), integration.RequestTimeout) + if _, err := dkapi.Create(ctx, "/_config/size", fmt.Sprintf("%d", size)); err != nil { + t.Fatal(err) + } + cancel() + + c, err := e2e.NewEtcdProcessCluster(t, &e2e.EtcdProcessClusterConfig{ + BasePort: 3000, + ClusterSize: size, + IsPeerTLS: peerTLS, + Discovery: dc.EndpointsV2()[0] + "/v2/keys", + }) + if err != nil { + t.Fatalf("could not start etcd process cluster (%v)", err) + } + defer c.Close() + + kubectl := []string{e2e.CtlBinPath, "--endpoints", strings.Join(c.EndpointsV3(), ",")} + if err := e2e.SpawnWithExpect(append(kubectl, "put", "key", "value"), "OK"); err != nil { + t.Fatal(err) + } + if err := e2e.SpawnWithExpect(append(kubectl, "get", "key"), "value"); err != nil { + t.Fatal(err) + } +} diff --git a/tests/framework/e2e/cluster.go b/tests/framework/e2e/cluster.go index 445c84de9..4a7c9798b 100644 --- a/tests/framework/e2e/cluster.go +++ b/tests/framework/e2e/cluster.go @@ -170,6 +170,7 @@ type EtcdProcessClusterConfig struct { V2deprecation string RollingStart bool + Discovery string } // NewEtcdProcessCluster launches a new cluster from etcd processes, returning @@ -273,6 +274,7 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfigs(tb testing.TB) []* "--data-dir", dataDirPath, "--snapshot-count", fmt.Sprintf("%d", cfg.SnapshotCount), } + if cfg.ForceNewCluster { args = append(args, "--force-new-cluster") } @@ -309,6 +311,10 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfigs(tb testing.TB) []* args = append(args, "--v2-deprecation", cfg.V2deprecation) } + if cfg.Discovery != "" { + args = append(args, "--discovery", cfg.Discovery) + } + etcdCfgs[i] = &EtcdServerProcessConfig{ lg: lg, ExecPath: cfg.ExecPath, @@ -325,10 +331,12 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfigs(tb testing.TB) []* } } - initialClusterArgs := []string{"--initial-cluster", strings.Join(initialCluster, ",")} - for i := range etcdCfgs { - etcdCfgs[i].InitialCluster = strings.Join(initialCluster, ",") - etcdCfgs[i].Args = append(etcdCfgs[i].Args, initialClusterArgs...) + if cfg.Discovery == "" { + for i := range etcdCfgs { + initialClusterArgs := []string{"--initial-cluster", strings.Join(initialCluster, ",")} + etcdCfgs[i].InitialCluster = strings.Join(initialCluster, ",") + etcdCfgs[i].Args = append(etcdCfgs[i].Args, initialClusterArgs...) + } } return etcdCfgs diff --git a/tests/framework/integration/cluster.go b/tests/framework/integration/cluster.go index 323398c7b..f7fc08677 100644 --- a/tests/framework/integration/cluster.go +++ b/tests/framework/integration/cluster.go @@ -552,7 +552,7 @@ type Member struct { // ServerClient is a clientv3 that directly calls the etcdserver. ServerClient *clientv3.Client // Client is a clientv3 that communicates via socket, either UNIX or TCP. - Client *clientv3.Client + Client *clientv3.Client KeepDataDirTerminate bool ClientMaxCallSendMsgSize int diff --git a/tests/integration/cluster_test.go b/tests/integration/cluster_test.go index 9cd65b40b..8db6f30d5 100644 --- a/tests/integration/cluster_test.go +++ b/tests/integration/cluster_test.go @@ -67,49 +67,6 @@ func TestTLSClusterOf3WithSpecificUsage(t *testing.T) { clusterMustProgress(t, c.Members) } -func TestClusterOf1UsingDiscovery(t *testing.T) { testClusterUsingDiscovery(t, 1) } -func TestClusterOf3UsingDiscovery(t *testing.T) { testClusterUsingDiscovery(t, 3) } - -func testClusterUsingDiscovery(t *testing.T, size int) { - integration.BeforeTest(t) - dc := integration.NewCluster(t, &integration.ClusterConfig{Size: 1, UseIP: true}) - defer dc.Terminate(t) - // init discovery token space - dcc := integration.MustNewHTTPClient(t, dc.URLs(), nil) - dkapi := client.NewKeysAPI(dcc) - ctx, cancel := context.WithTimeout(context.Background(), integration.RequestTimeout) - if _, err := dkapi.Create(ctx, "/_config/size", fmt.Sprintf("%d", size)); err != nil { - t.Fatal(err) - } - cancel() - - c := integration.NewCluster(t, &integration.ClusterConfig{Size: size, DiscoveryURL: dc.URL(0) + "/v2/keys"}) - defer c.Terminate(t) - clusterMustProgress(t, c.Members) -} - -func TestTLSClusterOf3UsingDiscovery(t *testing.T) { - integration.BeforeTest(t) - dc := integration.NewCluster(t, &integration.ClusterConfig{Size: 1, UseIP: true}) - defer dc.Terminate(t) - // init discovery token space - dcc := integration.MustNewHTTPClient(t, dc.URLs(), nil) - dkapi := client.NewKeysAPI(dcc) - ctx, cancel := context.WithTimeout(context.Background(), integration.RequestTimeout) - if _, err := dkapi.Create(ctx, "/_config/size", fmt.Sprintf("%d", 3)); err != nil { - t.Fatal(err) - } - cancel() - - c := integration.NewCluster(t, &integration.ClusterConfig{ - Size: 3, - PeerTLS: &integration.TestTLSInfo, - DiscoveryURL: dc.URL(0) + "/v2/keys"}, - ) - defer c.Terminate(t) - clusterMustProgress(t, c.Members) -} - func TestDoubleClusterSizeOf1(t *testing.T) { testDoubleClusterSize(t, 1) } func TestDoubleClusterSizeOf3(t *testing.T) { testDoubleClusterSize(t, 3) }