Rename "container" to "image"

- Updated `wwctl upgrade` to handle updates
- Maintained `.Container` and `.ContainerName` in tstruct
- Added `ContainerName()` methods to node and profile objects
- Added `--container`, `-C` aliases to wwctl commands (`<node|profile> <add|set>`)
- Added `wwctl container` alias
- Added support for `container_exit.sh` if `image_exit.sh` is not found

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2025-01-18 17:34:48 -07:00
parent 96396ed47e
commit 45a690ca4e
142 changed files with 2212 additions and 2183 deletions

View File

@@ -0,0 +1,76 @@
package list
import (
"bytes"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
"github.com/warewulf/warewulf/internal/pkg/testenv"
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
"github.com/warewulf/warewulf/internal/pkg/wwlog"
)
func Test_List(t *testing.T) {
tests := []struct {
name string
args []string
stdout string
inDb string
mockFunc func()
}{
{
name: "image list test",
args: []string{"-l"},
stdout: `
IMAGE NAME NODES KERNEL VERSION CREATION TIME MODIFICATION TIME SIZE
---------- ----- -------------- ------------- ----------------- ----
test 1 kernel 01 Jan 70 00:00 UTC 01 Jan 70 00:00 UTC 0 B
`,
inDb: `
nodeprofiles:
default: {}
nodes:
n01:
profiles:
- default
`,
mockFunc: func() {
imageList = func() (imageInfo []*wwapiv1.ImageInfo, err error) {
imageInfo = append(imageInfo, &wwapiv1.ImageInfo{
Name: "test",
NodeCount: 1,
KernelVersion: "kernel",
CreateDate: uint64(time.Unix(0, 0).Unix()),
ModDate: uint64(time.Unix(0, 0).Unix()),
Size: uint64(1),
})
return
}
},
},
}
warewulfd.SetNoDaemon()
for _, tt := range tests {
env := testenv.New(t)
defer env.RemoveAll()
env.WriteFile("etc/warewulf/nodes.conf", tt.inDb)
t.Logf("Running test: %s\n", tt.name)
t.Run(tt.name, func(t *testing.T) {
tt.mockFunc()
buf := new(bytes.Buffer)
baseCmd := GetCommand()
baseCmd.SetArgs(tt.args)
baseCmd.SetOut(buf)
baseCmd.SetErr(buf)
wwlog.SetLogWriter(buf)
err := baseCmd.Execute()
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(tt.stdout), strings.TrimSpace(buf.String()))
})
}
}