From 444c0924f1b11bc18431870fa44d0462fb29286b Mon Sep 17 00:00:00 2001 From: Jonathon Anderson Date: Mon, 10 Feb 2025 12:10:21 -0700 Subject: [PATCH] Don't add "default" profile to new nodes if it does not exist. - Fixes: #1721 Signed-off-by: Jonathon Anderson --- CHANGELOG.md | 1 + internal/app/wwctl/node/add/main.go | 6 ++- internal/app/wwctl/node/add/main_test.go | 69 +++++++----------------- 3 files changed, 24 insertions(+), 52 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f389a2f9..c542d207 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fixed completions for `wwctl` commands. - Return "" when NetDev.IpCIDR is empty. - Updated `wwctl node export` to include node IDs. #1718 +- Don't add "default" profile to new nodes if it does not exist. #1721 ### Removed diff --git a/internal/app/wwctl/node/add/main.go b/internal/app/wwctl/node/add/main.go index 3a472513..25811322 100644 --- a/internal/app/wwctl/node/add/main.go +++ b/internal/app/wwctl/node/add/main.go @@ -54,7 +54,11 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) error { delete(vars.nodeConf.Disks, "UNDEF") vars.nodeConf.Ipmi.Tags = vars.nodeAdd.IpmiTagsAdd if len(vars.nodeConf.Profiles) == 0 { - vars.nodeConf.Profiles = []string{"default"} + if registry, err := node.New(); err == nil { + if _, err := registry.GetProfile("default"); err == nil { + vars.nodeConf.Profiles = []string{"default"} + } + } } buffer, err := yaml.Marshal(vars.nodeConf) if err != nil { diff --git a/internal/app/wwctl/node/add/main_test.go b/internal/app/wwctl/node/add/main_test.go index 728fa53c..b0734826 100644 --- a/internal/app/wwctl/node/add/main_test.go +++ b/internal/app/wwctl/node/add/main_test.go @@ -16,7 +16,7 @@ func Test_Add(t *testing.T) { args []string wantErr bool stdout string - chkout bool + inDb string outDb string }{ {name: "single node add", @@ -24,11 +24,23 @@ func Test_Add(t *testing.T) { wantErr: false, stdout: "", outDb: `nodeprofiles: {} +nodes: + n01: {} +`}, + {name: "single node add with default profile", + args: []string{"n01"}, + wantErr: false, + stdout: "", + inDb: ` +nodeprofiles: + default: {}`, + outDb: ` +nodeprofiles: + default: {} nodes: n01: profiles: - - default -`}, + - default`}, {name: "single node add, profile foo", args: []string{"--profile=foo", "n01"}, wantErr: false, @@ -47,8 +59,6 @@ nodes: nodes: n01: discoverable: "true" - profiles: - - default `}, {name: "single node add, discoverable true, implicit", args: []string{"--discoverable", "n01"}, @@ -58,14 +68,11 @@ nodes: nodes: n01: discoverable: "true" - profiles: - - default `}, {name: "single node add, discoverable wrong argument", args: []string{"--discoverable=maybe", "n01"}, wantErr: true, stdout: "", - chkout: false, outDb: `nodeprofiles: {} nodes: {} `}, @@ -77,8 +84,6 @@ nodes: {} nodes: n01: discoverable: "false" - profiles: - - default `}, {name: "single node add with Kernel args", args: []string{"--kernelargs=foo", "n01"}, @@ -90,8 +95,6 @@ nodes: kernel: args: - foo - profiles: - - default `}, {name: "double node add explicit", args: []string{"n01", "n02"}, @@ -99,12 +102,8 @@ nodes: stdout: "", outDb: `nodeprofiles: {} nodes: - n01: - profiles: - - default - n02: - profiles: - - default + n01: {} + n02: {} `}, {name: "single node with ipaddr6", args: []string{"--ipaddr6=fdaa::1", "n01"}, @@ -113,8 +112,6 @@ nodes: outDb: `nodeprofiles: {} nodes: n01: - profiles: - - default network devices: default: ip6addr: fdaa::1 @@ -126,8 +123,6 @@ nodes: outDb: `nodeprofiles: {} nodes: n01: - profiles: - - default network devices: default: ipaddr: 10.0.0.1 @@ -136,7 +131,6 @@ nodes: args: []string{"--ipaddr=10.0.1", "n01"}, wantErr: true, stdout: "", - chkout: false, outDb: `nodeprofiles: {} nodes: {} `}, @@ -147,20 +141,14 @@ nodes: {} outDb: `nodeprofiles: {} nodes: n01: - profiles: - - default network devices: default: ipaddr: 10.10.0.1 n02: - profiles: - - default network devices: default: ipaddr: 10.10.0.2 n03: - profiles: - - default network devices: default: ipaddr: 10.10.0.3 @@ -172,20 +160,14 @@ nodes: outDb: `nodeprofiles: {} nodes: n01: - profiles: - - default network devices: foo: ipaddr: 10.10.0.1 n02: - profiles: - - default network devices: foo: ipaddr: 10.10.0.2 n03: - profiles: - - default network devices: foo: ipaddr: 10.10.0.3 @@ -199,24 +181,18 @@ nodes: n01: ipmi: ipaddr: 10.20.0.1 - profiles: - - default network devices: foo: ipaddr: 10.10.0.1 n02: ipmi: ipaddr: 10.20.0.2 - profiles: - - default network devices: foo: ipaddr: 10.10.0.2 n03: ipmi: ipaddr: 10.20.0.3 - profiles: - - default network devices: foo: ipaddr: 10.10.0.3 @@ -228,8 +204,6 @@ nodes: outDb: `nodeprofiles: {} nodes: n01: - profiles: - - default filesystems: /dev/vda1: path: /var @@ -248,8 +222,6 @@ nodes: {} outDb: `nodeprofiles: {} nodes: n01: - profiles: - - default disks: /dev/vda: partitions: @@ -266,8 +238,6 @@ nodes: outDb: `nodeprofiles: {} nodes: n01: - profiles: - - default disks: /dev/vda: partitions: @@ -282,7 +252,7 @@ nodes: warewulfd.SetNoDaemon() for _, tt := range tests { env := testenv.New(t) - env.WriteFile("etc/warewulf/nodes.conf", ``) + env.WriteFile("etc/warewulf/nodes.conf", tt.inDb) var err error t.Run(tt.name, func(t *testing.T) { baseCmd := GetCommand() @@ -300,9 +270,6 @@ nodes: assert.NoError(t, configErr) dumpBytes, _ := config.Dump() assert.YAMLEq(t, tt.outDb, string(dumpBytes)) - if tt.chkout { - assert.Equal(t, tt.outDb, buf.String()) - } }) } }