Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sysconfig stage #1188

Merged
merged 4 commits into from Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -45,7 +45,7 @@ provided infrastructure and services.

The requirements for this project are:

* `osbuild >= 23`
* `osbuild >= 24`
* `systemd >= 244`

At build-time, the following software is required:
Expand Down
2 changes: 1 addition & 1 deletion Schutzfile
Expand Up @@ -9,7 +9,7 @@
"rhel-8.3": {
"dependencies": {
"osbuild": {
"commit": "5aee7b9fa724575daa010a55cad0558fbb7b9ad1"
"commit": "20a142d8f9b8b5d0a69f4d91631dc94118d209ca"
}
},
"dependants": {
Expand Down
5 changes: 5 additions & 0 deletions docs/news/unreleased/osbuild-24.md
@@ -0,0 +1,5 @@
# OSBuild: spec: update to osbuild version 24

In order to add the newly supported sysconfig stage, the osbuild dependency
needs to be updated to version 24. This update is reflected in both the spec
file dependency and in the testing dependency.
13 changes: 13 additions & 0 deletions docs/news/unreleased/sysconfig.md
@@ -0,0 +1,13 @@
# RHEL 8.4: add support for org.osbuild.sysconfig stage

The kernel and network sysconfigs need to have certain values set in RHEL 8.4.
Currently, the following values are set for all image types in 8.4:

kernel:
UPDATEDEFAULT=yes
DEFAULTKERNEL=kernel

network:
NETWORKING=yes
NOZEROCONF=yes

12 changes: 12 additions & 0 deletions internal/distro/rhel84/distro.go
Expand Up @@ -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{
Expand Down
25 changes: 25 additions & 0 deletions internal/osbuild/sysconfig_stage.go
@@ -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,
}
}
16 changes: 16 additions & 0 deletions internal/osbuild/sysconfig_stage_test.go
@@ -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)
}
4 changes: 2 additions & 2 deletions osbuild-composer.spec
Expand Up @@ -272,8 +272,8 @@ The core osbuild-composer binary. This is suitable both for spawning in containe
Summary: The worker for osbuild-composer
Requires: systemd
Requires: qemu-img
Requires: osbuild >= 23
Requires: osbuild-ostree >= 23
Requires: osbuild >= 24
Requires: osbuild-ostree >= 24

# remove in F34
Obsoletes: golang-github-osbuild-composer-worker < %{version}-%{release}
Expand Down
23 changes: 23 additions & 0 deletions test/data/manifests/rhel_84-x86_64-ami-boot.json
Expand Up @@ -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": {
Expand Down Expand Up @@ -9700,6 +9713,16 @@
"udisks2.service",
"unbound-anchor.timer"
],
"sysconfig": {
"kernel": {
"DEFAULTKERNEL": "kernel",
"UPDATEDEFAULT": "yes"
},
"network": {
"NETWORKING": "yes",
"NOZEROCONF": "yes"
}
},
"timezone": "New_York"
}
}
23 changes: 23 additions & 0 deletions test/data/manifests/rhel_84-x86_64-openstack-boot.json
Expand Up @@ -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": {
Expand Down Expand Up @@ -10321,6 +10334,16 @@
"udisks2.service",
"unbound-anchor.timer"
],
"sysconfig": {
"kernel": {
"DEFAULTKERNEL": "kernel",
"UPDATEDEFAULT": "yes"
},
"network": {
"NETWORKING": "yes",
"NOZEROCONF": "yes"
}
},
"timezone": "New_York"
}
}
23 changes: 23 additions & 0 deletions test/data/manifests/rhel_84-x86_64-qcow2-boot.json
Expand Up @@ -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": {
Expand Down Expand Up @@ -10168,6 +10181,16 @@
"tuned.service",
"unbound-anchor.timer"
],
"sysconfig": {
"kernel": {
"DEFAULTKERNEL": "kernel",
"UPDATEDEFAULT": "yes"
},
"network": {
"NETWORKING": "yes",
"NOZEROCONF": "yes"
}
},
"timezone": "New_York"
}
}
23 changes: 23 additions & 0 deletions test/data/manifests/rhel_84-x86_64-qcow2-customize.json
Expand Up @@ -3567,6 +3567,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": {
Expand Down Expand Up @@ -10271,6 +10284,16 @@
"tuned.service",
"unbound-anchor.timer"
],
"sysconfig": {
"kernel": {
"DEFAULTKERNEL": "kernel",
"UPDATEDEFAULT": "yes"
},
"network": {
"NETWORKING": "yes",
"NOZEROCONF": "yes"
}
},
"timezone": "London"
}
}
23 changes: 23 additions & 0 deletions test/data/manifests/rhel_84-x86_64-vhd-boot.json
Expand Up @@ -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": {
Expand Down Expand Up @@ -10248,6 +10261,16 @@
"unbound-anchor.timer",
"waagent.service"
],
"sysconfig": {
"kernel": {
"DEFAULTKERNEL": "kernel",
"UPDATEDEFAULT": "yes"
},
"network": {
"NETWORKING": "yes",
"NOZEROCONF": "yes"
}
},
"timezone": "New_York"
}
}
23 changes: 23 additions & 0 deletions test/data/manifests/rhel_84-x86_64-vmdk-boot.json
Expand Up @@ -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": {
Expand Down Expand Up @@ -9873,6 +9886,16 @@
"vgauthd.service",
"vmtoolsd.service"
],
"sysconfig": {
"kernel": {
"DEFAULTKERNEL": "kernel",
"UPDATEDEFAULT": "yes"
},
"network": {
"NETWORKING": "yes",
"NOZEROCONF": "yes"
}
},
"timezone": "New_York"
}
}
28 changes: 28 additions & 0 deletions tools/image-info
Expand Up @@ -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"):
Expand Down Expand Up @@ -389,6 +413,10 @@ def append_filesystem(report, tree, *, is_ostree=False):
if fstab:
report["fstab"] = fstab

sysconfig = read_sysconfig(tree)
if sysconfig:
gicmo marked this conversation as resolved.
Show resolved Hide resolved
report["sysconfig"] = sysconfig

with open(f"{tree}/etc/passwd") as f:
report["passwd"] = sorted(f.read().strip().split("\n"))

Expand Down