Skip to content

Commit

Permalink
Merge pull request warewulf#1036 from JasonYangShadow/issue/1024
Browse files Browse the repository at this point in the history
Fix error when editing node
  • Loading branch information
anderbubble authored Jan 31, 2024
2 parents c0e5d4b + cd0ef5c commit 705bb8c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Create `/etc/systemd/network/10-persistent-net-<netdev>.link` file per network device
- Fix the issue that the same tag added in `node set` is ignored. #967
- Change too-verbose warning message level from `Warn` to `Debug`. #1025
- Fixed a bug where error occurs when editing node. #1024

### Changed

Expand Down
9 changes: 6 additions & 3 deletions internal/app/wwctl/node/edit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import (
)

func CobraRunE(cmd *cobra.Command, args []string) error {
canWrite := apiutil.CanWriteConfig()
canWrite, err := apiutil.CanWriteConfig()
if err != nil {
wwlog.Error("While checking whether can write config, err: %w", err)
os.Exit(1)
}
if !canWrite.CanWriteConfig {
wwlog.Error("Can't write to config exiting")
os.Exit(1)
Expand Down Expand Up @@ -112,8 +116,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if yes {
err = apinode.NodeDelete(&wwapiv1.NodeDeleteParameter{NodeNames: nodeList, Force: true})
if err != nil {
wwlog.Error("Problem deleting nodes before modification: %s", err)
return err
wwlog.Verbose("Problem deleting nodes before modification %s", err)
}
buffer, _ = yaml.Marshal(modifiedNodeMap)
newHash := apinode.Hash()
Expand Down
1 change: 1 addition & 0 deletions internal/app/wwctl/node/edit/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
for _, node := range nodes {
node_names = append(node_names, node.Id.Get())
}

return node_names, cobra.ShellCompDirectiveNoFileComp
},
}
Expand Down
8 changes: 6 additions & 2 deletions internal/app/wwctl/profile/edit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import (
)

func CobraRunE(cmd *cobra.Command, args []string) error {
canWrite := apiutil.CanWriteConfig()
canWrite, err := apiutil.CanWriteConfig()
if err != nil {
wwlog.Error("While checking whether can write config, err: %w", err)
os.Exit(1)
}
if !canWrite.CanWriteConfig {
wwlog.Error("Can't write to config exiting")
os.Exit(1)
Expand Down Expand Up @@ -112,7 +116,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
err = apiprofile.ProfileDelete(&wwapiv1.NodeDeleteParameter{NodeNames: pList, Force: true})

if err != nil {
wwlog.Verbose("Problem deleting nodes before modification %s")
wwlog.Verbose("Problem deleting nodes before modification %s", err)
}
buffer, _ = yaml.Marshal(modifiedProfileMap)
newHash := apinode.Hash()
Expand Down
15 changes: 12 additions & 3 deletions internal/pkg/api/util/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package util

import (
"fmt"
"syscall"

"github.com/manifoldco/promptui"
Expand Down Expand Up @@ -28,14 +29,22 @@ func ConfirmationPrompt(label string) (yes bool) {
/*
Simple check if the config can be written in case wwctl isn't run as root
*/
func CanWriteConfig() (canwrite *wwapiv1.CanWriteConfig) {
func CanWriteConfig() (canwrite *wwapiv1.CanWriteConfig, err error) {
canwrite = new(wwapiv1.CanWriteConfig)
err := syscall.Access(node.ConfigFile, syscall.O_RDWR)
// node is not initialized yet
if node.ConfigFile == "" {
_, err := node.New()
if err != nil {
canwrite.CanWriteConfig = false
return canwrite, fmt.Errorf("unable to initialize the node %w", err)
}
}
err = syscall.Access(node.ConfigFile, syscall.O_RDWR)
if err != nil {
wwlog.Warn("Couldn't open %s:%s", node.ConfigFile, err)
canwrite.CanWriteConfig = false
} else {
canwrite.CanWriteConfig = true
}
return canwrite
return canwrite, err
}

0 comments on commit 705bb8c

Please sign in to comment.