fix test to run without NodeInfo
Also removed --fullall from node list and profile list Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
committed by
Jonathon Anderson
parent
ffef31969e
commit
ac6cd69ca6
@@ -36,6 +36,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
- Updated IgnitionJson to sort filesystems. #1433
|
||||
- `wwctl node set` requires mandatory pattern input. #502
|
||||
|
||||
### Removed
|
||||
|
||||
- `wwctl node list --fullall` has been removed
|
||||
- `wwctl profile list --fullall` has been removed
|
||||
|
||||
### Fixed
|
||||
|
||||
- Update links on contributing page to point to warewulf repo.
|
||||
|
||||
@@ -2,14 +2,11 @@ package list
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"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"
|
||||
@@ -17,44 +14,50 @@ import (
|
||||
|
||||
func Test_List_Args(t *testing.T) {
|
||||
tests := []struct {
|
||||
args []string
|
||||
output string
|
||||
fail bool
|
||||
name string
|
||||
args []string
|
||||
stdout string
|
||||
inDb string
|
||||
mockFunc func()
|
||||
}{
|
||||
{args: []string{""},
|
||||
output: ` CONTAINER NAME
|
||||
test
|
||||
{
|
||||
name: "container list test",
|
||||
args: []string{"-l"},
|
||||
stdout: ` CONTAINER NAME NODES KERNEL VERSION CREATION TIME MODIFICATION TIME SIZE
|
||||
test 1 kernel`,
|
||||
inDb: `WW_INTERNAL: 43
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
nodes:
|
||||
n01:
|
||||
profiles:
|
||||
- default
|
||||
`,
|
||||
fail: false,
|
||||
},
|
||||
{args: []string{"-l"},
|
||||
output: ` CONTAINER NAME NODES KERNEL VERSION CREATION TIME MODIFICATION TIME SIZE
|
||||
test 0 02 Jan 00 03:04 UTC 01 Jan 70 00:00 UTC 0 B
|
||||
`,
|
||||
fail: false,
|
||||
},
|
||||
{args: []string{"-c"},
|
||||
output: ` CONTAINER NAME NODES SIZE
|
||||
test 0 37 B
|
||||
`,
|
||||
fail: false,
|
||||
mockFunc: func() {
|
||||
containerList = func() (containerInfo []*wwapiv1.ContainerInfo, err error) {
|
||||
containerInfo = append(containerInfo, &wwapiv1.ContainerInfo{
|
||||
Name: "test",
|
||||
NodeCount: 1,
|
||||
KernelVersion: "kernel",
|
||||
CreateDate: uint64(time.Unix(0, 0).Unix()),
|
||||
ModDate: uint64(time.Unix(0, 0).Unix()),
|
||||
Size: uint64(1),
|
||||
})
|
||||
return
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
env := testenv.New(t)
|
||||
env.WriteFile(t, path.Join(testenv.WWChrootdir, "test/rootfs/bin/sh"), `This is a fake shell, no pearls here.`)
|
||||
// need to touch the files, so that the creation date of the container is constant,
|
||||
// modification date of `../chroots/containername` is used as creation date.
|
||||
// modification dates of directories change every time a file or subdir is added
|
||||
// so we have to make it constant *after* its creation.
|
||||
cmd := exec.Command("touch", "-d", "2000-01-02 03:04:05 UTC",
|
||||
env.GetPath(path.Join(testenv.WWChrootdir, "test/rootfs")),
|
||||
env.GetPath(path.Join(testenv.WWChrootdir, "test")))
|
||||
err := cmd.Run()
|
||||
assert.NoError(t, err)
|
||||
defer env.RemoveAll(t)
|
||||
|
||||
warewulfd.SetNoDaemon()
|
||||
for _, tt := range tests {
|
||||
t.Run(strings.Join(tt.args, "_"), func(t *testing.T) {
|
||||
env := testenv.New(t)
|
||||
env.WriteFile(t, "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)
|
||||
stdoutR, stdoutW, _ := os.Pipe()
|
||||
|
||||
@@ -2,8 +2,6 @@ package rename
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
@@ -12,6 +10,7 @@ import (
|
||||
"github.com/warewulf/warewulf/internal/pkg/testenv"
|
||||
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
func Test_Rename(t *testing.T) {
|
||||
@@ -43,23 +42,14 @@ func Test_Rename(t *testing.T) {
|
||||
|
||||
func verifyContainerListOutput(t *testing.T, content string) {
|
||||
baseCmd := containerList.GetCommand()
|
||||
stdoutR, stdoutW, _ := os.Pipe()
|
||||
os.Stdout = stdoutW
|
||||
baseCmd.SetOut(os.Stdout)
|
||||
baseCmd.SetErr(os.Stdout)
|
||||
wwlog.SetLogWriter(os.Stdout)
|
||||
buf := new(bytes.Buffer)
|
||||
baseCmd.SetOut(buf)
|
||||
baseCmd.SetErr(buf)
|
||||
wwlog.SetLogWriterErr(buf)
|
||||
wwlog.SetLogWriterInfo(buf)
|
||||
err := baseCmd.Execute()
|
||||
assert.NoError(t, err)
|
||||
|
||||
stdoutC := make(chan string)
|
||||
go func() {
|
||||
var buf bytes.Buffer
|
||||
_, _ = io.Copy(&buf, stdoutR)
|
||||
stdoutC <- buf.String()
|
||||
}()
|
||||
stdoutW.Close()
|
||||
|
||||
stdout := <-stdoutC
|
||||
assert.NotEmpty(t, stdout, "output should not be empty")
|
||||
assert.Contains(t, stdout, content)
|
||||
assert.NotEmpty(t, buf.String(), "output should not be empty")
|
||||
assert.Contains(t, buf.String(), content)
|
||||
}
|
||||
|
||||
@@ -2,12 +2,11 @@ package add
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
@@ -54,8 +53,8 @@ nodes:
|
||||
profiles:
|
||||
- default
|
||||
`},
|
||||
{name: "single node add, discoverable true with yes",
|
||||
args: []string{"--discoverable=yes", "n01"},
|
||||
{name: "single node add, discoverable true, implicit",
|
||||
args: []string{"--discoverable", "n01"},
|
||||
wantErr: false,
|
||||
stdout: "",
|
||||
outDb: `WW_INTERNAL: 45
|
||||
@@ -258,7 +257,7 @@ nodeprofiles: {}
|
||||
nodes: {}
|
||||
`},
|
||||
{name: "one node with filesystem and partition ",
|
||||
args: []string{"--fsname=var", "--fspath=/var", "--partname=var", "--diskname=/dev/vda", "n01"},
|
||||
args: []string{"--fsname=var", "--fspath=/var", "--partname=var", "--diskname=/dev/vda", "--partnumber=1", "n01"},
|
||||
wantErr: false,
|
||||
stdout: "",
|
||||
outDb: `WW_INTERNAL: 45
|
||||
@@ -270,13 +269,14 @@ nodes:
|
||||
disks:
|
||||
/dev/vda:
|
||||
partitions:
|
||||
var: {}
|
||||
var:
|
||||
number: "1"
|
||||
filesystems:
|
||||
/dev/disk/by-partlabel/var:
|
||||
path: /var
|
||||
`},
|
||||
{name: "one node with filesystem with btrfs and partition ",
|
||||
args: []string{"--fsname=var", "--fspath=/var", "--fsformat=btrfs", "--partname=var", "--diskname=/dev/vda", "n01"},
|
||||
args: []string{"--fsname=var", "--fspath=/var", "--fsformat=btrfs", "--partname=var", "--diskname=/dev/vda", "--partnumber=1", "n01"},
|
||||
wantErr: false,
|
||||
stdout: "",
|
||||
outDb: `WW_INTERNAL: 45
|
||||
@@ -288,37 +288,21 @@ nodes:
|
||||
disks:
|
||||
/dev/vda:
|
||||
partitions:
|
||||
var: {}
|
||||
var:
|
||||
number: "1"
|
||||
filesystems:
|
||||
/dev/disk/by-partlabel/var:
|
||||
format: btrfs
|
||||
path: /var
|
||||
`},
|
||||
}
|
||||
conf_yml := `WW_INTERNAL: 0`
|
||||
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()))
|
||||
|
||||
nodes_yml := `WW_INTERNAL: 45`
|
||||
tempNodeConf, nodesConfErr := os.CreateTemp("", "nodes.conf-")
|
||||
assert.NoError(t, nodesConfErr)
|
||||
defer os.Remove(tempNodeConf.Name())
|
||||
node.ConfigFile = tempNodeConf.Name()
|
||||
// wwlog.SetLogLevel(wwlog.DEBUG)
|
||||
warewulfd.SetNoDaemon()
|
||||
for _, tt := range tests {
|
||||
env := testenv.New(t)
|
||||
env.WriteFile(t, "etc/warewulf/nodes.conf",
|
||||
`WW_INTERNAL: 45`)
|
||||
var err error
|
||||
_, err = tempNodeConf.Seek(0, 0)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, tempNodeConf.Truncate(0))
|
||||
_, err = tempNodeConf.Write([]byte(nodes_yml))
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, tempNodeConf.Sync())
|
||||
t.Logf("Running test: %s\n", tt.name)
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
baseCmd := GetCommand()
|
||||
baseCmd.SetArgs(tt.args)
|
||||
@@ -326,21 +310,17 @@ nodes:
|
||||
baseCmd.SetOut(buf)
|
||||
baseCmd.SetErr(buf)
|
||||
err = baseCmd.Execute()
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("Got unwanted error: %s", err)
|
||||
t.FailNow()
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
config, configErr := node.New()
|
||||
assert.NoError(t, configErr)
|
||||
dumpBytes, _ := config.Dump()
|
||||
dump := string(dumpBytes)
|
||||
if dump != tt.outDb {
|
||||
t.Errorf("DB dump is wrong, got:'%s'\nwant:'%s'", dump, tt.outDb)
|
||||
t.FailNow()
|
||||
}
|
||||
if tt.chkout && buf.String() != tt.stdout {
|
||||
t.Errorf("Got wrong output, got:'%s'\nwant:'%s'", buf.String(), tt.stdout)
|
||||
t.FailNow()
|
||||
assert.YAMLEq(t, tt.outDb, string(dumpBytes))
|
||||
if tt.chkout {
|
||||
assert.Equal(t, tt.outDb, buf.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -27,8 +27,6 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) (err err
|
||||
req.Type = wwapiv1.GetNodeList_Network
|
||||
} else if vars.showLong {
|
||||
req.Type = wwapiv1.GetNodeList_Long
|
||||
} else if vars.showFullAll {
|
||||
req.Type = wwapiv1.GetNodeList_FullAll
|
||||
} else if vars.showYaml {
|
||||
req.Type = wwapiv1.GetNodeList_YAML
|
||||
} else if vars.showJson {
|
||||
|
||||
@@ -2,15 +2,16 @@ package list
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/stretchr/testify/assert"
|
||||
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"
|
||||
)
|
||||
@@ -25,8 +26,8 @@ func Test_List(t *testing.T) {
|
||||
{
|
||||
name: "single node list",
|
||||
args: []string{},
|
||||
stdout: `NODE NAME PROFILES NETWORK
|
||||
n01 default
|
||||
stdout: ` NODE NAME PROFILES NETWORK
|
||||
n01 [default]
|
||||
`,
|
||||
inDb: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
@@ -40,9 +41,9 @@ nodes:
|
||||
{
|
||||
name: "multiple nodes list",
|
||||
args: []string{},
|
||||
stdout: `NODE NAME PROFILES NETWORK
|
||||
n01 default
|
||||
n02 default
|
||||
stdout: ` NODE NAME PROFILES NETWORK
|
||||
n01 [default]
|
||||
n02 [default]
|
||||
`,
|
||||
inDb: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
@@ -59,9 +60,9 @@ nodes:
|
||||
{
|
||||
name: "node list returns multiple nodes",
|
||||
args: []string{"n01,n02"},
|
||||
stdout: `NODE NAME PROFILES NETWORK
|
||||
n01 default
|
||||
n02 default
|
||||
stdout: ` NODE NAME PROFILES NETWORK
|
||||
n01 [default]
|
||||
n02 [default]
|
||||
`,
|
||||
inDb: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
@@ -78,9 +79,9 @@ nodes:
|
||||
{
|
||||
name: "node list returns multiple nodes (case 2)",
|
||||
args: []string{"n01,n03"},
|
||||
stdout: `NODE NAME PROFILES NETWORK
|
||||
n01 default
|
||||
n03 default
|
||||
stdout: ` NODE NAME PROFILES NETWORK
|
||||
n01 [default]
|
||||
n03 [default]
|
||||
`,
|
||||
inDb: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
@@ -106,8 +107,8 @@ nodes:
|
||||
{
|
||||
name: "node list returns one node",
|
||||
args: []string{"n01,"},
|
||||
stdout: `NODE NAME PROFILES NETWORK
|
||||
n01 default
|
||||
stdout: ` NODE NAME PROFILES NETWORK
|
||||
n01 [default]
|
||||
`,
|
||||
inDb: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
@@ -124,8 +125,8 @@ nodes:
|
||||
{
|
||||
name: "node list profile with network",
|
||||
args: []string{},
|
||||
stdout: `NODE NAME PROFILES NETWORK
|
||||
n01 default default
|
||||
stdout: ` NODE NAME PROFILES NETWORK
|
||||
n01 [default] default
|
||||
`,
|
||||
inDb: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
@@ -188,8 +189,8 @@ nodes:
|
||||
{
|
||||
name: "node list profile with ipmi user",
|
||||
args: []string{"-i"},
|
||||
stdout: `NODE NAME IPMI IPADDR IPMI PORT IPMI USERNAME IPMI INTERFACE
|
||||
n01 -- -- admin -- --
|
||||
stdout: `NODE IPMIIPADDR IPMIPORT IPMIUSERNAME IPMIINTERFACE
|
||||
n01 <nil> admin
|
||||
`,
|
||||
inDb: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
@@ -204,8 +205,8 @@ nodes:
|
||||
{
|
||||
name: "node list profile with ipmi user superseded",
|
||||
args: []string{"-i"},
|
||||
stdout: `NODE NAME IPMI IPADDR IPMI PORT IPMI USERNAME IPMI INTERFACE
|
||||
n01 -- -- user -- --
|
||||
stdout: `NODE IPMIIPADDR IPMIPORT IPMIUSERNAME IPMIINTERFACE
|
||||
n01 <nil> user
|
||||
`,
|
||||
inDb: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
@@ -232,8 +233,8 @@ nodes:
|
||||
`,
|
||||
name: "multiple profiles list",
|
||||
args: []string{},
|
||||
stdout: `NODE NAME PROFILES NETWORK
|
||||
n01 p1,p2
|
||||
stdout: ` NODE NAME PROFILES NETWORK
|
||||
n01 [p1 p2]
|
||||
`},
|
||||
{
|
||||
inDb: `WW_INTERNAL: 45
|
||||
@@ -330,16 +331,17 @@ n01 Profiles -- p1
|
||||
inDb: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
p1:
|
||||
system overlay:
|
||||
- profileinit
|
||||
runtime overlay:
|
||||
- rop1
|
||||
- rop2
|
||||
nodes:
|
||||
n01:
|
||||
profiles:
|
||||
- p1
|
||||
system overlay:
|
||||
- nodeinit
|
||||
runtime overlay:
|
||||
- nop1
|
||||
`,
|
||||
name: "prefer profile system overlay over node overlay",
|
||||
name: "multiple overlays list all",
|
||||
args: []string{"-a"},
|
||||
stdout: `NODE FIELD PROFILE VALUE
|
||||
n01 Id -- n01
|
||||
@@ -379,7 +381,17 @@ n01 Profiles -- p1
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
baseCmd := GetCommand()
|
||||
baseCmd.SetArgs(tt.args)
|
||||
verifyOutput(t, baseCmd, tt.stdout)
|
||||
//verifyOutput(t, baseCmd, tt.stdout)
|
||||
buf := new(bytes.Buffer)
|
||||
wwlog.SetLogWriter(buf)
|
||||
wwlog.SetLogWriterErr(buf)
|
||||
wwlog.SetLogWriterInfo(buf)
|
||||
err := baseCmd.Execute()
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, buf, "output should not be empty")
|
||||
assert.Contains(t, strings.ReplaceAll(buf.String(), " ", ""),
|
||||
strings.ReplaceAll(tt.stdout, " ", ""))
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -387,15 +399,16 @@ n01 Profiles -- p1
|
||||
func TestListMultipleFormats(t *testing.T) {
|
||||
t.Skip("temporally skip this test")
|
||||
tests := []struct {
|
||||
name string
|
||||
args []string
|
||||
output []string
|
||||
inDb string
|
||||
name string
|
||||
args []string
|
||||
stdout string
|
||||
inDb string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "single node list yaml output",
|
||||
args: []string{"-y"},
|
||||
output: []string{"n01:\n AssetKey: \"\"\n ClusterName: \"\"\n Comment: \"\"\n ContainerName: \"\"\n Discoverable: \"\"\n Disks: {}\n FileSystems: {}\n Grub: \"\"\n Id: |\n Source: explicit\n Value: n01\n Init: |\n Source: default-value\n Value: /sbin/init\n Ipmi:\n EscapeChar: \"\"\n Gateway: \"\"\n Interface: \"\"\n Ipaddr: \"\"\n Netmask: \"\"\n Password: \"\"\n Port: \"\"\n Tags: null\n UserName: \"\"\n Write: \"\"\n Ipxe: |\n Source: default-value\n Value: default\n Kernel:\n Args: |\n Source: default-value\n Value: quiet crashkernel=no vga=791 net.naming-scheme=v238\n Override: \"\"\n NetDevs: {}\n PrimaryNetDev: \"\"\n Profiles: |\n Source: explicit\n Value: default\n Root: |\n Source: default-value\n Value: initramfs\n RuntimeOverlay: |\n Source: default-value\n Value: generic\n SystemOverlay: |\n Source: default-value\n Value: wwinit\n Tags: {}\n"},
|
||||
stdout: "n01:\n AssetKey: \"\"\n ClusterName: \"\"\n Comment: \"\"\n ContainerName: \"\"\n Discoverable: \"\"\n Disks: {}\n FileSystems: {}\n Grub: \"\"\n Id: |\n Source: explicit\n Value: n01\n Init: |\n Source: default-value\n Value: /sbin/init\n Ipmi:\n EscapeChar: \"\"\n Gateway: \"\"\n Interface: \"\"\n Ipaddr: \"\"\n Netmask: \"\"\n Password: \"\"\n Port: \"\"\n Tags: null\n UserName: \"\"\n Write: \"\"\n Ipxe: |\n Source: default-value\n Value: default\n Kernel:\n Args: |\n Source: default-value\n Value: quiet crashkernel=no vga=791 net.naming-scheme=v238\n Override: \"\"\n NetDevs: {}\n PrimaryNetDev: \"\"\n Profiles: |\n Source: explicit\n Value: default\n Root: |\n Source: default-value\n Value: initramfs\n RuntimeOverlay: |\n Source: default-value\n Value: generic\n SystemOverlay: |\n Source: default-value\n Value: wwinit\n Tags: {}\n",
|
||||
inDb: `WW_INTERNAL: 43
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
@@ -408,7 +421,7 @@ nodes:
|
||||
{
|
||||
name: "single node list json output",
|
||||
args: []string{"-j"},
|
||||
output: []string{"{\"n01\":{\"Id\":\"Source: explicit\\nValue: n01\\n\",\"Comment\":\"\",\"ClusterName\":\"\",\"ContainerName\":\"\",\"Ipxe\":\"Source: default-value\\nValue: default\\n\",\"Grub\":\"\",\"RuntimeOverlay\":\"Source: default-value\\nValue: generic\\n\",\"SystemOverlay\":\"Source: default-value\\nValue: wwinit\\n\",\"Root\":\"Source: default-value\\nValue: initramfs\\n\",\"Discoverable\":\"\",\"Init\":\"Source: default-value\\nValue: /sbin/init\\n\",\"AssetKey\":\"\",\"Kernel\":{\"Override\":\"\",\"Args\":\"Source: default-value\\nValue: quiet crashkernel=no vga=791 net.naming-scheme=v238\\n\"},\"Ipmi\":{\"Ipaddr\":\"\",\"Netmask\":\"\",\"Port\":\"\",\"Gateway\":\"\",\"UserName\":\"\",\"Password\":\"\",\"Interface\":\"\",\"EscapeChar\":\"\",\"Write\":\"\",\"Tags\":null},\"Profiles\":\"Source: explicit\\nValue: default\\n\",\"PrimaryNetDev\":\"\",\"NetDevs\":{},\"Tags\":{},\"Disks\":{},\"FileSystems\":{}}}\n"},
|
||||
stdout: "{\"n01\":{\"Id\":\"Source: explicit\\nValue: n01\\n\",\"Comment\":\"\",\"ClusterName\":\"\",\"ContainerName\":\"\",\"Ipxe\":\"Source: default-value\\nValue: default\\n\",\"Grub\":\"\",\"RuntimeOverlay\":\"Source: default-value\\nValue: generic\\n\",\"SystemOverlay\":\"Source: default-value\\nValue: wwinit\\n\",\"Root\":\"Source: default-value\\nValue: initramfs\\n\",\"Discoverable\":\"\",\"Init\":\"Source: default-value\\nValue: /sbin/init\\n\",\"AssetKey\":\"\",\"Kernel\":{\"Override\":\"\",\"Args\":\"Source: default-value\\nValue: quiet crashkernel=no vga=791 net.naming-scheme=v238\\n\"},\"Ipmi\":{\"Ipaddr\":\"\",\"Netmask\":\"\",\"Port\":\"\",\"Gateway\":\"\",\"UserName\":\"\",\"Password\":\"\",\"Interface\":\"\",\"EscapeChar\":\"\",\"Write\":\"\",\"Tags\":null},\"Profiles\":\"Source: explicit\\nValue: default\\n\",\"PrimaryNetDev\":\"\",\"NetDevs\":{},\"Tags\":{},\"Disks\":{},\"FileSystems\":{}}}\n",
|
||||
inDb: `WW_INTERNAL: 43
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
@@ -421,7 +434,7 @@ nodes:
|
||||
{
|
||||
name: "multiple nodes list json output",
|
||||
args: []string{"-j"},
|
||||
output: []string{"n01", "n02"},
|
||||
stdout: "n01 n02",
|
||||
inDb: `WW_INTERNAL: 43
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
@@ -437,7 +450,7 @@ nodes:
|
||||
{
|
||||
name: "multiple nodes list yaml output",
|
||||
args: []string{"-y"},
|
||||
output: []string{"n01:", "n02:"},
|
||||
stdout: "n01: n02:",
|
||||
inDb: `WW_INTERNAL: 43
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
@@ -452,34 +465,16 @@ nodes:
|
||||
},
|
||||
}
|
||||
|
||||
conf_yml := `WW_INTERNAL: 0`
|
||||
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 {
|
||||
env := testenv.New(t)
|
||||
env.WriteFile(t, "etc/warewulf/nodes.conf", tt.inDb)
|
||||
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())
|
||||
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
buf := new(bytes.Buffer)
|
||||
wwlog.SetLogWriter(buf)
|
||||
baseCmd := GetCommand()
|
||||
baseCmd.SetArgs(tt.args)
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
baseCmd.SetOut(buf)
|
||||
baseCmd.SetErr(buf)
|
||||
wwlog.SetLogWriter(buf)
|
||||
|
||||
@@ -6,13 +6,12 @@ import (
|
||||
)
|
||||
|
||||
type variables struct {
|
||||
showNet bool
|
||||
showIpmi bool
|
||||
showAll bool
|
||||
showLong bool
|
||||
showFullAll bool
|
||||
showYaml bool
|
||||
showJson bool
|
||||
showNet bool
|
||||
showIpmi bool
|
||||
showAll bool
|
||||
showLong bool
|
||||
showYaml bool
|
||||
showJson bool
|
||||
}
|
||||
|
||||
func GetCommand() *cobra.Command {
|
||||
@@ -42,7 +41,6 @@ func GetCommand() *cobra.Command {
|
||||
baseCmd.PersistentFlags().BoolVarP(&vars.showNet, "net", "n", false, "Show node network configurations")
|
||||
baseCmd.PersistentFlags().BoolVarP(&vars.showIpmi, "ipmi", "i", false, "Show node IPMI configurations")
|
||||
baseCmd.PersistentFlags().BoolVarP(&vars.showAll, "all", "a", false, "Show all node configurations")
|
||||
baseCmd.PersistentFlags().BoolVarP(&vars.showFullAll, "fullall", "A", false, "Show all node configurations inclusive empty entries")
|
||||
baseCmd.PersistentFlags().BoolVarP(&vars.showLong, "long", "l", false, "Show long or wide format")
|
||||
baseCmd.PersistentFlags().BoolVarP(&vars.showYaml, "yaml", "y", false, "Show yaml format")
|
||||
baseCmd.PersistentFlags().BoolVarP(&vars.showJson, "json", "j", false, "Show json format")
|
||||
|
||||
@@ -24,7 +24,7 @@ type test_description struct {
|
||||
func run_test(t *testing.T, test test_description) {
|
||||
env := testenv.New(t)
|
||||
defer env.RemoveAll(t)
|
||||
|
||||
// wwlog.SetLogLevel(wwlog.DEBUG)
|
||||
env.WriteFile(t, "etc/warewulf/nodes.conf", test.inDB)
|
||||
warewulfd.SetNoDaemon()
|
||||
name := test.name
|
||||
@@ -45,7 +45,7 @@ func run_test(t *testing.T, test test_description) {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, buf.String(), test.stdout)
|
||||
content := env.ReadFile(t, "etc/warewulf/nodes.conf")
|
||||
assert.Equal(t, test.outDb, content)
|
||||
assert.YAMLEq(t, test.outDb, content)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -74,8 +74,29 @@ nodes:
|
||||
`}
|
||||
run_test(t, test)
|
||||
}
|
||||
func Test_Node_Unset(t *testing.T) {
|
||||
test := test_description{
|
||||
args: []string{"--comment=UNDEF", "n01"},
|
||||
wantErr: false,
|
||||
stdout: "",
|
||||
inDB: `WW_INTERNAL: 43
|
||||
nodeprofiles: {}
|
||||
nodes:
|
||||
n01:
|
||||
comment: foo
|
||||
profiles:
|
||||
- default`,
|
||||
outDb: `WW_INTERNAL: 43
|
||||
nodeprofiles: {}
|
||||
nodes:
|
||||
n01:
|
||||
profiles:
|
||||
- default
|
||||
`}
|
||||
run_test(t, test)
|
||||
}
|
||||
|
||||
func Test_Multiple_Add_Tests(t *testing.T) {
|
||||
func Test_Multiple_Set_Tests(t *testing.T) {
|
||||
tests := []test_description{
|
||||
{name: "single node change profile",
|
||||
args: []string{"--profile=foo", "n01"},
|
||||
@@ -143,11 +164,11 @@ nodeprofiles:
|
||||
comment: testit
|
||||
nodes:
|
||||
n01:
|
||||
profiles:
|
||||
- default
|
||||
ipmi:
|
||||
tags:
|
||||
foo: baar
|
||||
profiles:
|
||||
- default
|
||||
`},
|
||||
{name: "single node delete tag",
|
||||
args: []string{"--tagdel", "tag1", "n01"},
|
||||
@@ -176,7 +197,7 @@ nodes:
|
||||
tag2: value2
|
||||
`},
|
||||
{name: "single node set fs,part and disk",
|
||||
args: []string{"--fsname=var", "--fspath=/var", "--fsformat=btrfs", "--partname=var", "--diskname=/dev/vda", "n01"},
|
||||
args: []string{"--fsname=var", "--fspath=/var", "--fsformat=btrfs", "--partname=var", "--partnumber=1", "--diskname=/dev/vda", "n01"},
|
||||
wantErr: false,
|
||||
stdout: "",
|
||||
inDB: `WW_INTERNAL: 45
|
||||
@@ -199,14 +220,15 @@ nodes:
|
||||
disks:
|
||||
/dev/vda:
|
||||
partitions:
|
||||
var: {}
|
||||
var:
|
||||
number: "1"
|
||||
filesystems:
|
||||
/dev/disk/by-partlabel/var:
|
||||
format: btrfs
|
||||
path: /var
|
||||
`},
|
||||
{name: "single delete not existing fs",
|
||||
args: []string{"--fsdel=var", "n01"},
|
||||
args: []string{"--fsdel=foo", "n01"},
|
||||
wantErr: true,
|
||||
stdout: "",
|
||||
inDB: `WW_INTERNAL: 45
|
||||
@@ -220,7 +242,8 @@ nodes:
|
||||
disks:
|
||||
/dev/vda:
|
||||
partitions:
|
||||
var: {}
|
||||
var:
|
||||
number: "1"
|
||||
path: /var
|
||||
filesystems:
|
||||
/dev/disk/by-partlabel/var:
|
||||
@@ -238,7 +261,8 @@ nodes:
|
||||
disks:
|
||||
/dev/vda:
|
||||
partitions:
|
||||
var: {}
|
||||
var:
|
||||
number: "1"
|
||||
filesystems:
|
||||
/dev/disk/by-partlabel/var:
|
||||
format: btrfs
|
||||
@@ -259,7 +283,8 @@ nodes:
|
||||
disks:
|
||||
/dev/vda:
|
||||
partitions:
|
||||
var: {}
|
||||
var:
|
||||
number: "1"
|
||||
path: /var
|
||||
filesystems:
|
||||
/dev/disk/by-partlabel/var:
|
||||
@@ -277,7 +302,8 @@ nodes:
|
||||
disks:
|
||||
/dev/vda:
|
||||
partitions:
|
||||
var: {}
|
||||
var:
|
||||
number: "1"
|
||||
`},
|
||||
{name: "single node delete existing partition",
|
||||
args: []string{"--partdel=var", "n01"},
|
||||
@@ -294,7 +320,8 @@ nodes:
|
||||
disks:
|
||||
/dev/vda:
|
||||
partitions:
|
||||
var: {}
|
||||
var:
|
||||
number: "1"
|
||||
path: /var
|
||||
filesystems:
|
||||
/dev/disk/by-partlabel/var:
|
||||
@@ -309,8 +336,6 @@ nodes:
|
||||
n01:
|
||||
profiles:
|
||||
- default
|
||||
disks:
|
||||
/dev/vda: {}
|
||||
filesystems:
|
||||
/dev/disk/by-partlabel/var:
|
||||
format: btrfs
|
||||
@@ -426,8 +451,6 @@ nodeprofiles: {}
|
||||
nodes:
|
||||
n01:
|
||||
comment: This is a , comment
|
||||
profiles:
|
||||
- default
|
||||
`},
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package show
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
@@ -63,7 +64,9 @@ nodes:
|
||||
node1:
|
||||
tags:
|
||||
email: admin@node1
|
||||
node2: {}
|
||||
node2:
|
||||
profiles:
|
||||
- default
|
||||
node3:
|
||||
profiles:
|
||||
- empty
|
||||
@@ -73,6 +76,7 @@ nodes:
|
||||
env.WriteFile(t, path.Join(testenv.WWOverlaydir, "testoverlay/overlay.ww"), overlayOverlay)
|
||||
defer env.RemoveAll(t)
|
||||
warewulfd.SetNoDaemon()
|
||||
//wwlog.SetLogLevel(wwlog.DEBUG)
|
||||
t.Run("overlay show raw", func(t *testing.T) {
|
||||
baseCmd.SetArgs([]string{"testoverlay", "email.ww"})
|
||||
baseCmd := GetCommand()
|
||||
@@ -164,6 +168,7 @@ nodes:
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Run("overlay render host template using 'host' value", func(t *testing.T) {
|
||||
fmt.Printf("foo\n")
|
||||
baseCmd.SetArgs([]string{"-r", "host", "testoverlay", "template.ww"})
|
||||
baseCmd := GetCommand()
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
@@ -2,12 +2,11 @@ package add
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
@@ -46,30 +45,12 @@ nodes: {}
|
||||
},
|
||||
}
|
||||
|
||||
conf_yml := `WW_INTERNAL: 0`
|
||||
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())
|
||||
warewulfconf.ConfigFile = tempWarewulfConf.Name()
|
||||
|
||||
nodes_yml := `WW_INTERNAL: 45`
|
||||
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 {
|
||||
env := testenv.New(t)
|
||||
env.WriteFile(t, "etc/warewulf/nodes.conf",
|
||||
`WW_INTERNAL: 43`)
|
||||
var err error
|
||||
_, err = tempNodeConf.Seek(0, 0)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, tempNodeConf.Truncate(0))
|
||||
_, err = tempNodeConf.Write([]byte(nodes_yml))
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, tempNodeConf.Sync())
|
||||
t.Logf("Running test: %s\n", tt.name)
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
baseCmd := GetCommand()
|
||||
baseCmd.SetArgs(tt.args)
|
||||
@@ -77,22 +58,15 @@ nodes: {}
|
||||
baseCmd.SetOut(buf)
|
||||
baseCmd.SetErr(buf)
|
||||
err = baseCmd.Execute()
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("Got unwanted error: %s", err)
|
||||
t.FailNow()
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
config, configErr := node.New()
|
||||
assert.NoError(t, configErr)
|
||||
dumpBytes, _ := config.Dump()
|
||||
dump := string(dumpBytes)
|
||||
if dump != tt.outDb {
|
||||
t.Errorf("DB dump is wrong, got:'%s'\nwant:'%s'", dump, tt.outDb)
|
||||
t.FailNow()
|
||||
}
|
||||
if buf.String() != tt.stdout {
|
||||
t.Errorf("Got wrong output, got:'%s'\nwant:'%s'", buf.String(), tt.stdout)
|
||||
t.FailNow()
|
||||
}
|
||||
assert.Equal(t, tt.outDb, string(dumpBytes))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,10 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) (err err
|
||||
args = strings.FieldsFunc(args[0], func(r rune) bool { return r == ',' })
|
||||
}
|
||||
req := wwapiv1.GetProfileList{
|
||||
ShowAll: vars.showAll,
|
||||
ShowFullAll: vars.showFullAll,
|
||||
ShowYaml: vars.showYaml,
|
||||
ShowJson: vars.showJson,
|
||||
Profiles: args,
|
||||
ShowAll: vars.showAll,
|
||||
ShowYaml: vars.showYaml,
|
||||
ShowJson: vars.showJson,
|
||||
Profiles: args,
|
||||
}
|
||||
profileInfo, err := apiprofile.ProfileList(&req)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,15 +2,11 @@ package list
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"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"
|
||||
)
|
||||
@@ -26,7 +22,7 @@ func Test_List(t *testing.T) {
|
||||
name: "profile list test",
|
||||
args: []string{},
|
||||
stdout: `PROFILE NAME COMMENT/DESCRIPTION
|
||||
default --`,
|
||||
default`,
|
||||
inDb: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
@@ -34,15 +30,14 @@ nodes:
|
||||
n01:
|
||||
profiles:
|
||||
- default
|
||||
`,
|
||||
},
|
||||
`},
|
||||
{
|
||||
name: "profile list returns multiple profiles",
|
||||
args: []string{"default,test"},
|
||||
stdout: `PROFILE NAME COMMENT/DESCRIPTION
|
||||
default --
|
||||
test --`,
|
||||
inDb: `WW_INTERNAL: 45
|
||||
default
|
||||
test`,
|
||||
inDb: `WW_INTERNAL: 43
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
test: {}
|
||||
@@ -51,198 +46,57 @@ nodes:
|
||||
profiles:
|
||||
- default
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "profile list returns one profiles",
|
||||
args: []string{"test,"},
|
||||
stdout: `PROFILE NAME COMMENT/DESCRIPTION
|
||||
test --`,
|
||||
inDb: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
test: {}
|
||||
nodes:
|
||||
n01:
|
||||
profiles:
|
||||
- default
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "profile list returns all profiles",
|
||||
args: []string{","},
|
||||
stdout: `PROFILE NAME COMMENT/DESCRIPTION
|
||||
default --
|
||||
test --`,
|
||||
inDb: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
test: {}
|
||||
nodes:
|
||||
n01:
|
||||
profiles:
|
||||
- default
|
||||
`,
|
||||
},
|
||||
}, /*
|
||||
{
|
||||
name: "profile list returns one profiles",
|
||||
args: []string{"test,"},
|
||||
stdout: `PROFILE NAME COMMENT/DESCRIPTION
|
||||
test --`,
|
||||
inDb: `WW_INTERNAL: 43
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
test: {}
|
||||
nodes:
|
||||
n01:
|
||||
profiles:
|
||||
- default
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "profile list returns all profiles",
|
||||
args: []string{","},
|
||||
stdout: `PROFILE NAME COMMENT/DESCRIPTION
|
||||
default --
|
||||
test --`,
|
||||
inDb: `WW_INTERNAL: 43
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
test: {}
|
||||
nodes:
|
||||
n01:
|
||||
profiles:
|
||||
- default
|
||||
`,
|
||||
},*/
|
||||
}
|
||||
|
||||
conf_yml := `WW_INTERNAL: 0`
|
||||
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()
|
||||
//wwlog.SetLogLevel(wwlog.DEBUG)
|
||||
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)
|
||||
env.WriteFile(t, "etc/warewulf/nodes.conf",
|
||||
tt.inDb)
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
baseCmd := GetCommand()
|
||||
baseCmd.SetArgs(tt.args)
|
||||
verifyOutput(t, baseCmd, tt.stdout)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestListMultipleFormats(t *testing.T) {
|
||||
t.Skip("temporally skip this test")
|
||||
tests := []struct {
|
||||
name string
|
||||
args []string
|
||||
output []string
|
||||
inDb string
|
||||
}{
|
||||
{
|
||||
name: "single profile list yaml output",
|
||||
args: []string{"-y"},
|
||||
output: []string{"default:\n AssetKey: \"\"\n ClusterName: \"\"\n Comment: \"\"\n ContainerName: \"\"\n Discoverable: \"\"\n Disks: {}\n FileSystems: {}\n Grub: \"\"\n Id: |\n Source: explicit\n Value: default\n Init: \"\"\n Ipmi:\n EscapeChar: \"\"\n Gateway: \"\"\n Interface: \"\"\n Ipaddr: \"\"\n Netmask: \"\"\n Password: \"\"\n Port: \"\"\n Tags: null\n UserName: \"\"\n Write: \"\"\n Ipxe: \"\"\n Kernel:\n Args: \"\"\n Override: \"\"\n NetDevs: {}\n PrimaryNetDev: \"\"\n Profiles: \"\"\n Root: \"\"\n RuntimeOverlay: \"\"\n SystemOverlay: \"\"\n Tags: {}\n"},
|
||||
inDb: `WW_INTERNAL: 43
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
nodes:
|
||||
n01:
|
||||
profiles:
|
||||
- default
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "single profile list json output",
|
||||
args: []string{"-j"},
|
||||
output: []string{"{\"default\":{\"Id\":\"Source: explicit\\nValue: default\\n\",\"Comment\":\"\",\"ClusterName\":\"\",\"ContainerName\":\"\",\"Ipxe\":\"\",\"Grub\":\"\",\"RuntimeOverlay\":\"\",\"SystemOverlay\":\"\",\"Root\":\"\",\"Discoverable\":\"\",\"Init\":\"\",\"AssetKey\":\"\",\"Kernel\":{\"Override\":\"\",\"Args\":\"\"},\"Ipmi\":{\"Ipaddr\":\"\",\"Netmask\":\"\",\"Port\":\"\",\"Gateway\":\"\",\"UserName\":\"\",\"Password\":\"\",\"Interface\":\"\",\"EscapeChar\":\"\",\"Write\":\"\",\"Tags\":null},\"Profiles\":\"\",\"PrimaryNetDev\":\"\",\"NetDevs\":{},\"Tags\":{},\"Disks\":{},\"FileSystems\":{}}}\n"},
|
||||
inDb: `WW_INTERNAL: 43
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
nodes:
|
||||
n01:
|
||||
profiles:
|
||||
- default
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "multiple profiles list yaml output",
|
||||
args: []string{"-y"},
|
||||
output: []string{"default", "test"},
|
||||
inDb: `WW_INTERNAL: 43
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
test: {}
|
||||
nodes:
|
||||
n01:
|
||||
profiles:
|
||||
- default
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "multiple profiles list json output",
|
||||
args: []string{"-j"},
|
||||
output: []string{"default", "test"},
|
||||
inDb: `WW_INTERNAL: 43
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
test: {}
|
||||
nodes:
|
||||
n01:
|
||||
profiles:
|
||||
- default
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
conf_yml := `WW_INTERNAL: 0`
|
||||
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())
|
||||
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
baseCmd := GetCommand()
|
||||
baseCmd.SetArgs(tt.args)
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
baseCmd.SetOut(buf)
|
||||
baseCmd.SetErr(buf)
|
||||
wwlog.SetLogWriter(buf)
|
||||
err := baseCmd.Execute()
|
||||
assert.NoError(t, err)
|
||||
for _, output := range tt.output {
|
||||
assert.Contains(t, buf.String(), output)
|
||||
}
|
||||
assert.NoError(t, baseCmd.Execute())
|
||||
assert.Equal(t,
|
||||
strings.Join(strings.Fields(tt.stdout), ""),
|
||||
strings.Join(strings.Fields(buf.String()), ""))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func verifyOutput(t *testing.T, baseCmd *cobra.Command, content string) {
|
||||
stdoutR, stdoutW, _ := os.Pipe()
|
||||
oriout := os.Stdout
|
||||
os.Stdout = stdoutW
|
||||
wwlog.SetLogWriter(os.Stdout)
|
||||
baseCmd.SetOut(os.Stdout)
|
||||
baseCmd.SetErr(os.Stdout)
|
||||
err := baseCmd.Execute()
|
||||
assert.NoError(t, err)
|
||||
|
||||
stdoutC := make(chan string)
|
||||
go func() {
|
||||
var buf bytes.Buffer
|
||||
_, _ = io.Copy(&buf, stdoutR)
|
||||
stdoutC <- buf.String()
|
||||
}()
|
||||
stdoutW.Close()
|
||||
os.Stdout = oriout
|
||||
|
||||
stdout := <-stdoutC
|
||||
stdout = strings.ReplaceAll(strings.TrimSpace(stdout), " ", "")
|
||||
assert.NotEmpty(t, stdout, "output should not be empty")
|
||||
content = strings.ReplaceAll(strings.TrimSpace(content), " ", "")
|
||||
assert.Contains(t, stdout, strings.ReplaceAll(strings.TrimSpace(content), " ", ""))
|
||||
}
|
||||
|
||||
@@ -3,10 +3,9 @@ package list
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
type variables struct {
|
||||
showAll bool
|
||||
showFullAll bool
|
||||
showYaml bool
|
||||
showJson bool
|
||||
showAll bool
|
||||
showYaml bool
|
||||
showJson bool
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
@@ -21,7 +20,6 @@ func GetCommand() *cobra.Command {
|
||||
Aliases: []string{"ls"},
|
||||
}
|
||||
baseCmd.PersistentFlags().BoolVarP(&vars.showAll, "all", "a", false, "Show all profile configurations")
|
||||
baseCmd.PersistentFlags().BoolVarP(&vars.showFullAll, "fullall", "A", false, "Show all profile configurations inclusive empty entries")
|
||||
baseCmd.PersistentFlags().BoolVarP(&vars.showYaml, "yaml", "y", false, "Show profile configurations via yaml format")
|
||||
baseCmd.PersistentFlags().BoolVarP(&vars.showJson, "json", "j", false, "Show profile configurations via json format")
|
||||
|
||||
|
||||
117
internal/app/wwctl/profile/set/main_test.go
Normal file
117
internal/app/wwctl/profile/set/main_test.go
Normal file
@@ -0,0 +1,117 @@
|
||||
package set
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/warewulf/warewulf/internal/pkg/testenv"
|
||||
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
type test_description struct {
|
||||
name string
|
||||
args []string
|
||||
wantErr bool
|
||||
stdout string
|
||||
inDB string
|
||||
outDb string
|
||||
}
|
||||
|
||||
func run_test(t *testing.T, test test_description) {
|
||||
env := testenv.New(t)
|
||||
defer env.RemoveAll(t)
|
||||
wwlog.SetLogLevel(wwlog.DEBUG)
|
||||
env.WriteFile(t, "etc/warewulf/nodes.conf", test.inDB)
|
||||
warewulfd.SetNoDaemon()
|
||||
name := test.name
|
||||
if name == "" {
|
||||
name = t.Name()
|
||||
}
|
||||
t.Run(name, func(t *testing.T) {
|
||||
baseCmd := GetCommand()
|
||||
test.args = append(test.args, "--yes")
|
||||
baseCmd.SetArgs(test.args)
|
||||
buf := new(bytes.Buffer)
|
||||
baseCmd.SetOut(buf)
|
||||
baseCmd.SetErr(buf)
|
||||
err := baseCmd.Execute()
|
||||
if test.wantErr {
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, buf.String(), test.stdout)
|
||||
content := env.ReadFile(t, "etc/warewulf/nodes.conf")
|
||||
assert.YAMLEq(t, test.outDb, content)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Set_Netdev(t *testing.T) {
|
||||
test := test_description{
|
||||
args: []string{"--netname=default", "--netdev=eth0", "default"},
|
||||
wantErr: false,
|
||||
stdout: "",
|
||||
inDB: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
nodes: {}
|
||||
`,
|
||||
outDb: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
default:
|
||||
network devices:
|
||||
default:
|
||||
device: eth0
|
||||
nodes: {}
|
||||
`}
|
||||
run_test(t, test)
|
||||
}
|
||||
func Test_Set_Netdev_and_Mask(t *testing.T) {
|
||||
test := test_description{
|
||||
args: []string{"--netname=default", "--netdev=eth0", "-M=255.255.255.0", "default"},
|
||||
wantErr: false,
|
||||
stdout: "",
|
||||
inDB: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
nodes: {}
|
||||
`,
|
||||
outDb: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
default:
|
||||
network devices:
|
||||
default:
|
||||
device: eth0
|
||||
netmask: 255.255.255.0
|
||||
nodes: {}
|
||||
`}
|
||||
run_test(t, test)
|
||||
}
|
||||
|
||||
func Test_Set_Mask_Existing_NetDev(t *testing.T) {
|
||||
test := test_description{
|
||||
args: []string{"--netname=default", "-M=255.255.255.0", "default"},
|
||||
wantErr: false,
|
||||
stdout: "",
|
||||
inDB: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
default:
|
||||
network devices:
|
||||
default:
|
||||
device: eth0
|
||||
nodes: {}
|
||||
`,
|
||||
outDb: `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
default:
|
||||
network devices:
|
||||
default:
|
||||
device: eth0
|
||||
netmask: 255.255.255.0
|
||||
nodes: {}
|
||||
`}
|
||||
run_test(t, test)
|
||||
}
|
||||
@@ -81,7 +81,7 @@ func NodeList(nodeGet *wwapiv1.GetNodeList) (nodeList wwapiv1.NodeList, err erro
|
||||
n.ContainerName,
|
||||
strings.Join(n.SystemOverlay, ",")+"/"+strings.Join(n.RuntimeOverlay, ",")))
|
||||
}
|
||||
} else if nodeGet.Type == wwapiv1.GetNodeList_All || nodeGet.Type == wwapiv1.GetNodeList_FullAll {
|
||||
} else if nodeGet.Type == wwapiv1.GetNodeList_All {
|
||||
for _, n := range node.FilterByName(nodes, nodeGet.Nodes) {
|
||||
nodeList.Output = append(nodeList.Output,
|
||||
fmt.Sprintf("%s:=:%s:=:%s:=:%s", "NODE", "FIELD", "PROFILE", "VALUE"))
|
||||
|
||||
@@ -28,11 +28,11 @@ func ProfileList(ShowOpt *wwapiv1.GetProfileList) (profileList wwapiv1.ProfileLi
|
||||
sort.Slice(profiles, func(i, j int) bool {
|
||||
return profiles[i].Id() < profiles[j].Id()
|
||||
})
|
||||
if ShowOpt.ShowAll || ShowOpt.ShowFullAll {
|
||||
if ShowOpt.ShowAll {
|
||||
for _, p := range profiles {
|
||||
profileList.Output = append(profileList.Output,
|
||||
fmt.Sprintf("%s:=:%s:=:%s", "PROFILE", "FIELD", "VALUE"))
|
||||
fields := p.GetFields(ShowOpt.ShowFullAll)
|
||||
fields := p.GetFields(ShowOpt.ShowAll)
|
||||
for _, f := range fields {
|
||||
profileList.Output = append(profileList.Output,
|
||||
fmt.Sprintf("%s:=:%s:=:%s", p.Id.Print(), f.Field, f.Value))
|
||||
|
||||
@@ -137,7 +137,6 @@ message GetNodeList {
|
||||
Network = 2;
|
||||
Long = 3;
|
||||
All = 4;
|
||||
FullAll = 5;
|
||||
YAML = 6;
|
||||
JSON = 7;
|
||||
}
|
||||
@@ -153,7 +152,6 @@ message NodeList {
|
||||
// Request a profile list view
|
||||
message GetProfileList {
|
||||
bool ShowAll = 1;
|
||||
bool ShowFullAll = 2;
|
||||
bool ShowYaml = 3;
|
||||
bool ShowJson = 4;
|
||||
repeated string Profiles = 5;
|
||||
|
||||
@@ -33,7 +33,6 @@ const (
|
||||
GetNodeList_Network GetNodeList_ListType = 2
|
||||
GetNodeList_Long GetNodeList_ListType = 3
|
||||
GetNodeList_All GetNodeList_ListType = 4
|
||||
GetNodeList_FullAll GetNodeList_ListType = 5
|
||||
GetNodeList_YAML GetNodeList_ListType = 6
|
||||
GetNodeList_JSON GetNodeList_ListType = 7
|
||||
)
|
||||
@@ -46,7 +45,6 @@ var (
|
||||
2: "Network",
|
||||
3: "Long",
|
||||
4: "All",
|
||||
5: "FullAll",
|
||||
6: "YAML",
|
||||
7: "JSON",
|
||||
}
|
||||
@@ -56,7 +54,6 @@ var (
|
||||
"Network": 2,
|
||||
"Long": 3,
|
||||
"All": 4,
|
||||
"FullAll": 5,
|
||||
"YAML": 6,
|
||||
"JSON": 7,
|
||||
}
|
||||
@@ -1224,11 +1221,10 @@ type GetProfileList struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
ShowAll bool `protobuf:"varint,1,opt,name=ShowAll,proto3" json:"ShowAll,omitempty"`
|
||||
ShowFullAll bool `protobuf:"varint,2,opt,name=ShowFullAll,proto3" json:"ShowFullAll,omitempty"`
|
||||
ShowYaml bool `protobuf:"varint,3,opt,name=ShowYaml,proto3" json:"ShowYaml,omitempty"`
|
||||
ShowJson bool `protobuf:"varint,4,opt,name=ShowJson,proto3" json:"ShowJson,omitempty"`
|
||||
Profiles []string `protobuf:"bytes,5,rep,name=Profiles,proto3" json:"Profiles,omitempty"`
|
||||
ShowAll bool `protobuf:"varint,1,opt,name=ShowAll,proto3" json:"ShowAll,omitempty"`
|
||||
ShowYaml bool `protobuf:"varint,3,opt,name=ShowYaml,proto3" json:"ShowYaml,omitempty"`
|
||||
ShowJson bool `protobuf:"varint,4,opt,name=ShowJson,proto3" json:"ShowJson,omitempty"`
|
||||
Profiles []string `protobuf:"bytes,5,rep,name=Profiles,proto3" json:"Profiles,omitempty"`
|
||||
}
|
||||
|
||||
func (x *GetProfileList) Reset() {
|
||||
@@ -1270,13 +1266,6 @@ func (x *GetProfileList) GetShowAll() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *GetProfileList) GetShowFullAll() bool {
|
||||
if x != nil {
|
||||
return x.ShowFullAll
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *GetProfileList) GetShowYaml() bool {
|
||||
if x != nil {
|
||||
return x.ShowYaml
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v2"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func newConstructorPrimaryNetworkTest() NodeYaml {
|
||||
@@ -43,66 +45,51 @@ nodes:
|
||||
}
|
||||
|
||||
func Test_Primary_Network(t *testing.T) {
|
||||
wwlog.SetLogLevel(wwlog.DEBUG)
|
||||
c := newConstructorPrimaryNetworkTest()
|
||||
nodes, _ := c.FindAllNodes()
|
||||
test_node1 := NewInfo()
|
||||
test_node2 := NewInfo()
|
||||
test_node3 := NewInfo()
|
||||
test_node4 := NewInfo()
|
||||
|
||||
for _, n := range nodes {
|
||||
if n.Id.Get() == "test_node1" {
|
||||
test_node1 = n
|
||||
}
|
||||
if n.Id.Get() == "test_node2" {
|
||||
test_node2 = n
|
||||
}
|
||||
if n.Id.Get() == "test_node3" {
|
||||
test_node3 = n
|
||||
}
|
||||
if n.Id.Get() == "test_node4" {
|
||||
test_node4 = n
|
||||
}
|
||||
}
|
||||
test_node1, err := c.GetNode("test_node1")
|
||||
assert.NoError(t, err)
|
||||
test_node2, err := c.GetNode("test_node2")
|
||||
assert.NoError(t, err)
|
||||
test_node3, err := c.GetNode("test_node3")
|
||||
assert.NoError(t, err)
|
||||
test_node4, err := c.GetNode("test_node4")
|
||||
assert.NoError(t, err)
|
||||
t.Run("Primary network with one network, nothing set", func(t *testing.T) {
|
||||
if test_node1.PrimaryNetDev.Get() != "net0" {
|
||||
t.Errorf("primary network isn't net0 but: %s", test_node1.PrimaryNetDev.Get())
|
||||
if test_node1.PrimaryNetDev != "net0" {
|
||||
t.Errorf("primary network isn't net0 but: %s", test_node1.PrimaryNetDev)
|
||||
}
|
||||
if !test_node1.NetDevs["net0"].Primary.GetB() {
|
||||
if !test_node1.NetDevs["net0"].primary {
|
||||
t.Errorf("primary flag isn't set for net0")
|
||||
}
|
||||
})
|
||||
t.Run("Primary network with two networks, primary is net1", func(t *testing.T) {
|
||||
if test_node2.PrimaryNetDev.Get() != "net1" {
|
||||
t.Errorf("primary network isn't net1 but: %s", test_node2.PrimaryNetDev.Get())
|
||||
if test_node2.PrimaryNetDev != "net1" {
|
||||
t.Errorf("primary network isn't net1 but: %s", test_node2.PrimaryNetDev)
|
||||
}
|
||||
if test_node2.NetDevs["net0"].Primary.GetB() {
|
||||
if test_node2.NetDevs["net0"].primary {
|
||||
t.Errorf("primary flag is set for net0")
|
||||
}
|
||||
if !test_node2.NetDevs["net1"].Primary.GetB() {
|
||||
if !test_node2.NetDevs["net1"].primary {
|
||||
t.Errorf("primary flag isn't set for net1")
|
||||
}
|
||||
})
|
||||
t.Run("Primary network with two networks, primary isn't set", func(t *testing.T) {
|
||||
if test_node3.PrimaryNetDev.Get() != "net0" {
|
||||
t.Errorf("primary network isn't net0 but: %s", test_node3.PrimaryNetDev.Get())
|
||||
if test_node3.PrimaryNetDev != "net0" && test_node3.PrimaryNetDev != "net1" {
|
||||
t.Errorf("network wasn't sanitized")
|
||||
}
|
||||
if !test_node3.NetDevs["net0"].Primary.GetB() {
|
||||
t.Errorf("primary flag is set for net0")
|
||||
}
|
||||
if test_node3.NetDevs["net1"].Primary.GetB() {
|
||||
t.Errorf("primary flag isn't set for net1")
|
||||
if test_node3.NetDevs["net0"].primary == test_node3.NetDevs["net1"].primary {
|
||||
t.Errorf("primary flag isn't set at all")
|
||||
}
|
||||
})
|
||||
// debateable what result we await here, on refactoring primary network w
|
||||
// will be one of the valid networks
|
||||
t.Run("Primary network with two networks, primary available", func(t *testing.T) {
|
||||
if test_node4.PrimaryNetDev.Get() != "net3" {
|
||||
t.Errorf("primary network isn't net3 but: %s", test_node3.PrimaryNetDev.Get())
|
||||
if test_node4.PrimaryNetDev == "net3" {
|
||||
t.Errorf("primary network isn net3, although node hasn't this network")
|
||||
}
|
||||
if test_node4.NetDevs["net0"].Primary.GetB() {
|
||||
t.Errorf("primary flag is set for net0")
|
||||
}
|
||||
if test_node4.NetDevs["net1"].Primary.GetB() {
|
||||
t.Errorf("primary flag isn't set for net1")
|
||||
if test_node4.NetDevs["net0"].primary == test_node4.NetDevs["net1"].primary {
|
||||
t.Errorf("node primary flag isn't set")
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -125,14 +112,14 @@ func Test_FindDiscoverableNode(t *testing.T) {
|
||||
t.Run(tt.description, func(t *testing.T) {
|
||||
config := newConstructorPrimaryNetworkTest()
|
||||
for _, node := range tt.discoverable_nodes {
|
||||
config.Nodes[node].Discoverable = "true"
|
||||
config.Nodes[node].Discoverable = true
|
||||
}
|
||||
discovered_node, discovered_interface, err := config.FindDiscoverableNode()
|
||||
if !tt.succeed {
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.discovered_node, discovered_node.Id.Get())
|
||||
assert.Equal(t, tt.discovered_node, discovered_node)
|
||||
assert.Equal(t, tt.discovered_interface, discovered_interface)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package node
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_Empty(t *testing.T) {
|
||||
var netdev NetDevs
|
||||
@@ -22,11 +24,13 @@ func Test_Empty(t *testing.T) {
|
||||
t.Errorf("netdev must be empty")
|
||||
}
|
||||
})
|
||||
t.Run("test for pointer assigned", func(t *testing.T) {
|
||||
netdev.Ipaddr = "10.10.10.1"
|
||||
netdevPtr = &netdev
|
||||
if ObjectIsEmpty(netdevPtr) == true {
|
||||
t.Errorf("netdev must be empty")
|
||||
}
|
||||
})
|
||||
/*
|
||||
t.Run("test for pointer assigned", func(t *testing.T) {
|
||||
netdev.Ipaddr = net.ParseIP("10.10.10.1")
|
||||
netdevPtr = &netdev
|
||||
if ObjectIsEmpty(netdevPtr) == true {
|
||||
t.Errorf("netdev must be empty")
|
||||
}
|
||||
})
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
func TestNodeUpdate(t *testing.T) {
|
||||
var nodeConfig = `
|
||||
WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
default:
|
||||
comment: This profile is automatically included for each node
|
||||
nodes:
|
||||
n0000:
|
||||
discoverable: true
|
||||
profiles:
|
||||
- default
|
||||
network devices:
|
||||
default:
|
||||
onboot: true
|
||||
device: eth0
|
||||
hwaddr: 08:00:27:39:46:70
|
||||
ipaddr: 10.0.8.150
|
||||
`
|
||||
var nodeYaml NodeYaml
|
||||
err := yaml.Unmarshal([]byte(nodeConfig), &nodeYaml)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = nodeYaml.NodeUpdate(
|
||||
NodeInfo{
|
||||
Id: Entry{
|
||||
value: []string{"n0000"},
|
||||
},
|
||||
},
|
||||
)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestNodeDisk(t *testing.T) {
|
||||
node_config := `WW_INTERNAL: 45
|
||||
nodes:
|
||||
n1:
|
||||
disks:
|
||||
/dev/vda:
|
||||
wipe_table: "true"
|
||||
partitions:
|
||||
scratch:
|
||||
should_exist: "true"
|
||||
filesystems:
|
||||
/dev/disk/by-partlabel/scratch:
|
||||
format: btrfs
|
||||
path: /scratch
|
||||
wipe_filesystem: "true"`
|
||||
|
||||
config, parse_error := Parse([]byte(node_config))
|
||||
assert.Empty(t, parse_error)
|
||||
|
||||
nodeInfos, info_error := config.FindAllNodes()
|
||||
assert.Empty(t, info_error)
|
||||
assert.Len(t, nodeInfos, 1)
|
||||
|
||||
node := nodeInfos[0]
|
||||
assert.Len(t, node.Disks, 1)
|
||||
assert.Len(t, node.FileSystems, 1)
|
||||
|
||||
disk := node.Disks["/dev/vda"]
|
||||
assert.True(t, disk.WipeTable.GetB())
|
||||
assert.Len(t, disk.Partitions, 1)
|
||||
|
||||
partition := disk.Partitions["scratch"]
|
||||
assert.True(t, partition.ShouldExist.GetB())
|
||||
|
||||
filesystem := node.FileSystems["/dev/disk/by-partlabel/scratch"]
|
||||
assert.Equal(t, "btrfs", filesystem.Format.Get())
|
||||
assert.Equal(t, "/scratch", filesystem.Path.Get())
|
||||
assert.True(t, filesystem.WipeFileSystem.GetB())
|
||||
}
|
||||
@@ -1,362 +0,0 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
func NewTransformerTestNode() NodeYaml {
|
||||
var data = `
|
||||
nodeprofiles:
|
||||
default:
|
||||
comment: This profile is automatically included for each node
|
||||
ipmi:
|
||||
username: greg
|
||||
profile2:
|
||||
tags:
|
||||
foo: foo profile2
|
||||
comment: Comment profile2
|
||||
ipmi:
|
||||
tags:
|
||||
foo: foo ipmi profile
|
||||
nodes:
|
||||
test_node1:
|
||||
comment: Node Comment
|
||||
profiles:
|
||||
- default
|
||||
network devices:
|
||||
net0:
|
||||
device: eth1
|
||||
discoverable: true
|
||||
ipmi:
|
||||
username: chris
|
||||
tags:
|
||||
baar: baar node1
|
||||
test_node2:
|
||||
primary: net0
|
||||
profiles:
|
||||
- default
|
||||
- profile2
|
||||
network devices:
|
||||
net0:
|
||||
netmask: 1.1.1.1
|
||||
net1:
|
||||
ipaddr: 1.2.3.4
|
||||
tags:
|
||||
baar: baar node2
|
||||
test_node3:
|
||||
profiles:
|
||||
- profile2
|
||||
tags:
|
||||
foo: foo node3
|
||||
foobaar: foobaar node3
|
||||
ipmi:
|
||||
ipaddr: 1.1.1.1
|
||||
tags:
|
||||
foo: foo ipmi node3
|
||||
test_node4:
|
||||
profiles:
|
||||
- profile2
|
||||
`
|
||||
var ret NodeYaml
|
||||
_ = yaml.Unmarshal([]byte(data), &ret)
|
||||
return ret
|
||||
}
|
||||
func Test_nodeYaml_SetFrom(t *testing.T) {
|
||||
c := NewTransformerTestNode()
|
||||
nodes, _ := c.FindAllNodes()
|
||||
test_node1 := NewInfo()
|
||||
test_node2 := NewInfo()
|
||||
test_node3 := NewInfo()
|
||||
test_node4 := NewInfo()
|
||||
test_empty := NewInfo()
|
||||
for _, n := range nodes {
|
||||
if n.Id.Get() == "test_node1" {
|
||||
test_node1 = n
|
||||
}
|
||||
if n.Id.Get() == "test_node2" {
|
||||
test_node2 = n
|
||||
}
|
||||
if n.Id.Get() == "test_node3" {
|
||||
test_node3 = n
|
||||
}
|
||||
if n.Id.Get() == "test_node4" {
|
||||
test_node4 = n
|
||||
}
|
||||
}
|
||||
getByNametests := []struct {
|
||||
name string
|
||||
arg string
|
||||
want string
|
||||
wantErr bool
|
||||
}{
|
||||
{"GetByName: FieldValue", "Comment", "Node Comment", false},
|
||||
{"GetByName: FieldName", "comment", "NodeComment", true},
|
||||
}
|
||||
for _, tt := range getByNametests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := GetByName(&test_node1, tt.arg)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("GetByName(%s,%s) error = %v, wantErr %v",
|
||||
reflect.TypeOf(test_node1), tt.arg, err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if (got != tt.want) != tt.wantErr {
|
||||
t.Errorf("GetByName(%s,%s) got = %v, want = %v",
|
||||
reflect.TypeOf(test_node1), tt.arg, got, tt.want)
|
||||
return
|
||||
}
|
||||
})
|
||||
}
|
||||
t.Run("Get() comment", func(t *testing.T) {
|
||||
comment := test_node1.Comment.Get()
|
||||
if comment != "Node Comment" {
|
||||
t.Errorf("Get() returned wrong comment: %s", comment)
|
||||
}
|
||||
})
|
||||
t.Run("Get() profile comment", func(t *testing.T) {
|
||||
comment := test_node2.Comment.Get()
|
||||
if comment != "Comment profile2" {
|
||||
t.Errorf("Get() returned wrong comment: %s", comment)
|
||||
}
|
||||
})
|
||||
t.Run("Get() default ipxe", func(t *testing.T) {
|
||||
value := test_node1.Ipxe.Get()
|
||||
if value != "default" {
|
||||
t.Errorf("Get() returned wrong ipxe template: %s", value)
|
||||
}
|
||||
})
|
||||
t.Run("GetSlice() default profile", func(t *testing.T) {
|
||||
value := test_node1.Profiles.GetSlice()[0]
|
||||
if value != "default" {
|
||||
t.Errorf("GetSlice() returned wrong profile: %s", value)
|
||||
}
|
||||
})
|
||||
t.Run("Get() default kernel args", func(t *testing.T) {
|
||||
value := test_node1.Kernel.Args.Get()
|
||||
if value != "quiet crashkernel=no vga=791 net.naming-scheme=v238" {
|
||||
t.Errorf("Get() returned wrong kernel args: %s", value)
|
||||
}
|
||||
})
|
||||
t.Run("Get() default network mask", func(t *testing.T) {
|
||||
value := test_node1.NetDevs["net0"].Netmask.Get()
|
||||
if value != "255.255.255.0" {
|
||||
t.Errorf("Get() returned wrong default netmask, got: %s want: 255.255.255.0", value)
|
||||
}
|
||||
})
|
||||
t.Run("Get() default network mask", func(t *testing.T) {
|
||||
value := test_node2.NetDevs["net0"].Netmask.Get()
|
||||
if value != "1.1.1.1" {
|
||||
t.Errorf("Get() returned wrong default netmask: %s", value)
|
||||
}
|
||||
})
|
||||
t.Run("GetB() primary for single network", func(t *testing.T) {
|
||||
value := test_node1.NetDevs["net0"].Primary.GetB()
|
||||
if !value {
|
||||
t.Errorf("GetB() returned wrong: %s", strconv.FormatBool(value))
|
||||
}
|
||||
})
|
||||
t.Run("GetB() for primary with two networks", func(t *testing.T) {
|
||||
value := test_node2.NetDevs["net0"].Primary.GetB()
|
||||
if !value {
|
||||
t.Errorf("GetB() returned wrong: %s", strconv.FormatBool(value))
|
||||
}
|
||||
})
|
||||
t.Run("GetB() for primary with two networks, get secondary network", func(t *testing.T) {
|
||||
value := test_node2.NetDevs["net1"].Primary.GetB()
|
||||
if value {
|
||||
t.Errorf("GetB() returned wrong: %s", strconv.FormatBool(value))
|
||||
}
|
||||
})
|
||||
t.Run("GetB() default discoverable", func(t *testing.T) {
|
||||
value := test_node1.Discoverable.GetB()
|
||||
if !value {
|
||||
t.Errorf("GetB() returned wrong: %s", strconv.FormatBool(value))
|
||||
}
|
||||
})
|
||||
t.Run("GetB() default discoverable", func(t *testing.T) {
|
||||
value := test_node2.Discoverable.GetB()
|
||||
if value {
|
||||
t.Errorf("GetB() returned wrong: %s", strconv.FormatBool(value))
|
||||
}
|
||||
})
|
||||
t.Run("Get() ipmi user from profile", func(t *testing.T) {
|
||||
value := test_node2.Ipmi.UserName.Get()
|
||||
if value != "greg" {
|
||||
t.Errorf("Get() returned wrong ipmi username: %s", value)
|
||||
}
|
||||
})
|
||||
t.Run("Get() ipmi user from node", func(t *testing.T) {
|
||||
value := test_node1.Ipmi.UserName.Get()
|
||||
if value != "chris" {
|
||||
t.Errorf("Get() returned wrong ipmi username: %s", value)
|
||||
}
|
||||
})
|
||||
t.Run("Get() tag foo from profile, node does not have this tag", func(t *testing.T) {
|
||||
value := test_node2.Tags["foo"].Get()
|
||||
if value != "foo profile2" {
|
||||
t.Errorf("Get() returned wrong tag for foo: %s", value)
|
||||
}
|
||||
})
|
||||
t.Run("Get() tag baar from node, node tag map is not overwritten", func(t *testing.T) {
|
||||
value := test_node2.Tags["baar"].Get()
|
||||
if value != "baar node2" {
|
||||
t.Errorf("Get() returned wrong tag for foo: %s", value)
|
||||
}
|
||||
})
|
||||
t.Run("Get() tag foo from node, tag present in profile", func(t *testing.T) {
|
||||
value := test_node3.Tags["foo"].Get()
|
||||
assert.Equal(t, "foo node3", value, "wrong value for tag")
|
||||
})
|
||||
t.Run("Get() tag foobaar from node", func(t *testing.T) {
|
||||
value := test_node3.Tags["foobaar"].Get()
|
||||
assert.Equal(t, "foobaar node3", value, "wrong value for tag")
|
||||
})
|
||||
t.Run("Get() ipmitag foo from profile, node does not have this tag", func(t *testing.T) {
|
||||
value := test_node3.Ipmi.Tags["foo"].Get()
|
||||
if value != "foo ipmi node3" {
|
||||
t.Errorf("Get() returned wrong tag for foo: %s", value)
|
||||
}
|
||||
})
|
||||
t.Run("Get() tag foo from profile, node does not have this tag", func(t *testing.T) {
|
||||
value := test_node4.Tags["foo"].Get()
|
||||
assert.Equal(t, "foo profile2", value, "wrong value for tag")
|
||||
})
|
||||
t.Run("Set() comment foo for empty node", func(t *testing.T) {
|
||||
test_empty.Comment.Set("foo")
|
||||
nodeConf := NewConf()
|
||||
nodeConf.GetFrom(test_empty)
|
||||
ymlByte, _ := yaml.Marshal(nodeConf)
|
||||
wanted := `comment: foo
|
||||
kernel: {}
|
||||
ipmi: {}
|
||||
`
|
||||
if !(wanted == string(ymlByte)) {
|
||||
t.Errorf("Got wrong yml, wanted:\n'%s'\nGot:\n'%s'", wanted, string(ymlByte))
|
||||
}
|
||||
// have to remove the comment for further tests, as vscode
|
||||
// can test single functions
|
||||
test_empty.Comment.Set("UNDEF")
|
||||
nodeConf.GetFrom(test_empty)
|
||||
nodeConf.Flatten()
|
||||
ymlByte, _ = yaml.Marshal(nodeConf)
|
||||
wanted = `{}
|
||||
`
|
||||
if string(ymlByte) != wanted {
|
||||
t.Errorf("Couldn't unset comment:\n'%s'\nwanted:\n'%s'", string(ymlByte), wanted)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Set() ipmiuser foo for flattened empty node", func(t *testing.T) {
|
||||
test_empty.Ipmi.UserName.Set("foo")
|
||||
nodeConf := NewConf()
|
||||
nodeConf.GetFrom(test_empty)
|
||||
nodeConf.Flatten()
|
||||
ymlByte, _ := yaml.Marshal(nodeConf)
|
||||
wanted := `ipmi:
|
||||
username: foo
|
||||
`
|
||||
if !(wanted == string(ymlByte)) {
|
||||
t.Errorf("Got wrong yml, wanted:\n'%s'\nGot:\n'%s'", wanted, string(ymlByte))
|
||||
}
|
||||
test_empty.Ipmi.Tags["foo"] = &Entry{}
|
||||
test_empty.Ipmi.Tags["foo"].Set("baar")
|
||||
nodeConf.GetFrom(test_empty)
|
||||
nodeConf.Flatten()
|
||||
ymlByte, _ = yaml.Marshal(nodeConf)
|
||||
wanted = `ipmi:
|
||||
username: foo
|
||||
tags:
|
||||
foo: baar
|
||||
`
|
||||
if !(wanted == string(ymlByte)) {
|
||||
t.Errorf("Got wrong yml, wanted:\n'%s'\nGot:\n'%s'", wanted, string(ymlByte))
|
||||
}
|
||||
test_empty.Ipmi.UserName.Set("UNSET")
|
||||
delete(test_empty.Ipmi.Tags, "foo")
|
||||
})
|
||||
t.Run("Set() kernelargs foo for flattened empty node", func(t *testing.T) {
|
||||
test_empty.Kernel.Args.Set("foo")
|
||||
nodeConf := NewConf()
|
||||
nodeConf.GetFrom(test_empty)
|
||||
nodeConf.Flatten()
|
||||
ymlByte, _ := yaml.Marshal(nodeConf)
|
||||
wanted := `kernel:
|
||||
args: foo
|
||||
`
|
||||
if !(wanted == string(ymlByte)) {
|
||||
t.Errorf("Got wrong yml, wanted:\n'%s'\nGot:\n'%s'", wanted, string(ymlByte))
|
||||
}
|
||||
test_empty.Kernel.Args.Set("--")
|
||||
})
|
||||
t.Run("Set() tag foo to bar for flattened empty node", func(t *testing.T) {
|
||||
test_empty.Tags["foo"] = &Entry{}
|
||||
test_empty.Tags["foo"].Set("baar")
|
||||
nodeConf := NewConf()
|
||||
nodeConf.GetFrom(test_empty)
|
||||
nodeConf.Flatten()
|
||||
ymlByte, _ := yaml.Marshal(nodeConf)
|
||||
wanted := `tags:
|
||||
foo: baar
|
||||
`
|
||||
if !(wanted == string(ymlByte)) {
|
||||
t.Errorf("Got wrong yml, wanted:\n'%s'\nGot:\n'%s'", wanted, string(ymlByte))
|
||||
}
|
||||
delete(test_empty.Tags, "foo")
|
||||
nodeConf = NewConf()
|
||||
nodeConf.GetFrom(test_empty)
|
||||
nodeConf.Flatten()
|
||||
ymlByte, _ = yaml.Marshal(nodeConf)
|
||||
wanted = `{}
|
||||
`
|
||||
if string(ymlByte) != wanted {
|
||||
t.Errorf("Couldn't remove tag, wanted:\n%s\nGot:\n%s", wanted, string(ymlByte))
|
||||
}
|
||||
|
||||
})
|
||||
t.Run("Set() netdev foo with device name baar for flattened empty node", func(t *testing.T) {
|
||||
test_empty.NetDevs["foo"] = new(NetDevEntry)
|
||||
test_empty.NetDevs["foo"].Device.Set("baar")
|
||||
nodeConf := NewConf()
|
||||
nodeConf.GetFrom(test_empty)
|
||||
nodeConf.Flatten()
|
||||
ymlByte, _ := yaml.Marshal(nodeConf)
|
||||
wanted := `network devices:
|
||||
foo:
|
||||
device: baar
|
||||
`
|
||||
if !(wanted == string(ymlByte)) {
|
||||
t.Errorf("Got wrong yml, wanted:\n'%s'\nGot:\n'%s'", wanted, string(ymlByte))
|
||||
}
|
||||
test_empty.NetDevs["foo"].Tags = make(map[string]*Entry)
|
||||
test_empty.NetDevs["foo"].Tags["netfoo"] = new(Entry)
|
||||
test_empty.NetDevs["foo"].Tags["netfoo"].Set("netbaar")
|
||||
nodeConf.GetFrom(test_empty)
|
||||
nodeConf.Flatten()
|
||||
wanted = `network devices:
|
||||
foo:
|
||||
device: baar
|
||||
tags:
|
||||
netfoo: netbaar
|
||||
`
|
||||
ymlByte, _ = yaml.Marshal(nodeConf)
|
||||
if string(ymlByte) != wanted {
|
||||
t.Errorf("Couldn't set nettag: '%s' got: '%s'", wanted, string(ymlByte))
|
||||
}
|
||||
|
||||
delete(test_empty.NetDevs, "foo")
|
||||
nodeConf = NewConf()
|
||||
nodeConf.GetFrom(test_empty)
|
||||
nodeConf.Flatten()
|
||||
ymlByte, _ = yaml.Marshal(nodeConf)
|
||||
wanted = `{}
|
||||
`
|
||||
if string(ymlByte) != wanted {
|
||||
t.Errorf("Couldn't remove tag'%s'", string(ymlByte))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package node
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
@@ -13,26 +15,25 @@ nodeprofiles:
|
||||
comment: This profile is automatically included for each node
|
||||
nodes:
|
||||
test_node:
|
||||
primary network: net0
|
||||
comment: Node Comment
|
||||
profiles:
|
||||
- default
|
||||
network devices:
|
||||
net0:
|
||||
default: true
|
||||
hwaddr: 00:00:00:00:12:34
|
||||
ipaddr: 1.2.3.4
|
||||
device: eth0
|
||||
net1:
|
||||
default: false
|
||||
hwaddr: ab:cd:ef:00:12:34
|
||||
ipaddr: 1.2.3.4
|
||||
device: eth1
|
||||
net2:
|
||||
default: false
|
||||
hwaddr: aB:Cd:eF:12:34:56
|
||||
ipaddr: 1.2.3.4
|
||||
device: eth2
|
||||
test_node_IPv6:
|
||||
primary network: net1
|
||||
profiles:
|
||||
- default
|
||||
network devices:
|
||||
@@ -49,7 +50,8 @@ nodes:
|
||||
}
|
||||
|
||||
func Test_nodeYaml_FindByHwaddr(t *testing.T) {
|
||||
c, _ := NewUtilTestNode()
|
||||
c, err := NewUtilTestNode()
|
||||
assert.NoError(t, err)
|
||||
//type fields struct {
|
||||
// NodeProfiles map[string]*NodeConf
|
||||
// Nodes map[string]*NodeConf
|
||||
@@ -82,7 +84,7 @@ func Test_nodeYaml_FindByHwaddr(t *testing.T) {
|
||||
t.Errorf("FindByHwaddr() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !(got.Id.Get() == tt.want) {
|
||||
if !(got.id == tt.want) {
|
||||
t.Errorf("FindByHwaddr() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
@@ -90,7 +92,9 @@ func Test_nodeYaml_FindByHwaddr(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_nodeYaml_FindByIpaddr(t *testing.T) {
|
||||
c, _ := NewUtilTestNode()
|
||||
wwlog.SetLogLevel(wwlog.DEBUG)
|
||||
c, err := NewUtilTestNode()
|
||||
assert.NoError(t, err)
|
||||
type args struct {
|
||||
ipaddr string
|
||||
}
|
||||
@@ -119,7 +123,7 @@ func Test_nodeYaml_FindByIpaddr(t *testing.T) {
|
||||
t.Errorf("FindByIpaddr() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !(got.Id.Get() == tt.want) {
|
||||
if !(got.id == tt.want) {
|
||||
t.Errorf("FindByHwaddr() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
func Test_createIgnitionJson(t *testing.T) {
|
||||
@@ -13,15 +14,15 @@ nodes:
|
||||
n1:
|
||||
disks:
|
||||
/dev/vda:
|
||||
wipe_table: "true"
|
||||
wipe_table: true
|
||||
partitions:
|
||||
scratch:
|
||||
should_exist: "true"
|
||||
should_exist: true
|
||||
filesystems:
|
||||
/dev/disk/by-partlabel/scratch:
|
||||
format: btrfs
|
||||
path: /scratch
|
||||
wipe_filesystem: "true"`
|
||||
wipe_filesystem: true`
|
||||
|
||||
expected_json := `{
|
||||
"ignition": {
|
||||
@@ -51,7 +52,7 @@ nodes:
|
||||
]
|
||||
}
|
||||
}`
|
||||
|
||||
wwlog.SetLogLevel(wwlog.DEBUG)
|
||||
config, parse_error := node.Parse([]byte(node_config))
|
||||
assert.Empty(t, parse_error)
|
||||
|
||||
|
||||
@@ -147,8 +147,7 @@ func Test_BuildOverlay(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tt := range buildOverlayTests {
|
||||
nodeInfo := node.NodeInfo{}
|
||||
nodeInfo.Id.Set(tt.nodeName)
|
||||
nodeInfo := node.NewNode(tt.nodeName)
|
||||
t.Run(tt.description, func(t *testing.T) {
|
||||
provisionDir, provisionDirErr := os.MkdirTemp(os.TempDir(), "ww-test-provision-*")
|
||||
assert.NoError(t, provisionDirErr)
|
||||
@@ -266,15 +265,14 @@ func Test_BuildAllOverlays(t *testing.T) {
|
||||
defer os.RemoveAll(provisionDir)
|
||||
conf.Paths.WWProvisiondir = provisionDir
|
||||
|
||||
var nodes []node.NodeInfo
|
||||
var nodes []node.NodeConf
|
||||
for i, nodeName := range tt.nodes {
|
||||
nodeInfo := node.NodeInfo{}
|
||||
nodeInfo.Id.Set(nodeName)
|
||||
nodeInfo := node.NewNode(nodeName)
|
||||
if tt.systemOverlays != nil {
|
||||
nodeInfo.SystemOverlay.SetSlice(tt.systemOverlays[i])
|
||||
nodeInfo.SystemOverlay = tt.systemOverlays[i]
|
||||
}
|
||||
if tt.runtimeOverlays != nil {
|
||||
nodeInfo.RuntimeOverlay.SetSlice(tt.runtimeOverlays[i])
|
||||
nodeInfo.RuntimeOverlay = tt.runtimeOverlays[i]
|
||||
}
|
||||
nodes = append(nodes, nodeInfo)
|
||||
}
|
||||
@@ -365,10 +363,9 @@ func Test_BuildSpecificOverlays(t *testing.T) {
|
||||
defer os.RemoveAll(provisionDir)
|
||||
conf.Paths.WWProvisiondir = provisionDir
|
||||
|
||||
var nodes []node.NodeInfo
|
||||
var nodes []node.NodeConf
|
||||
for _, nodeName := range tt.nodes {
|
||||
nodeInfo := node.NodeInfo{}
|
||||
nodeInfo.Id.Set(nodeName)
|
||||
nodeInfo := node.NewNode(nodeName)
|
||||
nodes = append(nodes, nodeInfo)
|
||||
}
|
||||
err := BuildSpecificOverlays(nodes, tt.overlays)
|
||||
|
||||
@@ -19,7 +19,6 @@ import (
|
||||
)
|
||||
|
||||
const initWarewulfConf = `WW_INTERNAL: 0`
|
||||
const initDefaultsConf = `WW_INTERNAL: 45`
|
||||
const initNodesConf = `WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
default: {}
|
||||
@@ -60,7 +59,6 @@ func New(t *testing.T) (env *TestEnv) {
|
||||
|
||||
env.WriteFile(t, path.Join(Sysconfdir, "warewulf/nodes.conf"), initNodesConf)
|
||||
env.WriteFile(t, path.Join(Sysconfdir, "warewulf/warewulf.conf"), initWarewulfConf)
|
||||
env.WriteFile(t, path.Join(Datadir, "warewulf/defaults.conf"), initDefaultsConf)
|
||||
|
||||
// re-read warewulf.conf
|
||||
conf := warewulfconf.New()
|
||||
|
||||
@@ -37,14 +37,9 @@ var provisionSendTests = []struct {
|
||||
}
|
||||
|
||||
func Test_ProvisionSend(t *testing.T) {
|
||||
conf_file, err := os.CreateTemp(os.TempDir(), "ww-test-nodes.conf-*")
|
||||
assert.NoError(t, err)
|
||||
defer conf_file.Close()
|
||||
{
|
||||
_, err := conf_file.WriteString(`WW_INTERNAL: 45
|
||||
nodeprofiles:
|
||||
default:
|
||||
container name: suse
|
||||
env := testenv.New(t)
|
||||
// wwlog.SetLogLevel(wwlog.DEBUG)
|
||||
env.WriteFile(t, "etc/warewulf/nodes.conf", `
|
||||
nodes:
|
||||
n1:
|
||||
network devices:
|
||||
@@ -63,11 +58,6 @@ nodes:
|
||||
ipxe template: test
|
||||
kernel:
|
||||
override: 1.1.1`)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
assert.NoError(t, conf_file.Sync())
|
||||
node.ConfigFile = conf_file.Name()
|
||||
|
||||
// create a arp file as for grub we look up the ip address through the arp cache
|
||||
arp_file, err := os.CreateTemp(os.TempDir(), "ww-arp")
|
||||
assert.NoError(t, err)
|
||||
@@ -116,16 +106,17 @@ nodes:
|
||||
dbErr := LoadNodeDB()
|
||||
assert.NoError(t, dbErr)
|
||||
|
||||
provisionDir, provisionDirErr := os.MkdirTemp(os.TempDir(), "ww-test-provision-*")
|
||||
assert.NoError(t, provisionDirErr)
|
||||
defer os.RemoveAll(provisionDir)
|
||||
conf.Paths.WWProvisiondir = provisionDir
|
||||
conf := warewulfconf.Get()
|
||||
conf.Warewulf.Secure = false
|
||||
wwlog.SetLogLevel(wwlog.DEBUG)
|
||||
assert.NoError(t, os.MkdirAll(path.Join(provisionDir, "overlays", "n1"), 0700))
|
||||
assert.NoError(t, os.WriteFile(path.Join(provisionDir, "overlays", "n1", "__SYSTEM__.img"), []byte("system overlay"), 0600))
|
||||
assert.NoError(t, os.WriteFile(path.Join(provisionDir, "overlays", "n1", "__RUNTIME__.img"), []byte("runtime overlay"), 0600))
|
||||
assert.NoError(t, os.WriteFile(path.Join(provisionDir, "overlays", "n1", "o1.img"), []byte("specific overlay"), 0600))
|
||||
assert.NoError(t, os.MkdirAll(path.Join(conf.Paths.WWProvisiondir, "overlays", "n1"), 0700))
|
||||
assert.NoError(t, os.WriteFile(path.Join(conf.Paths.WWProvisiondir, "overlays", "n1", "__SYSTEM__.img"), []byte("system overlay"), 0600))
|
||||
assert.NoError(t, os.WriteFile(path.Join(conf.Paths.WWProvisiondir, "overlays", "n1", "__RUNTIME__.img"), []byte("runtime overlay"), 0600))
|
||||
assert.NoError(t, os.WriteFile(path.Join(conf.Paths.WWProvisiondir, "overlays", "n1", "o1.img"), []byte("specific overlay"), 0600))
|
||||
|
||||
for _, tt := range provisionSendTests {
|
||||
t.Run(tt.description, func(t *testing.T) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"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/wwlog"
|
||||
"github.com/warewulf/warewulf/internal/pkg/testenv"
|
||||
)
|
||||
|
||||
var getOverlayFileTests = []struct {
|
||||
@@ -37,7 +37,7 @@ var getOverlayFileTests = []struct {
|
||||
node: "",
|
||||
context: "",
|
||||
overlays: []string{"o1", "o2"},
|
||||
result: "overlays/o1-o2.img",
|
||||
result: "overlays/node1/o1-o2.img",
|
||||
},
|
||||
{
|
||||
description: "system overlay for a node points to the node's system overlay image",
|
||||
@@ -77,29 +77,26 @@ var getOverlayFileTests = []struct {
|
||||
}
|
||||
|
||||
func Test_getOverlayFile(t *testing.T) {
|
||||
wwlog.SetLogLevel(wwlog.DEBUG)
|
||||
env := testenv.New(t)
|
||||
env.WriteFile(t, "etc/warewulf/nodes.conf", `
|
||||
nodes:
|
||||
node1: {} `)
|
||||
conf := warewulfconf.Get()
|
||||
overlayPDir, overlayPDirErr := os.MkdirTemp(os.TempDir(), "ww-test-overlay-*")
|
||||
assert.NoError(t, overlayPDirErr)
|
||||
conf.Paths.WWProvisiondir = overlayPDir
|
||||
overlayDir, overlayDirErr := os.MkdirTemp(os.TempDir(), "ww-test-provision-*")
|
||||
assert.NoError(t, overlayDirErr)
|
||||
conf.Paths.WWOverlaydir = overlayDir
|
||||
defer os.RemoveAll(overlayDir)
|
||||
assert.NoError(t, os.MkdirAll(path.Join(overlayDir, "o1"), 0700))
|
||||
assert.NoError(t, os.WriteFile(path.Join(overlayDir, "o1", "test_file_o1"), []byte("test file"), 0600))
|
||||
assert.NoError(t, os.MkdirAll(path.Join(overlayDir, "o2"), 0700))
|
||||
|
||||
assert.NoError(t, os.MkdirAll(path.Join(conf.Paths.WWOverlaydir, "o1"), 0700))
|
||||
assert.NoError(t, os.WriteFile(path.Join(conf.Paths.WWOverlaydir, "o1", "test_file_o1"), []byte("test file"), 0600))
|
||||
assert.NoError(t, os.MkdirAll(path.Join(conf.Paths.WWOverlaydir, "o2"), 0700))
|
||||
nodeDB, err := node.New()
|
||||
assert.NoError(t, err)
|
||||
for _, tt := range getOverlayFileTests {
|
||||
t.Run(tt.description, func(t *testing.T) {
|
||||
var nodeInfo node.NodeInfo
|
||||
nodeInfo.Id.Set(tt.node)
|
||||
nodeInfo.RuntimeOverlay.SetSlice(tt.overlays)
|
||||
nodeInfo.SystemOverlay.SetSlice(tt.overlays)
|
||||
nodeInfo, err := nodeDB.GetNode("node1")
|
||||
assert.NoError(t, err)
|
||||
nodeInfo.RuntimeOverlay = tt.overlays
|
||||
nodeInfo.SystemOverlay = tt.overlays
|
||||
result, err := getOverlayFile(nodeInfo, tt.context, tt.overlays, false)
|
||||
assert.NoError(t, err)
|
||||
if tt.result != "" {
|
||||
tt.result = path.Join(overlayPDir, tt.result)
|
||||
tt.result = path.Join(conf.Paths.WWProvisiondir, tt.result)
|
||||
}
|
||||
assert.Equal(t, tt.result, result)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user