distro/rhel84: add sysconfig stage

The org.osbuild.sysconfig stage is now supported. Config updates can be
made to the kernel and network files. Currently, the same values are
used for all image types in rhel84. The image-info script is updated to
allow testing the sysconfig info.
This commit is contained in:
Jacob Kozol 2021-02-01 12:56:33 +01:00 committed by jkozol
parent 12f8a1540c
commit eea18fc897
10 changed files with 219 additions and 0 deletions

View file

@ -329,6 +329,18 @@ func (t *imageType) pipeline(c *blueprint.Customizations, options distro.ImageOp
p.AddStage(osbuild.NewSELinuxStage(t.selinuxStageOptions()))
// These are the current defaults for the sysconfig stage. This can be changed to be image type exclusive if different configs are needed.
p.AddStage(osbuild.NewSysconfigStage(&osbuild.SysconfigStageOptions{
Kernel: osbuild.SysconfigKernelOptions{
UpdateDefault: true,
DefaultKernel: "kernel",
},
Network: osbuild.SysconfigNetworkOptions{
Networking: true,
NoZeroConf: true,
},
}))
if t.rpmOstree {
p.AddStage(osbuild.NewRPMOSTreeStage(&osbuild.RPMOSTreeStageOptions{
EtcGroupMembers: []string{

View file

@ -0,0 +1,25 @@
package osbuild
type SysconfigStageOptions struct {
Kernel SysconfigKernelOptions `json:"kernel,omitempty"`
Network SysconfigNetworkOptions `json:"network,omitempty"`
}
type SysconfigNetworkOptions struct {
Networking bool `json:"networking,omitempty"`
NoZeroConf bool `json:"no_zero_conf,omitempty"`
}
type SysconfigKernelOptions struct {
UpdateDefault bool `json:"update_default,omitempty"`
DefaultKernel string `json:"default_kernel,omitempty"`
}
func (SysconfigStageOptions) isStageOptions() {}
func NewSysconfigStage(options *SysconfigStageOptions) *Stage {
return &Stage{
Name: "org.osbuild.sysconfig",
Options: options,
}
}

View file

@ -0,0 +1,16 @@
package osbuild
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewSysconfigStage(t *testing.T) {
expectedStage := &Stage{
Name: "org.osbuild.sysconfig",
Options: &SysconfigStageOptions{},
}
actualStage := NewSysconfigStage(&SysconfigStageOptions{})
assert.Equal(t, expectedStage, actualStage)
}

View file

@ -3285,6 +3285,19 @@
"options": {
"file_contexts": "etc/selinux/targeted/contexts/files/file_contexts"
}
},
{
"name": "org.osbuild.sysconfig",
"options": {
"kernel": {
"update_default": true,
"default_kernel": "kernel"
},
"network": {
"networking": true,
"no_zero_conf": true
}
}
}
],
"assembler": {
@ -9700,6 +9713,16 @@
"udisks2.service",
"unbound-anchor.timer"
],
"sysconfig": {
"kernel": {
"DEFAULTKERNEL": "kernel",
"UPDATEDEFAULT": "yes"
},
"network": {
"NETWORKING": "yes",
"NOZEROCONF": "yes"
}
},
"timezone": "New_York"
}
}

View file

@ -3528,6 +3528,19 @@
"options": {
"file_contexts": "etc/selinux/targeted/contexts/files/file_contexts"
}
},
{
"name": "org.osbuild.sysconfig",
"options": {
"kernel": {
"update_default": true,
"default_kernel": "kernel"
},
"network": {
"networking": true,
"no_zero_conf": true
}
}
}
],
"assembler": {
@ -10321,6 +10334,16 @@
"udisks2.service",
"unbound-anchor.timer"
],
"sysconfig": {
"kernel": {
"DEFAULTKERNEL": "kernel",
"UPDATEDEFAULT": "yes"
},
"network": {
"NETWORKING": "yes",
"NOZEROCONF": "yes"
}
},
"timezone": "New_York"
}
}

View file

@ -3468,6 +3468,19 @@
"options": {
"file_contexts": "etc/selinux/targeted/contexts/files/file_contexts"
}
},
{
"name": "org.osbuild.sysconfig",
"options": {
"kernel": {
"update_default": true,
"default_kernel": "kernel"
},
"network": {
"networking": true,
"no_zero_conf": true
}
}
}
],
"assembler": {
@ -10168,6 +10181,16 @@
"tuned.service",
"unbound-anchor.timer"
],
"sysconfig": {
"kernel": {
"DEFAULTKERNEL": "kernel",
"UPDATEDEFAULT": "yes"
},
"network": {
"NETWORKING": "yes",
"NOZEROCONF": "yes"
}
},
"timezone": "New_York"
}
}

View file

@ -3573,6 +3573,19 @@
"options": {
"file_contexts": "etc/selinux/targeted/contexts/files/file_contexts"
}
},
{
"name": "org.osbuild.sysconfig",
"options": {
"kernel": {
"update_default": true,
"default_kernel": "kernel"
},
"network": {
"networking": true,
"no_zero_conf": true
}
}
}
],
"assembler": {
@ -10278,6 +10291,16 @@
"tuned.service",
"unbound-anchor.timer"
],
"sysconfig": {
"kernel": {
"DEFAULTKERNEL": "kernel",
"UPDATEDEFAULT": "yes"
},
"network": {
"NETWORKING": "yes",
"NOZEROCONF": "yes"
}
},
"timezone": "London"
}
}

View file

@ -3499,6 +3499,19 @@
"options": {
"file_contexts": "etc/selinux/targeted/contexts/files/file_contexts"
}
},
{
"name": "org.osbuild.sysconfig",
"options": {
"kernel": {
"update_default": true,
"default_kernel": "kernel"
},
"network": {
"networking": true,
"no_zero_conf": true
}
}
}
],
"assembler": {
@ -10248,6 +10261,16 @@
"unbound-anchor.timer",
"waagent.service"
],
"sysconfig": {
"kernel": {
"DEFAULTKERNEL": "kernel",
"UPDATEDEFAULT": "yes"
},
"network": {
"NETWORKING": "yes",
"NOZEROCONF": "yes"
}
},
"timezone": "New_York"
}
}

View file

@ -3357,6 +3357,19 @@
"options": {
"file_contexts": "etc/selinux/targeted/contexts/files/file_contexts"
}
},
{
"name": "org.osbuild.sysconfig",
"options": {
"kernel": {
"update_default": true,
"default_kernel": "kernel"
},
"network": {
"networking": true,
"no_zero_conf": true
}
}
}
],
"assembler": {
@ -9873,6 +9886,16 @@
"vgauthd.service",
"vmtoolsd.service"
],
"sysconfig": {
"kernel": {
"DEFAULTKERNEL": "kernel",
"UPDATEDEFAULT": "yes"
},
"network": {
"NETWORKING": "yes",
"NOZEROCONF": "yes"
}
},
"timezone": "New_York"
}
}

View file

@ -358,6 +358,30 @@ def read_fstab(tree):
result = sorted([line.split() for line in f if line and not line.startswith("#")])
return result
# Create a nested dictionary for all supported sysconfigs
def read_sysconfig(tree):
result = {}
sysconfig_paths = {
"kernel": f"{tree}/etc/sysconfig/kernel",
"network": f"{tree}/etc/sysconfig/network"
}
# iterate through supported configs
# based on https://github.com/osbuild/osbuild/blob/main/osbuild/util/osrelease.py#L17
for name, path in sysconfig_paths.items():
with contextlib.suppress(FileNotFoundError):
with open(path) as f:
# if file exists start with empty array of values
result[name] = {}
for line in f:
line = line.strip()
if not line:
continue
if line[0] == "#":
continue
key, value = line.split("=", 1)
result[name][key] = value.strip('"')
return result
def append_filesystem(report, tree, *, is_ostree=False):
if os.path.exists(f"{tree}/etc/os-release"):
@ -389,6 +413,10 @@ def append_filesystem(report, tree, *, is_ostree=False):
if fstab:
report["fstab"] = fstab
sysconfig = read_sysconfig(tree)
if sysconfig:
report["sysconfig"] = sysconfig
with open(f"{tree}/etc/passwd") as f:
report["passwd"] = sorted(f.read().strip().split("\n"))