From 51786b5e4a3bd3d58ff302bb807e34a07c659635 Mon Sep 17 00:00:00 2001 From: Jonathon Anderson Date: Tue, 1 Apr 2025 16:48:43 -0600 Subject: [PATCH] Fix a panic during `wwctl node list --ipmi` for nodes with no ipmi configuration. #1847 Signed-off-by: Jonathon Anderson --- CHANGELOG.md | 1 + internal/app/wwctl/node/list/main_test.go | 12 ++++++++++++ internal/pkg/api/node/list.go | 15 +++++++++++---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93ebd987..6628d0f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Actually cause grub to sleep and reboot when log messages indiacte. #1838 - Fixed issue with importing new nodes from yaml. #1842 - `wwctl upgrade nodes --replace-overlays` avoids applying overlays multiple times. #1823 +- Fix a panic during `wwctl node list --ipmi` for nodes with no ipmi configuration. #1847 ### Changed diff --git a/internal/app/wwctl/node/list/main_test.go b/internal/app/wwctl/node/list/main_test.go index 013cea36..3281d771 100644 --- a/internal/app/wwctl/node/list/main_test.go +++ b/internal/app/wwctl/node/list/main_test.go @@ -187,6 +187,18 @@ nodes: profiles: - default `, + }, + { + name: "node list with no ipmi data", + args: []string{"--ipmi"}, + wantErr: false, + stdout: ` +NODE IPMI IPADDR IPMI PORT IPMI USERNAME IPMI INTERFACE +---- ----------- --------- ------------- -------------- +n1 -- -- -- --`, + inDb: ` +nodes: + n1: {}`, }, { name: "node list profile with ipmi user", diff --git a/internal/pkg/api/node/list.go b/internal/pkg/api/node/list.go index eafdabb4..abe1b2c5 100644 --- a/internal/pkg/api/node/list.go +++ b/internal/pkg/api/node/list.go @@ -64,13 +64,20 @@ func NodeList(nodeGet *wwapiv1.GetNodeList) (nodeList wwapiv1.NodeList, err erro nodeList.Output = append(nodeList.Output, fmt.Sprintf("%s:=:%s:=:%s:=:%s:=:%s", "NODE", "IPMI IPADDR", "IPMI PORT", "IPMI USERNAME", "IPMI INTERFACE")) for _, n := range node.FilterNodeListByName(nodes, nodeGet.Nodes) { + ipaddr, port, username, iface := "", "", "", "" + if n.Ipmi != nil { + ipaddr = n.Ipmi.Ipaddr.String() + port = n.Ipmi.Port + username = n.Ipmi.UserName + iface = n.Ipmi.Interface + } nodeList.Output = append(nodeList.Output, fmt.Sprintf("%s:=:%s:=:%s:=:%s:=:%s", n.Id(), - n.Ipmi.Ipaddr.String(), - n.Ipmi.Port, - n.Ipmi.UserName, - n.Ipmi.Interface)) + ipaddr, + port, + username, + iface)) } } else if nodeGet.Type == wwapiv1.GetNodeList_Long { nodeList.Output = append(nodeList.Output,