Merge pull request #1036 from JasonYangShadow/issue/1024
Fix error when editing node
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
@@ -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()
|
||||
|
||||
@@ -23,6 +23,7 @@ var (
|
||||
for _, node := range nodes {
|
||||
node_names = append(node_names, node.Id.Get())
|
||||
}
|
||||
|
||||
return node_names, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
@@ -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()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
|
||||
"github.com/manifoldco/promptui"
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user