E2E tests should log commandlines used to spawn etcd or etcd proxy binaries.

This commit is contained in:
Piotr Tabor 2021-05-14 05:54:15 +02:00
parent f5c26814ab
commit 582d02e7f5
4 changed files with 23 additions and 2 deletions

View File

@ -27,6 +27,7 @@ import (
"strings"
"go.etcd.io/etcd/pkg/v3/expect"
"go.uber.org/zap"
)
type proxyEtcdProcess struct {
@ -115,6 +116,7 @@ func (p *proxyEtcdProcess) WithStopSignal(sig os.Signal) os.Signal {
}
type proxyProc struct {
lg *zap.Logger
execPath string
args []string
ep string
@ -130,7 +132,7 @@ func (pp *proxyProc) start() error {
if pp.proc != nil {
panic("already started")
}
proc, err := spawnCmd(append([]string{pp.execPath}, pp.args...))
proc, err := spawnCmdWithLogger(pp.lg, append([]string{pp.execPath}, pp.args...))
if err != nil {
return err
}
@ -192,6 +194,7 @@ func newProxyV2Proc(cfg *etcdServerProcessConfig) *proxyV2Proc {
}
return &proxyV2Proc{
proxyProc{
lg: cfg.lg,
execPath: cfg.execPath,
args: append(args, cfg.tlsArgs...),
ep: listenAddr,
@ -276,6 +279,7 @@ func newProxyV3Proc(cfg *etcdServerProcessConfig) *proxyV3Proc {
}
return &proxyV3Proc{
proxyProc{
lg: cfg.lg,
execPath: cfg.execPath,
args: append(args, tlsArgs...),
ep: listenAddr,

View File

@ -25,6 +25,7 @@ import (
"go.etcd.io/etcd/server/v3/etcdserver"
"go.etcd.io/etcd/tests/v3/integration"
"go.uber.org/zap/zaptest"
)
const etcdProcessBasePort = 20000
@ -225,6 +226,8 @@ func (cfg *etcdProcessClusterConfig) peerScheme() string {
}
func (cfg *etcdProcessClusterConfig) etcdServerProcessConfigs(tb testing.TB) []*etcdServerProcessConfig {
lg := zaptest.NewLogger(tb)
if cfg.basePort == 0 {
cfg.basePort = etcdProcessBasePort
}
@ -309,6 +312,7 @@ func (cfg *etcdProcessClusterConfig) etcdServerProcessConfigs(tb testing.TB) []*
}
etcdCfgs[i] = &etcdServerProcessConfig{
lg: lg,
execPath: cfg.execPath,
args: args,
tlsArgs: cfg.tlsArgs(),

View File

@ -21,6 +21,7 @@ import (
"go.etcd.io/etcd/client/pkg/v3/fileutil"
"go.etcd.io/etcd/pkg/v3/expect"
"go.uber.org/zap"
)
var (
@ -50,6 +51,7 @@ type etcdServerProcess struct {
}
type etcdServerProcessConfig struct {
lg *zap.Logger
execPath string
args []string
tlsArgs []string
@ -88,7 +90,7 @@ func (ep *etcdServerProcess) Start() error {
if ep.proc != nil {
panic("already started")
}
proc, err := spawnCmd(append([]string{ep.cfg.execPath}, ep.cfg.args...))
proc, err := spawnCmdWithLogger(ep.cfg.lg, append([]string{ep.cfg.execPath}, ep.cfg.args...))
if err != nil {
return err
}

View File

@ -21,14 +21,25 @@ import (
"os"
"go.etcd.io/etcd/pkg/v3/expect"
"go.uber.org/zap"
)
const noOutputLineCount = 0 // regular binaries emit no extra lines
func spawnCmd(args []string) (*expect.ExpectProcess, error) {
return spawnCmdWithLogger(zap.NewNop(), args)
}
func spawnCmdWithLogger(lg *zap.Logger, args []string) (*expect.ExpectProcess, error) {
wd, err := os.Getwd()
if err != nil {
return nil, err
}
if args[0] == ctlBinPath+"3" {
env := append(os.Environ(), "ETCDCTL_API=3")
lg.Info("spawning process with ETCDCTL_API=3", zap.Strings("args", args), zap.String("working-dir", wd))
return expect.NewExpectWithEnv(ctlBinPath, args[1:], env)
}
lg.Info("spawning process", zap.Strings("args", args), zap.String("working-dir", wd))
return expect.NewExpect(args[0], args[1:]...)
}