Configure nodes.conf path dynamically from config
Removes the use of init() to initialize the variable. - Closes: #1596 - See also: #1569 Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
@@ -15,9 +15,6 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
|
||||
@@ -12,9 +12,6 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
|
||||
@@ -13,9 +13,6 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
|
||||
@@ -17,9 +17,6 @@ var (
|
||||
keyTypes []string
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
baseCmd.PersistentFlags().StringArrayVarP(&keyTypes, "keytypes", "t", []string{}, "ssh key types to be created")
|
||||
|
||||
@@ -26,7 +26,6 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Nothing to do here
|
||||
baseCmd.PersistentFlags().BoolVarP(&Build, "build", "b", false, "Build container after copy")
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ var baseCmd = &cobra.Command{
|
||||
var SetBuild bool
|
||||
|
||||
func init() {
|
||||
// Nothing to do here
|
||||
baseCmd.PersistentFlags().BoolVarP(&SetBuild, "build", "b", false, "Build container after rename")
|
||||
}
|
||||
|
||||
|
||||
@@ -14,9 +14,6 @@ var (
|
||||
Zsh bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
|
||||
@@ -15,9 +15,6 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
|
||||
@@ -14,9 +14,6 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
|
||||
@@ -14,9 +14,6 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
}
|
||||
|
||||
@@ -29,9 +29,6 @@ var (
|
||||
NoHeader bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
|
||||
@@ -2,14 +2,11 @@ package list
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||
|
||||
"github.com/warewulf/warewulf/internal/pkg/testenv"
|
||||
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
@@ -396,30 +393,14 @@ NODE FIELD PROFILE VALUE
|
||||
},
|
||||
}
|
||||
|
||||
conf_yml := ``
|
||||
tempWarewulfConf, warewulfConfErr := os.CreateTemp("", "warewulf.conf-")
|
||||
assert.NoError(t, warewulfConfErr)
|
||||
defer os.Remove(tempWarewulfConf.Name())
|
||||
_, warewulfConfErr = tempWarewulfConf.Write([]byte(conf_yml))
|
||||
assert.NoError(t, warewulfConfErr)
|
||||
assert.NoError(t, tempWarewulfConf.Sync())
|
||||
assert.NoError(t, warewulfconf.New().Read(tempWarewulfConf.Name()))
|
||||
|
||||
tempNodeConf, nodesConfErr := os.CreateTemp("", "nodes.conf-")
|
||||
assert.NoError(t, nodesConfErr)
|
||||
defer os.Remove(tempNodeConf.Name())
|
||||
node.ConfigFile = tempNodeConf.Name()
|
||||
warewulfd.SetNoDaemon()
|
||||
for _, tt := range tests {
|
||||
var err error
|
||||
_, err = tempNodeConf.Seek(0, 0)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, tempNodeConf.Truncate(0))
|
||||
_, err = tempNodeConf.Write([]byte(tt.inDb))
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, tempNodeConf.Sync())
|
||||
env := testenv.New(t)
|
||||
defer env.RemoveAll(t)
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
env.WriteFile(t, "etc/warewulf/nodes.conf", tt.inDb)
|
||||
|
||||
baseCmd := GetCommand()
|
||||
baseCmd.SetArgs(tt.args)
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
@@ -2,12 +2,9 @@ package set
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||
"github.com/warewulf/warewulf/internal/pkg/testenv"
|
||||
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
@@ -646,19 +643,6 @@ nodes:
|
||||
},
|
||||
}
|
||||
|
||||
conf_yml := ``
|
||||
tempWarewulfConf, warewulfConfErr := os.CreateTemp("", "warewulf.conf-")
|
||||
assert.NoError(t, warewulfConfErr)
|
||||
defer os.Remove(tempWarewulfConf.Name())
|
||||
_, warewulfConfErr = tempWarewulfConf.Write([]byte(conf_yml))
|
||||
assert.NoError(t, warewulfConfErr)
|
||||
assert.NoError(t, tempWarewulfConf.Sync())
|
||||
assert.NoError(t, warewulfconf.New().Read(tempWarewulfConf.Name()))
|
||||
|
||||
tempNodeConf, nodesConfErr := os.CreateTemp("", "nodes.conf-")
|
||||
assert.NoError(t, nodesConfErr)
|
||||
defer os.Remove(tempNodeConf.Name())
|
||||
node.ConfigFile = tempNodeConf.Name()
|
||||
warewulfd.SetNoDaemon()
|
||||
for _, tt := range tests {
|
||||
run_test(t, tt)
|
||||
|
||||
@@ -29,9 +29,6 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
|
||||
@@ -28,9 +28,6 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
|
||||
@@ -16,9 +16,6 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
return baseCmd
|
||||
|
||||
@@ -20,8 +20,6 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
// baseCmd.PersistentFlags().BoolVarP(&test, "test", "t", false, "Testing.")
|
||||
|
||||
baseCmd.AddCommand(powercycle.GetCommand())
|
||||
baseCmd.AddCommand(poweroff.GetCommand())
|
||||
baseCmd.AddCommand(poweron.GetCommand())
|
||||
|
||||
@@ -8,8 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||
"github.com/warewulf/warewulf/internal/pkg/testenv"
|
||||
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
@@ -96,31 +95,13 @@ nodes:
|
||||
},
|
||||
}
|
||||
|
||||
conf_yml := ``
|
||||
tempWarewulfConf, warewulfConfErr := os.CreateTemp("", "warewulf.conf-")
|
||||
assert.NoError(t, warewulfConfErr)
|
||||
defer os.Remove(tempWarewulfConf.Name())
|
||||
_, warewulfConfErr = tempWarewulfConf.Write([]byte(conf_yml))
|
||||
assert.NoError(t, warewulfConfErr)
|
||||
assert.NoError(t, tempWarewulfConf.Sync())
|
||||
assert.NoError(t, warewulfconf.New().Read(tempWarewulfConf.Name()))
|
||||
|
||||
tempNodeConf, nodesConfErr := os.CreateTemp("", "nodes.conf-")
|
||||
assert.NoError(t, nodesConfErr)
|
||||
defer os.Remove(tempNodeConf.Name())
|
||||
node.ConfigFile = tempNodeConf.Name()
|
||||
warewulfd.SetNoDaemon()
|
||||
for _, tt := range tests {
|
||||
var err error
|
||||
_, err = tempNodeConf.Seek(0, 0)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, tempNodeConf.Truncate(0))
|
||||
_, err = tempNodeConf.Write([]byte(tt.inDb))
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, tempNodeConf.Sync())
|
||||
assert.NoError(t, err)
|
||||
env := testenv.New(t)
|
||||
defer env.RemoveAll(t)
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
env.WriteFile(t, "etc/warewulf/nodes.conf", tt.inDb)
|
||||
baseCmd := GetCommand()
|
||||
baseCmd.SetArgs(tt.args)
|
||||
stdoutR, stdoutW, _ := os.Pipe()
|
||||
@@ -270,28 +251,12 @@ nodes:
|
||||
},
|
||||
}
|
||||
|
||||
conf_yml := ``
|
||||
tempWarewulfConf, warewulfConfErr := os.CreateTemp("", "warewulf.conf-")
|
||||
assert.NoError(t, warewulfConfErr)
|
||||
defer os.Remove(tempWarewulfConf.Name())
|
||||
_, warewulfConfErr = tempWarewulfConf.Write([]byte(conf_yml))
|
||||
assert.NoError(t, warewulfConfErr)
|
||||
assert.NoError(t, tempWarewulfConf.Sync())
|
||||
assert.NoError(t, warewulfconf.New().Read(tempWarewulfConf.Name()))
|
||||
|
||||
tempNodeConf, nodesConfErr := os.CreateTemp("", "nodes.conf-")
|
||||
assert.NoError(t, nodesConfErr)
|
||||
defer os.Remove(tempNodeConf.Name())
|
||||
node.ConfigFile = tempNodeConf.Name()
|
||||
warewulfd.SetNoDaemon()
|
||||
env := testenv.New(t)
|
||||
defer env.RemoveAll(t)
|
||||
|
||||
for _, tt := range tests {
|
||||
var err error
|
||||
_, err = tempNodeConf.Seek(0, 0)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, tempNodeConf.Truncate(0))
|
||||
_, err = tempNodeConf.Write([]byte(tt.inDb))
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, tempNodeConf.Sync())
|
||||
env.WriteFile(t, "etc/warewulf/nodes.conf", tt.inDb)
|
||||
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
baseCmd := GetCommand()
|
||||
|
||||
@@ -59,7 +59,7 @@ func init() {
|
||||
rootCmd.AddCommand(ssh.GetCommand())
|
||||
rootCmd.AddCommand(genconf.GetCommand())
|
||||
rootCmd.AddCommand(clean.GetCommand())
|
||||
rootCmd.AddCommand(upgrade.Command)
|
||||
rootCmd.AddCommand(upgrade.GetCommand())
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
|
||||
@@ -7,17 +7,15 @@ import (
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/upgrade/nodes"
|
||||
)
|
||||
|
||||
var (
|
||||
Command = &cobra.Command{
|
||||
func GetCommand() *cobra.Command {
|
||||
command := &cobra.Command{
|
||||
DisableFlagsInUseLine: true,
|
||||
Use: "upgrade <config|nodes> [OPTIONS]",
|
||||
Short: "Upgrade configuration files",
|
||||
Long: `Upgrade warewulf.conf or nodes.conf from a previous version of Warewulf 4 to a format
|
||||
supported by the current version.`,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
Command.AddCommand(config.Command)
|
||||
Command.AddCommand(nodes.Command)
|
||||
command.AddCommand(config.GetCommand())
|
||||
command.AddCommand(nodes.GetCommand())
|
||||
return command
|
||||
}
|
||||
|
||||
@@ -7,12 +7,17 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/warewulf/warewulf/internal/pkg/config"
|
||||
libupgrade "github.com/warewulf/warewulf/internal/pkg/upgrade"
|
||||
"github.com/warewulf/warewulf/internal/pkg/upgrade"
|
||||
"github.com/warewulf/warewulf/internal/pkg/util"
|
||||
)
|
||||
|
||||
var (
|
||||
Command = &cobra.Command{
|
||||
inputPath string
|
||||
outputPath string
|
||||
)
|
||||
|
||||
func GetCommand() *cobra.Command {
|
||||
command := &cobra.Command{
|
||||
DisableFlagsInUseLine: true,
|
||||
Use: "config [OPTIONS]",
|
||||
Short: "Upgrade an existing warewulf.conf",
|
||||
@@ -20,14 +25,9 @@ var (
|
||||
supported by the current version.`,
|
||||
RunE: UpgradeNodesConf,
|
||||
}
|
||||
|
||||
inputPath string
|
||||
outputPath string
|
||||
)
|
||||
|
||||
func init() {
|
||||
Command.Flags().StringVarP(&inputPath, "input-path", "i", config.ConfigFile, "Path to a legacy warewulf.conf")
|
||||
Command.Flags().StringVarP(&outputPath, "output-path", "o", config.ConfigFile, "Path to write the upgraded warewulf.conf to")
|
||||
command.Flags().StringVarP(&inputPath, "input-path", "i", config.ConfigFile, "Path to a legacy warewulf.conf")
|
||||
command.Flags().StringVarP(&outputPath, "output-path", "o", config.ConfigFile, "Path to write the upgraded warewulf.conf to")
|
||||
return command
|
||||
}
|
||||
|
||||
func UpgradeNodesConf(cmd *cobra.Command, args []string) error {
|
||||
@@ -35,7 +35,7 @@ func UpgradeNodesConf(cmd *cobra.Command, args []string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
legacy, err := libupgrade.ParseConfig(data)
|
||||
legacy, err := upgrade.ParseConfig(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -6,13 +6,20 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||
libupgrade "github.com/warewulf/warewulf/internal/pkg/upgrade"
|
||||
"github.com/warewulf/warewulf/internal/pkg/config"
|
||||
"github.com/warewulf/warewulf/internal/pkg/upgrade"
|
||||
"github.com/warewulf/warewulf/internal/pkg/util"
|
||||
)
|
||||
|
||||
var (
|
||||
Command = &cobra.Command{
|
||||
addDefaults bool
|
||||
replaceOverlays bool
|
||||
inputPath string
|
||||
outputPath string
|
||||
)
|
||||
|
||||
func GetCommand() *cobra.Command {
|
||||
command := &cobra.Command{
|
||||
DisableFlagsInUseLine: true,
|
||||
Use: "nodes [OPTIONS]",
|
||||
Short: "Upgrade an existing nodes.conf",
|
||||
@@ -20,32 +27,33 @@ var (
|
||||
supported by the current version.`,
|
||||
RunE: UpgradeNodesConf,
|
||||
}
|
||||
|
||||
addDefaults bool
|
||||
replaceOverlays bool
|
||||
inputPath string
|
||||
outputPath string
|
||||
)
|
||||
|
||||
func init() {
|
||||
Command.Flags().BoolVar(&addDefaults, "add-defaults", false, "Configure a default profile and set default node values")
|
||||
Command.Flags().BoolVar(&replaceOverlays, "replace-overlays", false, "Replace 'wwinit' and 'generic' overlays with their split replacements")
|
||||
Command.Flags().StringVarP(&inputPath, "input-path", "i", node.ConfigFile, "Path to a legacy nodes.conf")
|
||||
Command.Flags().StringVarP(&outputPath, "output-path", "o", node.ConfigFile, "Path to write the upgraded nodes.conf to")
|
||||
if err := Command.MarkFlagRequired("add-defaults"); err != nil {
|
||||
command.Flags().BoolVar(&addDefaults, "add-defaults", false, "Configure a default profile and set default node values")
|
||||
command.Flags().BoolVar(&replaceOverlays, "replace-overlays", false, "Replace 'wwinit' and 'generic' overlays with their split replacements")
|
||||
command.Flags().StringVarP(&inputPath, "input-path", "i", "", "Path to a legacy nodes.conf")
|
||||
command.Flags().StringVarP(&outputPath, "output-path", "o", "", "Path to write the upgraded nodes.conf to")
|
||||
if err := command.MarkFlagRequired("add-defaults"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := Command.MarkFlagRequired("replace-overlays"); err != nil {
|
||||
if err := command.MarkFlagRequired("replace-overlays"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return command
|
||||
}
|
||||
|
||||
func UpgradeNodesConf(cmd *cobra.Command, args []string) error {
|
||||
inputPath := inputPath
|
||||
if inputPath == "" {
|
||||
inputPath = config.Get().Paths.NodesConf()
|
||||
}
|
||||
outputPath := outputPath
|
||||
if outputPath == "" {
|
||||
outputPath = config.Get().Paths.NodesConf()
|
||||
}
|
||||
data, err := os.ReadFile(inputPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
legacy, err := libupgrade.ParseNodes(data)
|
||||
legacy, err := upgrade.ParseNodes(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user