From de0efc9aa4cb5a5bbb55d0c251dd04b731c9de04 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Mon, 17 Oct 2022 12:12:31 +0200 Subject: [PATCH 1/7] tests: Move global e2e configuration into one file Signed-off-by: Marek Siarkowicz --- tests/framework/e2e/etcd_process.go | 3 --- tests/framework/e2e/flags.go | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/framework/e2e/etcd_process.go b/tests/framework/e2e/etcd_process.go index f4c85990714..b355669c01a 100644 --- a/tests/framework/e2e/etcd_process.go +++ b/tests/framework/e2e/etcd_process.go @@ -30,9 +30,6 @@ import ( var ( EtcdServerReadyLines = []string{"ready to serve client requests"} - BinPath string - CtlBinPath string - UtlBinPath string ) // EtcdProcess is a process that serves etcd requests. diff --git a/tests/framework/e2e/flags.go b/tests/framework/e2e/flags.go index a8607830c8b..85d7e858abc 100644 --- a/tests/framework/e2e/flags.go +++ b/tests/framework/e2e/flags.go @@ -40,6 +40,10 @@ var ( RevokedCertPath string RevokedPrivateKeyPath string + BinPath string + CtlBinPath string + UtlBinPath string + FixturesDir = testutils.MustAbsPath("../fixtures") ) From d3b9951126fd7a3c5aa1c688c5b8d24e47eb097d Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Mon, 17 Oct 2022 12:48:49 +0200 Subject: [PATCH 2/7] tests: Refactor BinPath into struct Signed-off-by: Marek Siarkowicz --- tests/e2e/ctl_v3_completion_test.go | 4 ++-- tests/e2e/ctl_v3_snapshot_test.go | 6 +++--- tests/e2e/ctl_v3_test.go | 4 ++-- tests/e2e/discovery_test.go | 2 +- tests/e2e/discovery_v3_test.go | 2 +- tests/e2e/gateway_test.go | 4 ++-- tests/e2e/utl_migrate_test.go | 4 ++-- tests/framework/e2e/cluster.go | 2 +- tests/framework/e2e/etcd_spawn.go | 8 ++++++++ tests/framework/e2e/etcdctl.go | 2 +- tests/framework/e2e/flags.go | 15 ++++++++------- 11 files changed, 31 insertions(+), 22 deletions(-) diff --git a/tests/e2e/ctl_v3_completion_test.go b/tests/e2e/ctl_v3_completion_test.go index 88c030d1ac2..ccadb4a8903 100644 --- a/tests/e2e/ctl_v3_completion_test.go +++ b/tests/e2e/ctl_v3_completion_test.go @@ -25,9 +25,9 @@ import ( "go.etcd.io/etcd/tests/v3/framework/e2e" ) -func TestCtlV3CompletionBash(t *testing.T) { testShellCompletion(t, e2e.CtlBinPath, "bash") } +func TestCtlV3CompletionBash(t *testing.T) { testShellCompletion(t, e2e.BinPath.Etcdctl, "bash") } -func TestUtlV3CompletionBash(t *testing.T) { testShellCompletion(t, e2e.UtlBinPath, "bash") } +func TestUtlV3CompletionBash(t *testing.T) { testShellCompletion(t, e2e.BinPath.Etcdutl, "bash") } func testShellCompletion(t *testing.T, binPath, shellName string) { e2e.BeforeTest(t) diff --git a/tests/e2e/ctl_v3_snapshot_test.go b/tests/e2e/ctl_v3_snapshot_test.go index 9047f64acf0..ff7b6e51edf 100644 --- a/tests/e2e/ctl_v3_snapshot_test.go +++ b/tests/e2e/ctl_v3_snapshot_test.go @@ -187,7 +187,7 @@ func testIssue6361(t *testing.T) { }() dialTimeout := 10 * time.Second - prefixArgs := []string{e2e.CtlBinPath, "--endpoints", strings.Join(epc.EndpointsV3(), ","), "--dial-timeout", dialTimeout.String()} + prefixArgs := []string{e2e.BinPath.Etcdctl, "--endpoints", strings.Join(epc.EndpointsV3(), ","), "--dial-timeout", dialTimeout.String()} t.Log("Writing some keys...") kvs := []kv{{"foo1", "val1"}, {"foo2", "val2"}, {"foo3", "val3"}} @@ -214,7 +214,7 @@ func testIssue6361(t *testing.T) { newDataDir := filepath.Join(t.TempDir(), "test.data") t.Log("etcdctl restoring the snapshot...") - err = e2e.SpawnWithExpect([]string{e2e.UtlBinPath, "snapshot", "restore", fpath, "--name", epc.Procs[0].Config().Name, "--initial-cluster", epc.Procs[0].Config().InitialCluster, "--initial-cluster-token", epc.Procs[0].Config().InitialToken, "--initial-advertise-peer-urls", epc.Procs[0].Config().Purl.String(), "--data-dir", newDataDir}, "added member") + err = e2e.SpawnWithExpect([]string{e2e.BinPath.Etcdutl, "snapshot", "restore", fpath, "--name", epc.Procs[0].Config().Name, "--initial-cluster", epc.Procs[0].Config().InitialCluster, "--initial-cluster-token", epc.Procs[0].Config().InitialToken, "--initial-advertise-peer-urls", epc.Procs[0].Config().Purl.String(), "--data-dir", newDataDir}, "added member") if err != nil { t.Fatal(err) } @@ -265,7 +265,7 @@ func testIssue6361(t *testing.T) { t.Fatal(err) } - prefixArgs = []string{e2e.CtlBinPath, "--endpoints", clientURL, "--dial-timeout", dialTimeout.String()} + prefixArgs = []string{e2e.BinPath.Etcdctl, "--endpoints", clientURL, "--dial-timeout", dialTimeout.String()} t.Log("Ensuring added member has data from incoming snapshot...") for i := range kvs { diff --git a/tests/e2e/ctl_v3_test.go b/tests/e2e/ctl_v3_test.go index 261aec66aea..a6118b06934 100644 --- a/tests/e2e/ctl_v3_test.go +++ b/tests/e2e/ctl_v3_test.go @@ -320,7 +320,7 @@ func (cx *ctlCtx) prefixArgs(eps []string) []string { useEnv := cx.envMap != nil - cmdArgs := []string{e2e.CtlBinPath} + cmdArgs := []string{e2e.BinPath.Etcdctl} for k, v := range fmap { if useEnv { ek := flags.FlagToEnv("ETCDCTL", k) @@ -341,7 +341,7 @@ func (cx *ctlCtx) PrefixArgs() []string { // PrefixArgsUtl returns prefix of the command that is etcdutl // Please not thet 'utl' compatible commands does not consume --endpoints flag. func (cx *ctlCtx) PrefixArgsUtl() []string { - return []string{e2e.UtlBinPath} + return []string{e2e.BinPath.Etcdutl} } func isGRPCTimedout(err error) bool { diff --git a/tests/e2e/discovery_test.go b/tests/e2e/discovery_test.go index b4c55f23cac..001fd96c394 100644 --- a/tests/e2e/discovery_test.go +++ b/tests/e2e/discovery_test.go @@ -73,7 +73,7 @@ func testClusterUsingDiscovery(t *testing.T, size int, peerTLS bool) { } defer c.Close() - kubectl := []string{e2e.CtlBinPath, "--endpoints", strings.Join(c.EndpointsV3(), ",")} + kubectl := []string{e2e.BinPath.Etcdctl, "--endpoints", strings.Join(c.EndpointsV3(), ",")} if err := e2e.SpawnWithExpect(append(kubectl, "put", "key", "value"), "OK"); err != nil { t.Fatal(err) } diff --git a/tests/e2e/discovery_v3_test.go b/tests/e2e/discovery_v3_test.go index 3cf75f63306..5b592f050e2 100644 --- a/tests/e2e/discovery_v3_test.go +++ b/tests/e2e/discovery_v3_test.go @@ -76,7 +76,7 @@ func testClusterUsingV3Discovery(t *testing.T, discoveryClusterSize, targetClust defer epc.Close() // step 4: sanity test on the etcd cluster - etcdctl := []string{e2e.CtlBinPath, "--endpoints", strings.Join(epc.EndpointsV3(), ",")} + etcdctl := []string{e2e.BinPath.Etcdctl, "--endpoints", strings.Join(epc.EndpointsV3(), ",")} if err := e2e.SpawnWithExpect(append(etcdctl, "put", "key", "value"), "OK"); err != nil { t.Fatal(err) } diff --git a/tests/e2e/gateway_test.go b/tests/e2e/gateway_test.go index ebd179e746a..2e2cc360be7 100644 --- a/tests/e2e/gateway_test.go +++ b/tests/e2e/gateway_test.go @@ -39,14 +39,14 @@ func TestGateway(t *testing.T) { p := startGateway(t, eps) defer p.Stop() - err = e2e.SpawnWithExpect([]string{e2e.CtlBinPath, "--endpoints=" + defaultGatewayEndpoint, "put", "foo", "bar"}, "OK\r\n") + err = e2e.SpawnWithExpect([]string{e2e.BinPath.Etcdctl, "--endpoints=" + defaultGatewayEndpoint, "put", "foo", "bar"}, "OK\r\n") if err != nil { t.Errorf("failed to finish put request through gateway: %v", err) } } func startGateway(t *testing.T, endpoints string) *expect.ExpectProcess { - p, err := expect.NewExpect(e2e.BinPath, "gateway", "--endpoints="+endpoints, "start") + p, err := expect.NewExpect(e2e.BinPath.Etcd, "gateway", "--endpoints="+endpoints, "start") if err != nil { t.Fatal(err) } diff --git a/tests/e2e/utl_migrate_test.go b/tests/e2e/utl_migrate_test.go index 3d1d3a10766..20f6e3f53d0 100644 --- a/tests/e2e/utl_migrate_test.go +++ b/tests/e2e/utl_migrate_test.go @@ -133,7 +133,7 @@ func TestEtctlutlMigrate(t *testing.T) { }() dialTimeout := 10 * time.Second - prefixArgs := []string{e2e.CtlBinPath, "--endpoints", strings.Join(epc.EndpointsV3(), ","), "--dial-timeout", dialTimeout.String()} + prefixArgs := []string{e2e.BinPath.Etcdctl, "--endpoints", strings.Join(epc.EndpointsV3(), ","), "--dial-timeout", dialTimeout.String()} t.Log("Write keys to ensure wal snapshot is created and all v3.5 fields are set...") for i := 0; i < 10; i++ { @@ -148,7 +148,7 @@ func TestEtctlutlMigrate(t *testing.T) { } t.Log("etcdutl migrate...") - args := []string{e2e.UtlBinPath, "migrate", "--data-dir", dataDirPath, "--target-version", tc.targetVersion} + args := []string{e2e.BinPath.Etcdutl, "migrate", "--data-dir", dataDirPath, "--target-version", tc.targetVersion} if tc.force { args = append(args, "--force") } diff --git a/tests/framework/e2e/cluster.go b/tests/framework/e2e/cluster.go index 074c318edba..5096df714f5 100644 --- a/tests/framework/e2e/cluster.go +++ b/tests/framework/e2e/cluster.go @@ -207,7 +207,7 @@ func InitEtcdProcessCluster(t testing.TB, cfg *EtcdProcessClusterConfig) (*EtcdP cfg.BasePort = EtcdProcessBasePort } if cfg.ExecPath == "" { - cfg.ExecPath = BinPath + cfg.ExecPath = BinPath.Etcd } if cfg.SnapshotCount == 0 { cfg.SnapshotCount = etcdserver.DefaultSnapshotCount diff --git a/tests/framework/e2e/etcd_spawn.go b/tests/framework/e2e/etcd_spawn.go index ab86df150a2..02e8b3cf125 100644 --- a/tests/framework/e2e/etcd_spawn.go +++ b/tests/framework/e2e/etcd_spawn.go @@ -29,3 +29,11 @@ func SpawnCmd(args []string, envVars map[string]string) (*expect.ExpectProcess, func SpawnNamedCmd(processName string, args []string, envVars map[string]string) (*expect.ExpectProcess, error) { return SpawnCmdWithLogger(zap.NewNop(), args, envVars, processName) } + +func initBinPath(binDir string) binPath { + return binPath{ + Etcd: binDir + "/etcd", + Etcdctl: binDir + "/etcdctl", + Etcdutl: binDir + "/etcdutl", + } +} diff --git a/tests/framework/e2e/etcdctl.go b/tests/framework/e2e/etcdctl.go index 024bd9d74fe..070c84e2e44 100644 --- a/tests/framework/e2e/etcdctl.go +++ b/tests/framework/e2e/etcdctl.go @@ -268,7 +268,7 @@ func (ctl *EtcdctlV3) MemberRemove(ctx context.Context, id uint64) (*clientv3.Me } func (ctl *EtcdctlV3) cmdArgs(args ...string) []string { - cmdArgs := []string{CtlBinPath} + cmdArgs := []string{BinPath.Etcdctl} for k, v := range ctl.flags() { cmdArgs = append(cmdArgs, fmt.Sprintf("--%s=%s", k, v)) } diff --git a/tests/framework/e2e/flags.go b/tests/framework/e2e/flags.go index 85d7e858abc..2b1e5dca3ca 100644 --- a/tests/framework/e2e/flags.go +++ b/tests/framework/e2e/flags.go @@ -40,13 +40,16 @@ var ( RevokedCertPath string RevokedPrivateKeyPath string - BinPath string - CtlBinPath string - UtlBinPath string - + BinPath binPath FixturesDir = testutils.MustAbsPath("../fixtures") ) +type binPath struct { + Etcd string + Etcdctl string + Etcdutl string +} + func InitFlags() { os.Setenv("ETCD_UNSUPPORTED_ARCH", runtime.GOARCH) @@ -57,9 +60,7 @@ func InitFlags() { flag.StringVar(&CertDir, "cert-dir", certDirDef, "The directory for store certificate files.") flag.Parse() - BinPath = BinDir + "/etcd" - CtlBinPath = BinDir + "/etcdctl" - UtlBinPath = BinDir + "/etcdutl" + BinPath = initBinPath(BinDir) CertPath = CertDir + "/server.crt" PrivateKeyPath = CertDir + "/server.key.insecure" CaPath = CertDir + "/ca.crt" From 89a1e7978ceb7ed5a00ece603e1c69c1ee2cbfb6 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Mon, 17 Oct 2022 12:40:26 +0200 Subject: [PATCH 3/7] tests: Configure coverage binary paths via init Signed-off-by: Marek Siarkowicz --- tests/e2e/ctl_v3_completion_test.go | 8 ++++++-- tests/framework/e2e/etcd_spawn.go | 12 ++++-------- tests/framework/e2e/etcd_spawn_cov.go | 21 ++++++++++++--------- tests/framework/e2e/etcd_spawn_nocov.go | 15 ++++++++++++++- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/tests/e2e/ctl_v3_completion_test.go b/tests/e2e/ctl_v3_completion_test.go index ccadb4a8903..b91edcde821 100644 --- a/tests/e2e/ctl_v3_completion_test.go +++ b/tests/e2e/ctl_v3_completion_test.go @@ -25,9 +25,13 @@ import ( "go.etcd.io/etcd/tests/v3/framework/e2e" ) -func TestCtlV3CompletionBash(t *testing.T) { testShellCompletion(t, e2e.BinPath.Etcdctl, "bash") } +func TestCtlV3CompletionBash(t *testing.T) { + testShellCompletion(t, e2e.BinPath.Etcdctl, "bash") +} -func TestUtlV3CompletionBash(t *testing.T) { testShellCompletion(t, e2e.BinPath.Etcdutl, "bash") } +func TestUtlV3CompletionBash(t *testing.T) { + testShellCompletion(t, e2e.BinPath.Etcdutl, "bash") +} func testShellCompletion(t *testing.T, binPath, shellName string) { e2e.BeforeTest(t) diff --git a/tests/framework/e2e/etcd_spawn.go b/tests/framework/e2e/etcd_spawn.go index 02e8b3cf125..5f76f186886 100644 --- a/tests/framework/e2e/etcd_spawn.go +++ b/tests/framework/e2e/etcd_spawn.go @@ -22,6 +22,10 @@ import ( "go.etcd.io/etcd/pkg/v3/expect" ) +var ( + initBinPath func(string) binPath +) + func SpawnCmd(args []string, envVars map[string]string) (*expect.ExpectProcess, error) { return SpawnNamedCmd(strings.Join(args, "_"), args, envVars) } @@ -29,11 +33,3 @@ func SpawnCmd(args []string, envVars map[string]string) (*expect.ExpectProcess, func SpawnNamedCmd(processName string, args []string, envVars map[string]string) (*expect.ExpectProcess, error) { return SpawnCmdWithLogger(zap.NewNop(), args, envVars, processName) } - -func initBinPath(binDir string) binPath { - return binPath{ - Etcd: binDir + "/etcd", - Etcdctl: binDir + "/etcdctl", - Etcdutl: binDir + "/etcdutl", - } -} diff --git a/tests/framework/e2e/etcd_spawn_cov.go b/tests/framework/e2e/etcd_spawn_cov.go index 97102f08ffd..fba1c37fe3a 100644 --- a/tests/framework/e2e/etcd_spawn_cov.go +++ b/tests/framework/e2e/etcd_spawn_cov.go @@ -20,7 +20,6 @@ package e2e import ( "fmt" "os" - "strings" "time" "go.etcd.io/etcd/client/pkg/v3/fileutil" @@ -35,17 +34,21 @@ var ( coverDir = testutils.MustAbsPath(os.Getenv("COVERDIR")) ) +func init() { + initBinPath = initBinPathCov +} + +func initBinPathCov(binDir string) binPath { + return binPath{ + Etcd: binDir + "/etcd_test", + Etcdctl: binDir + "/etcdctl_test", + Etcdutl: binDir + "/etcdutl_test", + } +} + func SpawnCmdWithLogger(lg *zap.Logger, args []string, envVars map[string]string, name string) (*expect.ExpectProcess, error) { cmd := args[0] env := mergeEnvVariables(envVars) - switch { - case strings.HasSuffix(cmd, "/etcd"): - cmd = cmd + "_test" - case strings.HasSuffix(cmd, "/etcdctl"): - cmd = cmd + "_test" - case strings.HasSuffix(cmd, "/etcdutl"): - cmd = cmd + "_test" - } wd, err := os.Getwd() if err != nil { diff --git a/tests/framework/e2e/etcd_spawn_nocov.go b/tests/framework/e2e/etcd_spawn_nocov.go index 46748ede1e2..a02df0d6c05 100644 --- a/tests/framework/e2e/etcd_spawn_nocov.go +++ b/tests/framework/e2e/etcd_spawn_nocov.go @@ -18,14 +18,27 @@ package e2e import ( - "go.uber.org/zap" "os" + "go.uber.org/zap" + "go.etcd.io/etcd/pkg/v3/expect" ) const noOutputLineCount = 0 // regular binaries emit no extra lines +func init() { + initBinPath = initBinPathNoCov +} + +func initBinPathNoCov(binDir string) binPath { + return binPath{ + Etcd: binDir + "/etcd", + Etcdctl: binDir + "/etcdctl", + Etcdutl: binDir + "/etcdutl", + } +} + func SpawnCmdWithLogger(lg *zap.Logger, args []string, envVars map[string]string, name string) (*expect.ExpectProcess, error) { wd, err := os.Getwd() if err != nil { From 0f9e15fc37609f99d4c415719d8cde71f09c1ddf Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Mon, 17 Oct 2022 12:54:05 +0200 Subject: [PATCH 4/7] test: Remove accessing etcd via BinDir Signed-off-by: Marek Siarkowicz --- tests/e2e/cluster_downgrade_test.go | 2 +- tests/e2e/ctl_v3_test.go | 2 +- tests/e2e/etcd_config_test.go | 20 ++++++++++---------- tests/e2e/etcd_grpcproxy_test.go | 2 +- tests/e2e/etcd_release_upgrade_test.go | 4 ++-- tests/e2e/v2store_deprecation_test.go | 8 ++++---- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/tests/e2e/cluster_downgrade_test.go b/tests/e2e/cluster_downgrade_test.go index a8531e7dbb2..827178557e2 100644 --- a/tests/e2e/cluster_downgrade_test.go +++ b/tests/e2e/cluster_downgrade_test.go @@ -37,7 +37,7 @@ func TestDowngradeUpgradeClusterOf3(t *testing.T) { } func testDowngradeUpgrade(t *testing.T, clusterSize int) { - currentEtcdBinary := e2e.BinDir + "/etcd" + currentEtcdBinary := e2e.BinPath.Etcd lastReleaseBinary := e2e.BinDir + "/etcd-last-release" if !fileutil.Exist(lastReleaseBinary) { t.Skipf("%q does not exist", lastReleaseBinary) diff --git a/tests/e2e/ctl_v3_test.go b/tests/e2e/ctl_v3_test.go index a6118b06934..9f898245aca 100644 --- a/tests/e2e/ctl_v3_test.go +++ b/tests/e2e/ctl_v3_test.go @@ -51,7 +51,7 @@ func TestClusterVersion(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - binary := e2e.BinDir + "/etcd" + binary := e2e.BinPath.Etcd if !fileutil.Exist(binary) { t.Skipf("%q does not exist", binary) } diff --git a/tests/e2e/etcd_config_test.go b/tests/e2e/etcd_config_test.go index 4af2448e357..822bc45bb11 100644 --- a/tests/e2e/etcd_config_test.go +++ b/tests/e2e/etcd_config_test.go @@ -30,7 +30,7 @@ const exampleConfigFile = "../../etcd.conf.yml.sample" func TestEtcdExampleConfig(t *testing.T) { e2e.SkipInShortMode(t) - proc, err := e2e.SpawnCmd([]string{e2e.BinDir + "/etcd", "--config-file", exampleConfigFile}, nil) + proc, err := e2e.SpawnCmd([]string{e2e.BinPath.Etcd, "--config-file", exampleConfigFile}, nil) if err != nil { t.Fatal(err) } @@ -62,7 +62,7 @@ func TestEtcdMultiPeer(t *testing.T) { }() for i := range procs { args := []string{ - e2e.BinDir + "/etcd", + e2e.BinPath.Etcd, "--name", fmt.Sprintf("e%d", i), "--listen-client-urls", "http://0.0.0.0:0", "--data-dir", tmpdirs[i], @@ -92,7 +92,7 @@ func TestEtcdUnixPeers(t *testing.T) { d := t.TempDir() proc, err := e2e.SpawnCmd( []string{ - e2e.BinDir + "/etcd", + e2e.BinPath.Etcd, "--data-dir", d, "--name", "e1", "--listen-peer-urls", "unix://etcd.unix:1", @@ -135,7 +135,7 @@ func TestEtcdPeerCNAuth(t *testing.T) { // node 0 and 1 have a cert with the correct CN, node 2 doesn't for i := range procs { commonArgs := []string{ - e2e.BinDir + "/etcd", + e2e.BinPath.Etcd, "--name", fmt.Sprintf("e%d", i), "--listen-client-urls", "http://0.0.0.0:0", "--data-dir", tmpdirs[i], @@ -214,7 +214,7 @@ func TestEtcdPeerNameAuth(t *testing.T) { // node 0 and 1 have a cert with the correct certificate name, node 2 doesn't for i := range procs { commonArgs := []string{ - e2e.BinDir + "/etcd", + e2e.BinPath.Etcd, "--name", fmt.Sprintf("e%d", i), "--listen-client-urls", "http://0.0.0.0:0", "--data-dir", tmpdirs[i], @@ -269,7 +269,7 @@ func TestGrpcproxyAndCommonName(t *testing.T) { e2e.SkipInShortMode(t) argsWithNonEmptyCN := []string{ - e2e.BinDir + "/etcd", + e2e.BinPath.Etcd, "grpc-proxy", "start", "--cert", e2e.CertPath2, @@ -278,7 +278,7 @@ func TestGrpcproxyAndCommonName(t *testing.T) { } argsWithEmptyCN := []string{ - e2e.BinDir + "/etcd", + e2e.BinPath.Etcd, "grpc-proxy", "start", "--cert", e2e.CertPath3, @@ -313,7 +313,7 @@ func TestGrpcproxyAndListenCipherSuite(t *testing.T) { { name: "ArgsWithCipherSuites", args: []string{ - e2e.BinDir + "/etcd", + e2e.BinPath.Etcd, "grpc-proxy", "start", "--listen-cipher-suites", "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", @@ -322,7 +322,7 @@ func TestGrpcproxyAndListenCipherSuite(t *testing.T) { { name: "ArgsWithoutCipherSuites", args: []string{ - e2e.BinDir + "/etcd", + e2e.BinPath.Etcd, "grpc-proxy", "start", "--listen-cipher-suites", "", @@ -346,7 +346,7 @@ func TestGrpcproxyAndListenCipherSuite(t *testing.T) { func TestBootstrapDefragFlag(t *testing.T) { e2e.SkipInShortMode(t) - proc, err := e2e.SpawnCmd([]string{e2e.BinDir + "/etcd", "--experimental-bootstrap-defrag-threshold-megabytes", "1000"}, nil) + proc, err := e2e.SpawnCmd([]string{e2e.BinPath.Etcd, "--experimental-bootstrap-defrag-threshold-megabytes", "1000"}, nil) if err != nil { t.Fatal(err) } diff --git a/tests/e2e/etcd_grpcproxy_test.go b/tests/e2e/etcd_grpcproxy_test.go index dae62b73855..71d01cf617b 100644 --- a/tests/e2e/etcd_grpcproxy_test.go +++ b/tests/e2e/etcd_grpcproxy_test.go @@ -49,7 +49,7 @@ func TestGrpcProxyAutoSync(t *testing.T) { ) // Run independent grpc-proxy instance - proxyProc, err := e2e.SpawnCmd([]string{e2e.BinDir + "/etcd", "grpc-proxy", "start", + proxyProc, err := e2e.SpawnCmd([]string{e2e.BinPath.Etcd, "grpc-proxy", "start", "--advertise-client-url", proxyClientURL, "--listen-addr", proxyClientURL, "--endpoints", node1ClientURL, "--endpoints-auto-sync-interval", "1s", diff --git a/tests/e2e/etcd_release_upgrade_test.go b/tests/e2e/etcd_release_upgrade_test.go index 88f97ca737f..1541e6c5bfa 100644 --- a/tests/e2e/etcd_release_upgrade_test.go +++ b/tests/e2e/etcd_release_upgrade_test.go @@ -76,7 +76,7 @@ func TestReleaseUpgrade(t *testing.T) { t.Fatalf("#%d: error closing etcd process (%v)", i, err) } t.Logf("Stopped node: %v", i) - epc.Procs[i].Config().ExecPath = e2e.BinDir + "/etcd" + epc.Procs[i].Config().ExecPath = e2e.BinPath.Etcd epc.Procs[i].Config().KeepDataDir = true t.Logf("Restarting node in the new version: %v", i) @@ -162,7 +162,7 @@ func TestReleaseUpgradeWithRestart(t *testing.T) { wg.Add(len(epc.Procs)) for i := range epc.Procs { go func(i int) { - epc.Procs[i].Config().ExecPath = e2e.BinDir + "/etcd" + epc.Procs[i].Config().ExecPath = e2e.BinPath.Etcd epc.Procs[i].Config().KeepDataDir = true if err := epc.Procs[i].Restart(context.TODO()); err != nil { t.Errorf("error restarting etcd process (%v)", err) diff --git a/tests/e2e/v2store_deprecation_test.go b/tests/e2e/v2store_deprecation_test.go index 5b9f5f4ddad..87e4f08d18b 100644 --- a/tests/e2e/v2store_deprecation_test.go +++ b/tests/e2e/v2store_deprecation_test.go @@ -55,7 +55,7 @@ func createV2store(t testing.TB, lastReleaseBinary string, dataDirPath string) { func assertVerifyCannotStartV2deprecationWriteOnly(t testing.TB, dataDirPath string) { t.Log("Verify its infeasible to start etcd with --v2-deprecation=write-only mode") - proc, err := e2e.SpawnCmd([]string{e2e.BinDir + "/etcd", "--v2-deprecation=write-only", "--data-dir=" + dataDirPath}, nil) + proc, err := e2e.SpawnCmd([]string{e2e.BinPath.Etcd, "--v2-deprecation=write-only", "--data-dir=" + dataDirPath}, nil) assert.NoError(t, err) _, err = proc.Expect("detected disallowed custom content in v2store for stage --v2-deprecation=write-only") @@ -64,7 +64,7 @@ func assertVerifyCannotStartV2deprecationWriteOnly(t testing.TB, dataDirPath str func assertVerifyCannotStartV2deprecationNotYet(t testing.TB, dataDirPath string) { t.Log("Verify its infeasible to start etcd with --v2-deprecation=not-yet mode") - proc, err := e2e.SpawnCmd([]string{e2e.BinDir + "/etcd", "--v2-deprecation=not-yet", "--data-dir=" + dataDirPath}, nil) + proc, err := e2e.SpawnCmd([]string{e2e.BinPath.Etcd, "--v2-deprecation=not-yet", "--data-dir=" + dataDirPath}, nil) assert.NoError(t, err) _, err = proc.Expect(`invalid value "not-yet" for flag -v2-deprecation: invalid value "not-yet"`) @@ -102,7 +102,7 @@ func TestV2DeprecationSnapshotMatches(t *testing.T) { defer cancel() lastReleaseBinary := e2e.BinDir + "/etcd-last-release" - currentReleaseBinary := e2e.BinDir + "/etcd" + currentReleaseBinary := e2e.BinPath.Etcd if !fileutil.Exist(lastReleaseBinary) { t.Skipf("%q does not exist", lastReleaseBinary) @@ -137,7 +137,7 @@ func TestV2DeprecationSnapshotRecover(t *testing.T) { defer cancel() lastReleaseBinary := e2e.BinDir + "/etcd-last-release" - currentReleaseBinary := e2e.BinDir + "/etcd" + currentReleaseBinary := e2e.BinPath.Etcd if !fileutil.Exist(lastReleaseBinary) { t.Skipf("%q does not exist", lastReleaseBinary) From 9bba38e51fc0eaa86ce72d5e657adeaca684b8ef Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Mon, 17 Oct 2022 12:54:56 +0200 Subject: [PATCH 5/7] tests: Include etcd-last-release in BinPath Signed-off-by: Marek Siarkowicz --- tests/e2e/cluster_downgrade_test.go | 2 +- tests/e2e/discovery_test.go | 2 +- tests/e2e/etcd_release_upgrade_test.go | 4 ++-- tests/e2e/utl_migrate_test.go | 2 +- tests/e2e/v2store_deprecation_test.go | 6 +++--- tests/framework/e2e/etcd_spawn_cov.go | 7 ++++--- tests/framework/e2e/etcd_spawn_nocov.go | 7 ++++--- tests/framework/e2e/flags.go | 7 ++++--- 8 files changed, 20 insertions(+), 17 deletions(-) diff --git a/tests/e2e/cluster_downgrade_test.go b/tests/e2e/cluster_downgrade_test.go index 827178557e2..001f5d7d887 100644 --- a/tests/e2e/cluster_downgrade_test.go +++ b/tests/e2e/cluster_downgrade_test.go @@ -38,7 +38,7 @@ func TestDowngradeUpgradeClusterOf3(t *testing.T) { func testDowngradeUpgrade(t *testing.T, clusterSize int) { currentEtcdBinary := e2e.BinPath.Etcd - lastReleaseBinary := e2e.BinDir + "/etcd-last-release" + lastReleaseBinary := e2e.BinPath.EtcdLastRelease if !fileutil.Exist(lastReleaseBinary) { t.Skipf("%q does not exist", lastReleaseBinary) } diff --git a/tests/e2e/discovery_test.go b/tests/e2e/discovery_test.go index 001fd96c394..8bfa199e600 100644 --- a/tests/e2e/discovery_test.go +++ b/tests/e2e/discovery_test.go @@ -38,7 +38,7 @@ func TestTLSClusterOf3UsingDiscovery(t *testing.T) { testClusterUsingDiscovery(t func testClusterUsingDiscovery(t *testing.T, size int, peerTLS bool) { e2e.BeforeTest(t) - lastReleaseBinary := e2e.BinDir + "/etcd-last-release" + lastReleaseBinary := e2e.BinPath.EtcdLastRelease if !fileutil.Exist(lastReleaseBinary) { t.Skipf("%q does not exist", lastReleaseBinary) } diff --git a/tests/e2e/etcd_release_upgrade_test.go b/tests/e2e/etcd_release_upgrade_test.go index 1541e6c5bfa..1f65afd56d5 100644 --- a/tests/e2e/etcd_release_upgrade_test.go +++ b/tests/e2e/etcd_release_upgrade_test.go @@ -29,7 +29,7 @@ import ( // TestReleaseUpgrade ensures that changes to master branch does not affect // upgrade from latest etcd releases. func TestReleaseUpgrade(t *testing.T) { - lastReleaseBinary := e2e.BinDir + "/etcd-last-release" + lastReleaseBinary := e2e.BinPath.EtcdLastRelease if !fileutil.Exist(lastReleaseBinary) { t.Skipf("%q does not exist", lastReleaseBinary) } @@ -113,7 +113,7 @@ func TestReleaseUpgrade(t *testing.T) { } func TestReleaseUpgradeWithRestart(t *testing.T) { - lastReleaseBinary := e2e.BinDir + "/etcd-last-release" + lastReleaseBinary := e2e.BinPath.EtcdLastRelease if !fileutil.Exist(lastReleaseBinary) { t.Skipf("%q does not exist", lastReleaseBinary) } diff --git a/tests/e2e/utl_migrate_test.go b/tests/e2e/utl_migrate_test.go index 20f6e3f53d0..a6236991c22 100644 --- a/tests/e2e/utl_migrate_test.go +++ b/tests/e2e/utl_migrate_test.go @@ -32,7 +32,7 @@ import ( ) func TestEtctlutlMigrate(t *testing.T) { - lastReleaseBinary := e2e.BinDir + "/etcd-last-release" + lastReleaseBinary := e2e.BinPath.EtcdLastRelease tcs := []struct { name string diff --git a/tests/e2e/v2store_deprecation_test.go b/tests/e2e/v2store_deprecation_test.go index 87e4f08d18b..61dae5a4443 100644 --- a/tests/e2e/v2store_deprecation_test.go +++ b/tests/e2e/v2store_deprecation_test.go @@ -75,7 +75,7 @@ func TestV2DeprecationFlags(t *testing.T) { e2e.BeforeTest(t) dataDirPath := t.TempDir() - lastReleaseBinary := e2e.BinDir + "/etcd-last-release" + lastReleaseBinary := e2e.BinPath.EtcdLastRelease if !fileutil.Exist(lastReleaseBinary) { t.Skipf("%q does not exist", lastReleaseBinary) } @@ -101,7 +101,7 @@ func TestV2DeprecationSnapshotMatches(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - lastReleaseBinary := e2e.BinDir + "/etcd-last-release" + lastReleaseBinary := e2e.BinPath.EtcdLastRelease currentReleaseBinary := e2e.BinPath.Etcd if !fileutil.Exist(lastReleaseBinary) { @@ -136,7 +136,7 @@ func TestV2DeprecationSnapshotRecover(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - lastReleaseBinary := e2e.BinDir + "/etcd-last-release" + lastReleaseBinary := e2e.BinPath.EtcdLastRelease currentReleaseBinary := e2e.BinPath.Etcd if !fileutil.Exist(lastReleaseBinary) { diff --git a/tests/framework/e2e/etcd_spawn_cov.go b/tests/framework/e2e/etcd_spawn_cov.go index fba1c37fe3a..6aea4f2ae66 100644 --- a/tests/framework/e2e/etcd_spawn_cov.go +++ b/tests/framework/e2e/etcd_spawn_cov.go @@ -40,9 +40,10 @@ func init() { func initBinPathCov(binDir string) binPath { return binPath{ - Etcd: binDir + "/etcd_test", - Etcdctl: binDir + "/etcdctl_test", - Etcdutl: binDir + "/etcdutl_test", + Etcd: binDir + "/etcd_test", + EtcdLastRelease: binDir + "/etcd-last-release", + Etcdctl: binDir + "/etcdctl_test", + Etcdutl: binDir + "/etcdutl_test", } } diff --git a/tests/framework/e2e/etcd_spawn_nocov.go b/tests/framework/e2e/etcd_spawn_nocov.go index a02df0d6c05..d485eaa952b 100644 --- a/tests/framework/e2e/etcd_spawn_nocov.go +++ b/tests/framework/e2e/etcd_spawn_nocov.go @@ -33,9 +33,10 @@ func init() { func initBinPathNoCov(binDir string) binPath { return binPath{ - Etcd: binDir + "/etcd", - Etcdctl: binDir + "/etcdctl", - Etcdutl: binDir + "/etcdutl", + Etcd: binDir + "/etcd", + EtcdLastRelease: binDir + "/etcd-last-release", + Etcdctl: binDir + "/etcdctl", + Etcdutl: binDir + "/etcdutl", } } diff --git a/tests/framework/e2e/flags.go b/tests/framework/e2e/flags.go index 2b1e5dca3ca..213e8eb5c9e 100644 --- a/tests/framework/e2e/flags.go +++ b/tests/framework/e2e/flags.go @@ -45,9 +45,10 @@ var ( ) type binPath struct { - Etcd string - Etcdctl string - Etcdutl string + Etcd string + EtcdLastRelease string + Etcdctl string + Etcdutl string } func InitFlags() { From 574b3d33d17040481cab43250f4c4ea61ceac16b Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Mon, 17 Oct 2022 12:56:34 +0200 Subject: [PATCH 6/7] test: Remove BinDir global variable Signed-off-by: Marek Siarkowicz --- tests/framework/e2e/flags.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/framework/e2e/flags.go b/tests/framework/e2e/flags.go index 213e8eb5c9e..d51d2898034 100644 --- a/tests/framework/e2e/flags.go +++ b/tests/framework/e2e/flags.go @@ -23,7 +23,6 @@ import ( ) var ( - BinDir string CertDir string CertPath string @@ -57,11 +56,11 @@ func InitFlags() { binDirDef := testutils.MustAbsPath("../../bin") certDirDef := FixturesDir - flag.StringVar(&BinDir, "bin-dir", binDirDef, "The directory for store etcd and etcdctl binaries.") + binDir := flag.String("bin-dir", binDirDef, "The directory for store etcd and etcdctl binaries.") flag.StringVar(&CertDir, "cert-dir", certDirDef, "The directory for store certificate files.") flag.Parse() - BinPath = initBinPath(BinDir) + BinPath = initBinPath(*binDir) CertPath = CertDir + "/server.crt" PrivateKeyPath = CertDir + "/server.key.insecure" CaPath = CertDir + "/ca.crt" From 1b3f301cc21f475adb6aefa22d47773fe9fb2014 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Mon, 17 Oct 2022 13:04:20 +0200 Subject: [PATCH 7/7] tests: Share SpawnCmdWithLogger between coverage and no coverage scenarios Signed-off-by: Marek Siarkowicz --- tests/framework/e2e/etcd_spawn.go | 23 ++++++++++++++++++- tests/framework/e2e/etcd_spawn_cov.go | 30 ++----------------------- tests/framework/e2e/etcd_spawn_nocov.go | 23 +++---------------- 3 files changed, 27 insertions(+), 49 deletions(-) diff --git a/tests/framework/e2e/etcd_spawn.go b/tests/framework/e2e/etcd_spawn.go index 5f76f186886..ff2e2f4c790 100644 --- a/tests/framework/e2e/etcd_spawn.go +++ b/tests/framework/e2e/etcd_spawn.go @@ -15,6 +15,7 @@ package e2e import ( + "os" "strings" "go.uber.org/zap" @@ -23,7 +24,8 @@ import ( ) var ( - initBinPath func(string) binPath + initBinPath func(string) binPath + additionalArgs func() ([]string, error) ) func SpawnCmd(args []string, envVars map[string]string) (*expect.ExpectProcess, error) { @@ -33,3 +35,22 @@ func SpawnCmd(args []string, envVars map[string]string) (*expect.ExpectProcess, func SpawnNamedCmd(processName string, args []string, envVars map[string]string) (*expect.ExpectProcess, error) { return SpawnCmdWithLogger(zap.NewNop(), args, envVars, processName) } + +func SpawnCmdWithLogger(lg *zap.Logger, args []string, envVars map[string]string, name string) (*expect.ExpectProcess, error) { + wd, err := os.Getwd() + if err != nil { + return nil, err + } + + newArgs, err := additionalArgs() + if err != nil { + return nil, err + } + env := mergeEnvVariables(envVars) + lg.Info("spawning process", + zap.Strings("args", args), + zap.String("working-dir", wd), + zap.String("name", name), + zap.Strings("environment-variables", env)) + return expect.NewExpectWithEnv(args[0], append(args[1:], newArgs...), env, name) +} diff --git a/tests/framework/e2e/etcd_spawn_cov.go b/tests/framework/e2e/etcd_spawn_cov.go index 6aea4f2ae66..349391092df 100644 --- a/tests/framework/e2e/etcd_spawn_cov.go +++ b/tests/framework/e2e/etcd_spawn_cov.go @@ -23,9 +23,7 @@ import ( "time" "go.etcd.io/etcd/client/pkg/v3/fileutil" - "go.etcd.io/etcd/pkg/v3/expect" "go.etcd.io/etcd/tests/v3/framework/testutils" - "go.uber.org/zap" ) const noOutputLineCount = 2 // cov-enabled binaries emit PASS and coverage count lines @@ -36,6 +34,7 @@ var ( func init() { initBinPath = initBinPathCov + additionalArgs = additionalArgsCov } func initBinPathCov(binDir string) binPath { @@ -47,32 +46,7 @@ func initBinPathCov(binDir string) binPath { } } -func SpawnCmdWithLogger(lg *zap.Logger, args []string, envVars map[string]string, name string) (*expect.ExpectProcess, error) { - cmd := args[0] - env := mergeEnvVariables(envVars) - - wd, err := os.Getwd() - if err != nil { - return nil, err - } - - covArgs, err := getCovArgs() - if err != nil { - return nil, err - } - // when withFlagByEnv() is used in testCtl(), env variables for ctl is set to os.env. - // they must be included in ctl_cov_env. - - allArgs := append(args[1:], covArgs...) - lg.Info("spawning process in cov test", - zap.Strings("args", args), - zap.String("working-dir", wd), - zap.String("name", name), - zap.Strings("environment-variables", env)) - return expect.NewExpectWithEnv(cmd, allArgs, env, name) -} - -func getCovArgs() ([]string, error) { +func additionalArgsCov() ([]string, error) { if !fileutil.Exist(coverDir) { return nil, fmt.Errorf("could not find coverage folder: %s", coverDir) } diff --git a/tests/framework/e2e/etcd_spawn_nocov.go b/tests/framework/e2e/etcd_spawn_nocov.go index d485eaa952b..3f16e388798 100644 --- a/tests/framework/e2e/etcd_spawn_nocov.go +++ b/tests/framework/e2e/etcd_spawn_nocov.go @@ -17,18 +17,11 @@ package e2e -import ( - "os" - - "go.uber.org/zap" - - "go.etcd.io/etcd/pkg/v3/expect" -) - const noOutputLineCount = 0 // regular binaries emit no extra lines func init() { initBinPath = initBinPathNoCov + additionalArgs = additionalArgsNoCov } func initBinPathNoCov(binDir string) binPath { @@ -40,16 +33,6 @@ func initBinPathNoCov(binDir string) binPath { } } -func SpawnCmdWithLogger(lg *zap.Logger, args []string, envVars map[string]string, name string) (*expect.ExpectProcess, error) { - wd, err := os.Getwd() - if err != nil { - return nil, err - } - env := mergeEnvVariables(envVars) - lg.Info("spawning process", - zap.Strings("args", args), - zap.String("working-dir", wd), - zap.String("name", name), - zap.Strings("environment-variables", env)) - return expect.NewExpectWithEnv(args[0], args[1:], env, name) +func additionalArgsNoCov() ([]string, error) { + return []string{}, nil }