Missing hyphen in dhcp template path. Unit tests.

This is a single character bug fix.
Broke this out into a function for testing.
This commit is contained in:
MatthewHink
2022-01-25 18:39:42 -05:00
parent b038a8817b
commit 51798e483c
2 changed files with 40 additions and 10 deletions

View File

@@ -84,16 +84,7 @@ func Configure(show bool) error {
d.Nodes = append(d.Nodes, nodes...)
if controller.Dhcp.Template == "" {
templateFile = path.Join(buildconfig.SYSCONFDIR(), "warewulf/dhcp/default-dhcpd.conf")
} else {
if strings.HasPrefix(controller.Dhcp.Template, "/") {
templateFile = controller.Dhcp.Template
} else {
templateFile = path.Join(buildconfig.SYSCONFDIR(), "warewulf/dhcp/"+controller.Dhcp.Template+"dhcpd.conf")
}
}
templateFile = dhcpTemplateFile(controller.Dhcp.Template)
tmpl, err := template.New(path.Base(templateFile)).ParseFiles(templateFile)
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
@@ -137,3 +128,17 @@ func Configure(show bool) error {
return nil
}
// dhcpTemplateFile returns the path of the warewulf dhcp template given controller.Dhcp.Template.
func dhcpTemplateFile(controllerDhcpTemplate string) (templateFile string) {
if controllerDhcpTemplate == "" {
templateFile = path.Join(buildconfig.SYSCONFDIR(), "warewulf/dhcp/default-dhcpd.conf")
} else {
if strings.HasPrefix(controllerDhcpTemplate, "/") {
templateFile = controllerDhcpTemplate
} else {
templateFile = path.Join(buildconfig.SYSCONFDIR(), "warewulf/dhcp/"+controllerDhcpTemplate+"-dhcpd.conf")
}
}
return
}