mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #14441 from tjungblu/bz_1918413_3.4_upstream
[release-3.4] etcdctl: fix move-leader for multiple endpoints
This commit is contained in:
commit
a55a9f5e07
@ -42,7 +42,8 @@ func transferLeadershipCommandFunc(cmd *cobra.Command, args []string) {
|
|||||||
ExitWithError(ExitBadArgs, err)
|
ExitWithError(ExitBadArgs, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c := mustClientFromCmd(cmd)
|
cfg := clientConfigFromCmd(cmd)
|
||||||
|
c := cfg.mustClient()
|
||||||
eps := c.Endpoints()
|
eps := c.Endpoints()
|
||||||
c.Close()
|
c.Close()
|
||||||
|
|
||||||
@ -52,7 +53,6 @@ func transferLeadershipCommandFunc(cmd *cobra.Command, args []string) {
|
|||||||
var leaderCli *clientv3.Client
|
var leaderCli *clientv3.Client
|
||||||
var leaderID uint64
|
var leaderID uint64
|
||||||
for _, ep := range eps {
|
for _, ep := range eps {
|
||||||
cfg := clientConfigFromCmd(cmd)
|
|
||||||
cfg.endpoints = []string{ep}
|
cfg.endpoints = []string{ep}
|
||||||
cli := cfg.mustClient()
|
cli := cfg.mustClient()
|
||||||
resp, serr := cli.Status(ctx, ep)
|
resp, serr := cli.Status(ctx, ep)
|
||||||
|
@ -28,15 +28,31 @@ import (
|
|||||||
"go.etcd.io/etcd/pkg/types"
|
"go.etcd.io/etcd/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCtlV3MoveLeaderSecure(t *testing.T) {
|
func TestCtlV3MoveLeaderScenarios(t *testing.T) {
|
||||||
testCtlV3MoveLeader(t, configTLS)
|
security := map[string]struct {
|
||||||
|
cfg etcdProcessClusterConfig
|
||||||
|
}{
|
||||||
|
"Secure": {cfg: configTLS},
|
||||||
|
"Insecure": {cfg: configNoTLS},
|
||||||
|
}
|
||||||
|
|
||||||
|
tests := map[string]struct {
|
||||||
|
env map[string]struct{}
|
||||||
|
}{
|
||||||
|
"happy path": {env: nil},
|
||||||
|
"with env": {env: map[string]struct{}{}},
|
||||||
|
}
|
||||||
|
|
||||||
|
for testName, tx := range tests {
|
||||||
|
for subTestName, tc := range security {
|
||||||
|
t.Run(testName+" "+subTestName, func(t *testing.T) {
|
||||||
|
testCtlV3MoveLeader(t, tc.cfg, tx.env)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCtlV3MoveLeaderInsecure(t *testing.T) {
|
func testCtlV3MoveLeader(t *testing.T, cfg etcdProcessClusterConfig, envVars map[string]struct{}) {
|
||||||
testCtlV3MoveLeader(t, configNoTLS)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testCtlV3MoveLeader(t *testing.T, cfg etcdProcessClusterConfig) {
|
|
||||||
defer testutil.AfterTest(t)
|
defer testutil.AfterTest(t)
|
||||||
|
|
||||||
epc := setupEtcdctlTest(t, &cfg, true)
|
epc := setupEtcdctlTest(t, &cfg, true)
|
||||||
@ -95,23 +111,37 @@ func testCtlV3MoveLeader(t *testing.T, cfg etcdProcessClusterConfig) {
|
|||||||
cfg: configNoTLS,
|
cfg: configNoTLS,
|
||||||
dialTimeout: 7 * time.Second,
|
dialTimeout: 7 * time.Second,
|
||||||
epc: epc,
|
epc: epc,
|
||||||
|
envMap: envVars,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if cx.envMap != nil {
|
||||||
|
for k := range cx.envMap {
|
||||||
|
os.Unsetenv(k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
prefixes []string
|
prefixes []string
|
||||||
expect string
|
expect string
|
||||||
}{
|
}{
|
||||||
{ // request to non-leader
|
{ // request to non-leader
|
||||||
cx.prefixArgs([]string{cx.epc.EndpointsV3()[(leadIdx+1)%3]}),
|
[]string{cx.epc.EndpointsV3()[(leadIdx+1)%3]},
|
||||||
"no leader endpoint given at ",
|
"no leader endpoint given at ",
|
||||||
},
|
},
|
||||||
{ // request to leader
|
{ // request to leader
|
||||||
cx.prefixArgs([]string{cx.epc.EndpointsV3()[leadIdx]}),
|
[]string{cx.epc.EndpointsV3()[leadIdx]},
|
||||||
fmt.Sprintf("Leadership transferred from %s to %s", types.ID(leaderID), types.ID(transferee)),
|
fmt.Sprintf("Leadership transferred from %s to %s", types.ID(leaderID), types.ID(transferee)),
|
||||||
},
|
},
|
||||||
|
{ // request to all endpoints
|
||||||
|
cx.epc.EndpointsV3(),
|
||||||
|
fmt.Sprintf("Leadership transferred"),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for i, tc := range tests {
|
for i, tc := range tests {
|
||||||
cmdArgs := append(tc.prefixes, "move-leader", types.ID(transferee).String())
|
pf := cx.prefixArgs(tc.prefixes)
|
||||||
|
cmdArgs := append(pf, "move-leader", types.ID(transferee).String())
|
||||||
if err := spawnWithExpect(cmdArgs, tc.expect); err != nil {
|
if err := spawnWithExpect(cmdArgs, tc.expect); err != nil {
|
||||||
t.Fatalf("#%d: %v", i, err)
|
t.Fatalf("#%d: %v", i, err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user