From 3eac8e579ab1060110f6655c6aee8e5a48b7b85a Mon Sep 17 00:00:00 2001 From: husharp Date: Wed, 7 Aug 2024 17:32:04 +0800 Subject: [PATCH 1/3] add failed msg Signed-off-by: husharp --- tools/pd-ctl/pdctl/command/scheduler.go | 15 ++++++++++++++- tools/pd-ctl/tests/scheduler/scheduler_test.go | 8 +++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/tools/pd-ctl/pdctl/command/scheduler.go b/tools/pd-ctl/pdctl/command/scheduler.go index 4c85bb64037..c9838f8df41 100644 --- a/tools/pd-ctl/pdctl/command/scheduler.go +++ b/tools/pd-ctl/pdctl/command/scheduler.go @@ -641,6 +641,13 @@ func addStoreToSchedulerConfig(cmd *cobra.Command, schedulerName string, args [] cmd.Println(cmd.UsageString()) return } + + exist, err := checkSchedulerExist(cmd, schedulerName) + if !exist { + cmd.Printf("Failed! scheduler %s not found.\n", schedulerName) + return + } + storeID, err := strconv.ParseUint(args[0], 10, 64) if err != nil { cmd.Println(err) @@ -768,8 +775,14 @@ func deleteStoreFromSchedulerConfig(cmd *cobra.Command, schedulerName string, ar cmd.Println(cmd.Usage()) return } + exist, err := checkSchedulerExist(cmd, schedulerName) + if !exist { + cmd.Printf("Failed! scheduler %s not found.\n", schedulerName) + return + } + path := path.Join(schedulerConfigPrefix, "/", schedulerName, "delete", args[0]) - _, err := doRequest(cmd, path, http.MethodDelete, http.Header{}) + _, err = doRequest(cmd, path, http.MethodDelete, http.Header{}) if err != nil { cmd.Println(err) return diff --git a/tools/pd-ctl/tests/scheduler/scheduler_test.go b/tools/pd-ctl/tests/scheduler/scheduler_test.go index 3a6e29f3586..9c9ec704ac3 100644 --- a/tools/pd-ctl/tests/scheduler/scheduler_test.go +++ b/tools/pd-ctl/tests/scheduler/scheduler_test.go @@ -204,6 +204,12 @@ func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) { for idx := range schedulers { checkStorePause([]uint64{}, schedulers[idx]) + + // will fail because the scheduler is not existed + args = []string{"-u", pdAddr, "scheduler", "config", schedulers[idx], "add-store", "3"} + output := mustExec(re, cmd, args, nil) + re.Contains(output, fmt.Sprintf("Failed! scheduler %s not found", schedulers[idx])) + // scheduler add command args = []string{"-u", pdAddr, "scheduler", "add", schedulers[idx], "2"} expected = map[string]bool{ @@ -315,7 +321,7 @@ func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) { echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "remove", "evict-leader-scheduler-2"}, nil) re.Contains(echo, "Success!") echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "remove", "evict-leader-scheduler-1"}, nil) - re.Contains(echo, "404") + re.Contains(echo, "Failed! scheduler evict-leader-scheduler not found") testutil.Eventually(re, func() bool { // wait for removed scheduler to be synced to scheduling server. echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "config", "evict-leader-scheduler"}, nil) return strings.Contains(echo, "[404] scheduler not found") From 4f4e853e8b94974c68b8b98777dc45841887fb87 Mon Sep 17 00:00:00 2001 From: husharp Date: Wed, 7 Aug 2024 17:40:23 +0800 Subject: [PATCH 2/3] make static happy Signed-off-by: husharp --- tools/pd-ctl/pdctl/command/scheduler.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/pd-ctl/pdctl/command/scheduler.go b/tools/pd-ctl/pdctl/command/scheduler.go index c9838f8df41..95e1949d24c 100644 --- a/tools/pd-ctl/pdctl/command/scheduler.go +++ b/tools/pd-ctl/pdctl/command/scheduler.go @@ -643,6 +643,9 @@ func addStoreToSchedulerConfig(cmd *cobra.Command, schedulerName string, args [] } exist, err := checkSchedulerExist(cmd, schedulerName) + if err != nil { + return + } if !exist { cmd.Printf("Failed! scheduler %s not found.\n", schedulerName) return @@ -776,6 +779,9 @@ func deleteStoreFromSchedulerConfig(cmd *cobra.Command, schedulerName string, ar return } exist, err := checkSchedulerExist(cmd, schedulerName) + if err != nil { + return + } if !exist { cmd.Printf("Failed! scheduler %s not found.\n", schedulerName) return From 1f229807fde2c4d5daeeabd2ae03f72f7b47a283 Mon Sep 17 00:00:00 2001 From: husharp Date: Fri, 6 Sep 2024 15:27:06 +0800 Subject: [PATCH 3/3] change error msg Signed-off-by: husharp --- tools/pd-ctl/pdctl/command/scheduler.go | 4 ++-- tools/pd-ctl/tests/scheduler/scheduler_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/pd-ctl/pdctl/command/scheduler.go b/tools/pd-ctl/pdctl/command/scheduler.go index 95e1949d24c..43c6429cd4f 100644 --- a/tools/pd-ctl/pdctl/command/scheduler.go +++ b/tools/pd-ctl/pdctl/command/scheduler.go @@ -647,7 +647,7 @@ func addStoreToSchedulerConfig(cmd *cobra.Command, schedulerName string, args [] return } if !exist { - cmd.Printf("Failed! scheduler %s not found.\n", schedulerName) + cmd.Printf("Unable to update config: scheduler %s does not exist.\n", schedulerName) return } @@ -783,7 +783,7 @@ func deleteStoreFromSchedulerConfig(cmd *cobra.Command, schedulerName string, ar return } if !exist { - cmd.Printf("Failed! scheduler %s not found.\n", schedulerName) + cmd.Printf("Unable to update config: scheduler %s does not exist.\n", schedulerName) return } diff --git a/tools/pd-ctl/tests/scheduler/scheduler_test.go b/tools/pd-ctl/tests/scheduler/scheduler_test.go index 9c9ec704ac3..8c96f5ee3fa 100644 --- a/tools/pd-ctl/tests/scheduler/scheduler_test.go +++ b/tools/pd-ctl/tests/scheduler/scheduler_test.go @@ -208,7 +208,7 @@ func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) { // will fail because the scheduler is not existed args = []string{"-u", pdAddr, "scheduler", "config", schedulers[idx], "add-store", "3"} output := mustExec(re, cmd, args, nil) - re.Contains(output, fmt.Sprintf("Failed! scheduler %s not found", schedulers[idx])) + re.Contains(output, fmt.Sprintf("Unable to update config: scheduler %s does not exist.", schedulers[idx])) // scheduler add command args = []string{"-u", pdAddr, "scheduler", "add", schedulers[idx], "2"} @@ -321,7 +321,7 @@ func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) { echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "remove", "evict-leader-scheduler-2"}, nil) re.Contains(echo, "Success!") echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "remove", "evict-leader-scheduler-1"}, nil) - re.Contains(echo, "Failed! scheduler evict-leader-scheduler not found") + re.Contains(echo, "Unable to update config: scheduler evict-leader-scheduler does not exist.") testutil.Eventually(re, func() bool { // wait for removed scheduler to be synced to scheduling server. echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "config", "evict-leader-scheduler"}, nil) return strings.Contains(echo, "[404] scheduler not found")