wwctl should return non-zero exit code on wwctl power sub-commands

Signed-off-by: xu yang <xyang@ciq.com>
This commit is contained in:
xu yang
2024-09-30 06:41:53 +00:00
parent 617e1b9e5a
commit 65f67b79ba
13 changed files with 31 additions and 48 deletions

View File

@@ -48,6 +48,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix excessive line spacing issue when listing nodes. #1241 - Fix excessive line spacing issue when listing nodes. #1241
- Return non-zero exit code on node sub-commands #1421 - Return non-zero exit code on node sub-commands #1421
- Fix panic when getting a long container list before building the container. #1391 - Fix panic when getting a long container list before building the container. #1391
- Return non-zero exit code on power sub-commands #1439
## v4.5.8, unreleased ## v4.5.8, unreleased

View File

@@ -1,4 +1,4 @@
package powercycle package cycle
import ( import (
"fmt" "fmt"
@@ -17,14 +17,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
nodeDB, err := node.New() nodeDB, err := node.New()
if err != nil { if err != nil {
wwlog.Error("Could not open node configuration: %s", err) return fmt.Errorf("could not open node configuration: %s", err)
os.Exit(1)
} }
nodes, err := nodeDB.FindAllNodes() nodes, err := nodeDB.FindAllNodes()
if err != nil { if err != nil {
wwlog.Error("Could not get node list: %s", err) return fmt.Errorf("could not get node list: %s", err)
os.Exit(1)
} }
if len(args) > 0 { if len(args) > 0 {
@@ -36,8 +34,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
if len(nodes) == 0 { if len(nodes) == 0 {
fmt.Printf("No nodes found\n") return fmt.Errorf("no nodes found")
os.Exit(1)
} }
batchpool := batch.New(50) batchpool := batch.New(50)

View File

@@ -1,4 +1,4 @@
package powercycle package cycle
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"

View File

@@ -1,4 +1,4 @@
package poweroff package off
import ( import (
"fmt" "fmt"
@@ -17,14 +17,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
nodeDB, err := node.New() nodeDB, err := node.New()
if err != nil { if err != nil {
wwlog.Error("Could not open node configuration: %s", err) return fmt.Errorf("could not open node configuration: %s", err)
os.Exit(1)
} }
nodes, err := nodeDB.FindAllNodes() nodes, err := nodeDB.FindAllNodes()
if err != nil { if err != nil {
wwlog.Error("Could not get node list: %s", err) return fmt.Errorf("could not get node list: %s", err)
os.Exit(1)
} }
if len(args) > 0 { if len(args) > 0 {
@@ -36,8 +34,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
if len(nodes) == 0 { if len(nodes) == 0 {
fmt.Printf("No nodes found\n") return fmt.Errorf("no nodes found")
os.Exit(1)
} }
batchpool := batch.New(50) batchpool := batch.New(50)

View File

@@ -1,4 +1,4 @@
package poweroff package off
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"

View File

@@ -1,4 +1,4 @@
package poweron package on
import ( import (
"fmt" "fmt"
@@ -17,14 +17,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
nodeDB, err := node.New() nodeDB, err := node.New()
if err != nil { if err != nil {
wwlog.Error("Could not open node configuration: %s", err) return fmt.Errorf("could not open node configuration: %s", err)
os.Exit(1)
} }
nodes, err := nodeDB.FindAllNodes() nodes, err := nodeDB.FindAllNodes()
if err != nil { if err != nil {
wwlog.Error("Could not get node list: %s", err) return fmt.Errorf("could not get node list: %s", err)
os.Exit(1)
} }
if len(args) > 0 { if len(args) > 0 {
@@ -36,8 +34,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
if len(nodes) == 0 { if len(nodes) == 0 {
fmt.Printf("No nodes found\n") return fmt.Errorf("no nodes found")
os.Exit(1)
} }
batchpool := batch.New(50) batchpool := batch.New(50)

View File

@@ -1,4 +1,4 @@
package poweron package on
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"

View File

@@ -1,4 +1,4 @@
package powerreset package reset
import ( import (
"fmt" "fmt"
@@ -17,14 +17,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
nodeDB, err := node.New() nodeDB, err := node.New()
if err != nil { if err != nil {
wwlog.Error("Could not open node configuration: %s", err) return fmt.Errorf("could not open node configuration: %s", err)
os.Exit(1)
} }
nodes, err := nodeDB.FindAllNodes() nodes, err := nodeDB.FindAllNodes()
if err != nil { if err != nil {
wwlog.Error("Cloud not get nodeList: %s", err) return fmt.Errorf("cloud not get nodeList: %s", err)
os.Exit(1)
} }
if len(args) > 0 { if len(args) > 0 {
@@ -36,8 +34,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
if len(nodes) == 0 { if len(nodes) == 0 {
fmt.Printf("No nodes found\n") return fmt.Errorf("no nodes found")
os.Exit(1)
} }
batchpool := batch.New(50) batchpool := batch.New(50)

View File

@@ -1,4 +1,4 @@
package powerreset package reset
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"

View File

@@ -1,4 +1,4 @@
package powersoft package soft
import ( import (
"fmt" "fmt"
@@ -17,14 +17,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
nodeDB, err := node.New() nodeDB, err := node.New()
if err != nil { if err != nil {
wwlog.Error("Could not open node configuration: %s", err) return fmt.Errorf("could not open node configuration: %s", err)
os.Exit(1)
} }
nodes, err := nodeDB.FindAllNodes() nodes, err := nodeDB.FindAllNodes()
if err != nil { if err != nil {
wwlog.Error("Cloud not get nodeList: %s", err) return fmt.Errorf("could not get nodeList: %s", err)
os.Exit(1)
} }
if len(args) > 0 { if len(args) > 0 {
@@ -36,8 +34,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
if len(nodes) == 0 { if len(nodes) == 0 {
fmt.Printf("No nodes found\n") return fmt.Errorf("no nodes found")
os.Exit(1)
} }
batchpool := batch.New(50) batchpool := batch.New(50)

View File

@@ -1,4 +1,4 @@
package powersoft package soft
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"

View File

@@ -1,4 +1,4 @@
package powerstatus package status
import ( import (
"fmt" "fmt"
@@ -17,14 +17,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
nodeDB, err := node.New() nodeDB, err := node.New()
if err != nil { if err != nil {
wwlog.Error("Could not open node configuration: %s", err) return fmt.Errorf("could not open node configuration: %s", err)
os.Exit(1)
} }
nodes, err := nodeDB.FindAllNodes() nodes, err := nodeDB.FindAllNodes()
if err != nil { if err != nil {
wwlog.Error("Could not get node list: %s", err) return fmt.Errorf("could not get node list: %s", err)
os.Exit(1)
} }
if len(args) > 0 { if len(args) > 0 {
@@ -36,8 +34,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} }
if len(nodes) == 0 { if len(nodes) == 0 {
fmt.Printf("No nodes found\n") return fmt.Errorf("no nodes found")
os.Exit(1)
} }
batchpool := batch.New(50) batchpool := batch.New(50)

View File

@@ -1,4 +1,4 @@
package powerstatus package status
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"