Merge pull request #1548 from mslacken/TagsInOverlayGrub

Add test for sending grub.cfg
This commit is contained in:
Jonathon Anderson
2024-11-14 19:32:53 -07:00
committed by GitHub
3 changed files with 13 additions and 4 deletions

View File

@@ -64,6 +64,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Replace `olekukonko/tablewriter` with `cheynewallace/tabby`. #1497, #1498
- replaced deprecated errors.Wrapf with fmr.Errorf. #1534
- Rename udev net naming file to 70-persistent-net.rules. #1227
- Manage warewulfd template data as a pointer. #1548
- Added test for sending grub.cfg.ww. #1548
### Removed

View File

@@ -71,7 +71,7 @@ func ProvisionSend(w http.ResponseWriter, req *http.Request) {
var stage_file string
// TODO: when module version is upgraded to go1.18, should be 'any' type
var tmpl_data interface{}
var tmpl_data *templateVars
remoteNode, err := GetNodeOrSetDiscoverable(rinfo.hwaddr)
if err != nil && err != node.ErrNoUnconfigured {
@@ -91,13 +91,13 @@ func ProvisionSend(w http.ResponseWriter, req *http.Request) {
wwlog.Error("%s (unknown/unconfigured node)", rinfo.hwaddr)
if rinfo.stage == "ipxe" {
stage_file = path.Join(conf.Paths.Sysconfdir, "/warewulf/ipxe/unconfigured.ipxe")
tmpl_data = templateVars{
tmpl_data = &templateVars{
Hwaddr: rinfo.hwaddr}
}
} else if rinfo.stage == "ipxe" {
stage_file = path.Join(conf.Paths.Sysconfdir, "warewulf/ipxe/"+remoteNode.Ipxe+".ipxe")
tmpl_data = templateVars{
tmpl_data = &templateVars{
Id: remoteNode.Id(),
Cluster: remoteNode.ClusterName,
Fqdn: remoteNode.Id(),
@@ -181,7 +181,7 @@ func ProvisionSend(w http.ResponseWriter, req *http.Request) {
}
case "grub.cfg":
stage_file = path.Join(conf.Paths.Sysconfdir, "warewulf/grub/grub.cfg.ww")
tmpl_data = templateVars{
tmpl_data = &templateVars{
Id: remoteNode.Id(),
Cluster: remoteNode.ClusterName,
Fqdn: remoteNode.Id(),

View File

@@ -32,6 +32,7 @@ var provisionSendTests = []struct {
{"find grub", "/efiboot/grub.efi", "", 404, "10.10.10.11:9873"},
{"find initramfs", "/provision/00:00:00:ff:ff:ff?stage=initramfs", "", 200, "10.10.10.10:9873"},
{"ipxe test with NetDevs and KernelOverrides", "/provision/00:00:00:00:00:ff?stage=ipxe", "1.1.1 ifname=net:00:00:00:00:00:ff ", 200, "10.10.10.12:9873"},
{"find grub.cfg", "/efiboot/grub.cfg", "dracut", 200, "10.10.10.11:9873"},
}
func Test_ProvisionSend(t *testing.T) {
@@ -52,6 +53,8 @@ nodes:
default:
hwaddr: 00:00:00:00:ff:ff
container name: none
tags:
GrubMenuEntry: dracut
n3:
network devices:
default:
@@ -97,6 +100,10 @@ nodes:
{
assert.NoError(t, os.WriteFile(path.Join(conf.Paths.Sysconfdir, "warewulf/ipxe", "test.ipxe"), []byte("{{.KernelOverride}}{{range $devname, $netdev := .NetDevs}}{{if and $netdev.Hwaddr $netdev.Device}} ifname={{$netdev.Device}}:{{$netdev.Hwaddr}} {{end}}{{end}}"), 0600))
}
assert.NoError(t, os.MkdirAll(path.Join(conf.Paths.Sysconfdir, "warewulf/grub"), 0700))
{
assert.NoError(t, os.WriteFile(path.Join(conf.Paths.Sysconfdir, "warewulf/grub", "grub.cfg.ww"), []byte("{{ .Tags.GrubMenuEntry }}"), 0600))
}
dbErr := LoadNodeDB()
assert.NoError(t, dbErr)