Refine wwctl configure error handling

- Closes #1273

Signed-off-by: xu yang <xyang@ciq.com>
This commit is contained in:
xu yang
2024-08-08 06:43:00 +00:00
committed by Jonathon Anderson
parent a36427d1b2
commit 6212f40e4c
5 changed files with 19 additions and 28 deletions

View File

@@ -48,6 +48,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed
- Added a link to an example SELinux-enabled node image in documentation. #1305
- Refine error handling for `wwctl configure`. #1273
## v4.5.6, 2024-08-05

View File

@@ -2,7 +2,6 @@ package configure
import (
"fmt"
"os"
"github.com/pkg/errors"
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
@@ -20,18 +19,16 @@ func DHCP() (err error) {
controller := warewulfconf.Get()
if !controller.DHCP.Enabled {
wwlog.Info("This system is not configured as a Warewulf DHCP controller")
os.Exit(1)
wwlog.Warn("This system is not configured as a Warewulf DHCP controller, need to manually run `wwctl configure dhcp` later")
return
}
if controller.DHCP.RangeStart == "" {
wwlog.Error("Configuration is not defined: `dhcpd range start`")
os.Exit(1)
return fmt.Errorf("configuration is not defined: `dhcpd range start`")
}
if controller.DHCP.RangeEnd == "" {
wwlog.Error("Configuration is not defined: `dhcpd range end`")
os.Exit(1)
return fmt.Errorf("configuration is not defined: `dhcpd range end`")
}
if controller.Warewulf.EnableHostOverlay {
err = overlay.BuildHostOverlay()

View File

@@ -1,6 +1,7 @@
package configure
import (
"fmt"
"os"
"path"
@@ -8,17 +9,15 @@ import (
"github.com/warewulf/warewulf/internal/pkg/node"
"github.com/warewulf/warewulf/internal/pkg/overlay"
"github.com/warewulf/warewulf/internal/pkg/util"
"github.com/warewulf/warewulf/internal/pkg/wwlog"
)
/*
Creates '/etc/hosts' from the host template.
*/
func Hostfile() error {
func Hostfile() (err error) {
hostTemplate := path.Join(overlay.OverlaySourceDir("host"), "/etc/hosts.ww")
if !(util.IsFile(hostTemplate)) {
wwlog.Error("'the overlay template '/etc/hosts.ww' does not exists in 'host' overlay")
os.Exit(1)
return fmt.Errorf("'the overlay template '/etc/hosts.ww' does not exists in 'host' overlay")
}
nodeInfo := node.NewInfo()
@@ -29,13 +28,11 @@ func Hostfile() error {
hostTemplate,
tstruct)
if err != nil {
wwlog.Error("%s", err)
os.Exit(1)
return
}
info, err := os.Stat(hostTemplate)
if err != nil {
wwlog.Error("%s", err)
os.Exit(1)
return
}
if writeFile {
@@ -44,5 +41,5 @@ func Hostfile() error {
return errors.Wrap(err, "could not write file from template")
}
}
return nil
return
}

View File

@@ -23,8 +23,7 @@ func SSH(keyTypes ...string) error {
err := os.MkdirAll(path.Join(conf.Paths.Sysconfdir, "warewulf/keys"), 0755)
if err != nil {
wwlog.Error("Could not create base directory: %s", err)
os.Exit(1)
return fmt.Errorf("could not create base directory: %s", err)
}
for _, k := range keyTypes {
@@ -47,8 +46,7 @@ func SSH(keyTypes ...string) error {
homeDir, err := os.UserHomeDir()
if err != nil {
wwlog.Error("Could not obtain the user's home directory: %s", err)
os.Exit(1)
return fmt.Errorf("could not obtain the user's home directory: %s", err)
}
authorizedKeys := path.Join(homeDir, "/.ssh/authorized_keys")

View File

@@ -10,14 +10,13 @@ import (
"github.com/warewulf/warewulf/internal/pkg/wwlog"
)
func TFTP() error {
func TFTP() (err error) {
controller := warewulfconf.Get()
var tftpdir string = path.Join(controller.TFTP.TftpRoot, "warewulf")
err := os.MkdirAll(tftpdir, 0755)
err = os.MkdirAll(tftpdir, 0755)
if err != nil {
wwlog.Error("%s", err)
return err
return
}
if controller.Warewulf.GrubBoot {
@@ -43,15 +42,14 @@ func TFTP() error {
}
}
if !controller.TFTP.Enabled {
wwlog.Info("Warewulf does not auto start TFTP services due to disable by warewulf.conf")
os.Exit(0)
wwlog.Warn("Warewulf does not auto start TFTP services due to disable by warewulf.conf, need to manually run `wwctl configure tftp` later")
return nil
}
wwlog.Info("Enabling and restarting the TFTP services")
err = util.SystemdStart(controller.TFTP.SystemdName)
if err != nil {
wwlog.Error("%s", err)
return err
return
}
return nil