Fix newline handling in file, softlink, and ImportLink template functions
Use state-based routing instead of sentinel strings, so whitespace-trimming
syntax (e.g. `{{- file "name" -}}`) correctly creates all named files and
symlinks.
Fixes: #2118
Signed-off-by: Jonathon Anderson <janderson@ciq.com>
Co-authored-by: Christian Goll <cgoll@suse.com>
Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
@@ -87,7 +87,6 @@ nodes:
|
||||
log: `backupFile: true
|
||||
writeFile: true
|
||||
Filename: warewulf-default.conf
|
||||
|
||||
# This file is autogenerated by warewulf
|
||||
|
||||
[connection]
|
||||
@@ -178,7 +177,6 @@ nodes:
|
||||
log: `backupFile: true
|
||||
writeFile: true
|
||||
Filename: warewulf-default.conf
|
||||
|
||||
# This file is autogenerated by warewulf
|
||||
|
||||
[connection]
|
||||
@@ -278,7 +276,6 @@ nodes:
|
||||
log: `backupFile: true
|
||||
writeFile: true
|
||||
Filename: warewulf-tagged.conf
|
||||
|
||||
# This file is autogenerated by warewulf
|
||||
|
||||
[connection]
|
||||
@@ -343,7 +340,6 @@ nodes:
|
||||
log: `backupFile: true
|
||||
writeFile: true
|
||||
Filename: warewulf-bond0.conf
|
||||
|
||||
# This file is autogenerated by warewulf
|
||||
|
||||
[connection]
|
||||
@@ -436,7 +432,6 @@ nodes:
|
||||
log: `backupFile: true
|
||||
writeFile: true
|
||||
Filename: warewulf-bond0.conf
|
||||
|
||||
# This file is autogenerated by warewulf
|
||||
|
||||
[connection]
|
||||
@@ -528,7 +523,6 @@ nodes:
|
||||
log: `backupFile: true
|
||||
writeFile: true
|
||||
Filename: warewulf-bond0.conf
|
||||
|
||||
# This file is autogenerated by warewulf
|
||||
|
||||
[connection]
|
||||
@@ -620,7 +614,6 @@ nodes:
|
||||
log: `backupFile: true
|
||||
writeFile: true
|
||||
Filename: warewulf-bond0.conf
|
||||
|
||||
# This file is autogenerated by warewulf
|
||||
|
||||
[connection]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{{ file "warewulf-unmanaged.conf" }}
|
||||
{{- file "warewulf-unmanaged.conf" -}}
|
||||
# This file is autogenerated by warewulf
|
||||
|
||||
[main]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{{- range $devname, $netdev := .NetDevs }}
|
||||
{{ file (print "warewulf-" $devname ".conf") }}
|
||||
{{- file (print "warewulf-" $devname ".conf") -}}
|
||||
# This file is autogenerated by warewulf
|
||||
|
||||
[connection]
|
||||
|
||||
@@ -46,7 +46,6 @@ nodes:
|
||||
log: `backupFile: true
|
||||
writeFile: true
|
||||
Filename: ifcfg-default.conf
|
||||
|
||||
# This file is autogenerated by warewulf
|
||||
TYPE=Ethernet
|
||||
DEVICE=wwnet0
|
||||
@@ -116,7 +115,6 @@ nodes:
|
||||
log: `backupFile: true
|
||||
writeFile: true
|
||||
Filename: ifcfg-default.conf
|
||||
|
||||
# This file is autogenerated by warewulf
|
||||
TYPE=Ethernet
|
||||
NAME=default
|
||||
@@ -210,7 +208,6 @@ nodes:
|
||||
log: `backupFile: true
|
||||
writeFile: true
|
||||
Filename: ifcfg-tagged.conf
|
||||
|
||||
# This file is autogenerated by warewulf
|
||||
VLAN=yes
|
||||
DEVICE=eth0.902
|
||||
@@ -263,7 +260,6 @@ nodes:
|
||||
log: `backupFile: true
|
||||
writeFile: true
|
||||
Filename: ifcfg-bond0.conf
|
||||
|
||||
# This file is autogenerated by warewulf
|
||||
TYPE=Bond
|
||||
DEVICE=bond0
|
||||
@@ -333,10 +329,8 @@ nodes:
|
||||
log: `backupFile: true
|
||||
writeFile: true
|
||||
Filename: route-tagged.conf
|
||||
|
||||
# This file is autogenerated by warewulf
|
||||
192.168.1.0/24 via 192.168.2.254
|
||||
|
||||
backupFile: true
|
||||
writeFile: true
|
||||
Filename: route-untagged.conf
|
||||
@@ -363,7 +357,6 @@ nodes:
|
||||
log: `backupFile: true
|
||||
writeFile: true
|
||||
Filename: ifcfg-tagged.conf
|
||||
|
||||
# This file is autogenerated by warewulf
|
||||
VLAN=yes
|
||||
DEVICE=eth0.902
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{{- range $devname, $netdev := .NetDevs }}
|
||||
{{ file (print "ifcfg-" $devname ".conf") }}
|
||||
{{- file (print "ifcfg-" $devname ".conf") -}}
|
||||
# This file is autogenerated by warewulf
|
||||
{{- if eq $netdev.Type "vlan" }}
|
||||
VLAN=yes
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{{- range $devname, $netdev := .NetDevs }}
|
||||
{{ file (print "route-" $devname ".conf") }}
|
||||
{{- file (print "route-" $devname ".conf") -}}
|
||||
# This file is autogenerated by warewulf
|
||||
{{- range $tk, $tv := $netdev.Tags }}
|
||||
{{- if eq (substr 0 5 $tk) "route" }}
|
||||
|
||||
@@ -60,7 +60,6 @@ func Test_wickedOverlay(t *testing.T) {
|
||||
const expected_log string = `backupFile: true
|
||||
writeFile: true
|
||||
Filename: default
|
||||
|
||||
# This file is autogenerated by warewulf
|
||||
auto wwnet0
|
||||
allow-hotplug wwnet0
|
||||
@@ -69,7 +68,6 @@ iface wwnet0 inet static
|
||||
netmask 255.255.255.0
|
||||
gateway 192.168.3.1
|
||||
mtu 1500
|
||||
|
||||
backupFile: true
|
||||
writeFile: true
|
||||
Filename: secondary
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{{- range $devname, $netdev := .ThisNode.NetDevs }}
|
||||
{{ file $devname }}
|
||||
{{- file $devname -}}
|
||||
# This file is autogenerated by warewulf
|
||||
{{- if $netdev.OnBoot.BoolDefaultTrue }}
|
||||
auto {{ $netdev.Device }}
|
||||
|
||||
@@ -52,5 +52,5 @@ func Test_localtimeOverlay(t *testing.T) {
|
||||
const localtime string = `backupFile: true
|
||||
writeFile: true
|
||||
Filename: etc/localtime
|
||||
{{ /* softlink "/usr/share/zoneinfo/GMT" */ }}
|
||||
Symlink: /usr/share/zoneinfo/GMT
|
||||
`
|
||||
|
||||
@@ -35,8 +35,6 @@ nodes:
|
||||
output: `backupFile: true
|
||||
writeFile: true
|
||||
Filename: -.mount
|
||||
|
||||
|
||||
[Unit]
|
||||
Before=local-fs.target
|
||||
|
||||
@@ -50,7 +48,6 @@ RequiredBy=local-fs.target
|
||||
backupFile: true
|
||||
writeFile: true
|
||||
Filename: scratch.mount
|
||||
|
||||
[Unit]
|
||||
Before=local-fs.target
|
||||
|
||||
@@ -83,12 +80,11 @@ nodes:
|
||||
output: `backupFile: true
|
||||
writeFile: true
|
||||
Filename: -.mount
|
||||
|
||||
{{ /* softlink "/etc/systemd/system/-.mount" */ }}
|
||||
Symlink: /etc/systemd/system/-.mount
|
||||
backupFile: true
|
||||
writeFile: true
|
||||
Filename: scratch.mount
|
||||
{{ /* softlink "/etc/systemd/system/scratch.mount" */ }}
|
||||
Symlink: /etc/systemd/system/scratch.mount
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{{- range $fs := .ThisNode.FileSystemList }}
|
||||
{{- if and $fs.Path (ne $fs.Format "swap") }}
|
||||
{{- $abort = false }}
|
||||
{{ file (print ($fs.Path | SystemdEscapePath) ".mount") }}
|
||||
{{- file (print ($fs.Path | SystemdEscapePath) ".mount") -}}
|
||||
|
||||
[Unit]
|
||||
Before=local-fs.target
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{{- range $fs := .ThisNode.FileSystemList }}
|
||||
{{- if and $fs.Path (ne $fs.Format "swap") }}
|
||||
{{- $abort = false }}
|
||||
{{ file (print ($fs.Path | SystemdEscapePath) ".mount") }}
|
||||
{{- file (print ($fs.Path | SystemdEscapePath) ".mount") -}}
|
||||
{{ softlink (print "/etc/systemd/system/" ($fs.Path | SystemdEscapePath) ".mount") }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{{ range $devname, $netdev := .NetDevs -}}
|
||||
{{ file (print "10-ww4-netname-" $devname ".link") }}
|
||||
{{- file (print "10-ww4-netname-" $devname ".link") -}}
|
||||
# This file is autogenerated by warewulf
|
||||
{{- if and $netdev.Hwaddr $netdev.Device }}
|
||||
[Match]
|
||||
|
||||
@@ -59,7 +59,6 @@ func Test_systemdNetworkOverlay(t *testing.T) {
|
||||
const expected_log_with_hwaddr string = `backupFile: true
|
||||
writeFile: true
|
||||
Filename: 10-ww4-networkd-default.network
|
||||
|
||||
# This file is autogenerated by warewulf
|
||||
[Match]
|
||||
Name=wwnet0
|
||||
@@ -104,7 +103,6 @@ DUIDType=link-layer
|
||||
const expected_log_without_hwaddr string = `backupFile: true
|
||||
writeFile: true
|
||||
Filename: 10-ww4-networkd-default.network
|
||||
|
||||
# This file is autogenerated by warewulf
|
||||
[Match]
|
||||
Name=wwnet0
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{{- range $devname, $netdev := .ThisNode.NetDevs }}
|
||||
{{ file (print "10-ww4-networkd-" $devname ".network") }}
|
||||
{{- file (print "10-ww4-networkd-" $devname ".network") -}}
|
||||
# This file is autogenerated by warewulf
|
||||
[Match]
|
||||
{{- if $netdev.Device }}
|
||||
|
||||
@@ -35,8 +35,6 @@ nodes:
|
||||
output: `backupFile: true
|
||||
writeFile: true
|
||||
Filename: dev-disk-by\x2dpartlabel-swap.swap
|
||||
|
||||
|
||||
[Unit]
|
||||
Before=swap.target
|
||||
|
||||
@@ -67,8 +65,7 @@ nodes:
|
||||
output: `backupFile: true
|
||||
writeFile: true
|
||||
Filename: dev-disk-by\x2dpartlabel-swap.swap
|
||||
|
||||
{{ /* softlink "/etc/systemd/system/dev-disk-by\x2dpartlabel-swap.swap" */ }}
|
||||
Symlink: /etc/systemd/system/dev-disk-by\x2dpartlabel-swap.swap
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{{- range $fs := .ThisNode.FileSystemList }}
|
||||
{{- if eq $fs.Format "swap" }}
|
||||
{{- $abort = false }}
|
||||
{{ file (print ($fs.Id | SystemdEscapePath) ".swap") }}
|
||||
{{- file (print ($fs.Id | SystemdEscapePath) ".swap") -}}
|
||||
|
||||
[Unit]
|
||||
Before=swap.target
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{{- range $fs := .ThisNode.FileSystemList }}
|
||||
{{- if eq $fs.Format "swap" }}
|
||||
{{- $abort = false }}
|
||||
{{ file (print ($fs.Id | SystemdEscapePath) ".swap") }}
|
||||
{{- file (print ($fs.Id | SystemdEscapePath) ".swap") -}}
|
||||
{{ softlink (print "/etc/systemd/system/" ($fs.Id | SystemdEscapePath) ".swap") }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
@@ -58,7 +58,6 @@ func Test_wickedOverlay(t *testing.T) {
|
||||
const wicked string = `backupFile: true
|
||||
writeFile: true
|
||||
Filename: ifcfg-default.xml
|
||||
|
||||
<!--
|
||||
This file is autogenerated by warewulf
|
||||
-->
|
||||
@@ -90,7 +89,6 @@ This file is autogenerated by warewulf
|
||||
<accept-redirects>false</accept-redirects>
|
||||
</ipv6>
|
||||
</interface>
|
||||
|
||||
backupFile: true
|
||||
writeFile: true
|
||||
Filename: ifcfg-secondary.xml
|
||||
@@ -130,7 +128,6 @@ This file is autogenerated by warewulf
|
||||
const wicked_vlans string = `backupFile: true
|
||||
writeFile: true
|
||||
Filename: ifcfg-tagged.xml
|
||||
|
||||
<!--
|
||||
This file is autogenerated by warewulf
|
||||
-->
|
||||
@@ -168,7 +165,6 @@ This file is autogenerated by warewulf
|
||||
<accept-redirects>false</accept-redirects>
|
||||
</ipv6>
|
||||
</interface>
|
||||
|
||||
backupFile: true
|
||||
writeFile: true
|
||||
Filename: ifcfg-untagged.xml
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{{- $NetDevs := .NetDevs }}
|
||||
{{- range $devname, $netdev := .ThisNode.NetDevs }}
|
||||
{{ file (print "ifcfg-" $devname ".xml") }}
|
||||
{{- file (print "ifcfg-" $devname ".xml") -}}
|
||||
<!--
|
||||
This file is autogenerated by warewulf
|
||||
-->
|
||||
|
||||
Reference in New Issue
Block a user