osbuild2: extract unit drop-ins from systemd -> systemd.unit

The part creating Systemd unit drop-ins was extracted from
`org.osbuild.systemd` stage to `org.osbuild.systemd.unit`,
before the osbuild v30 release. Update the composer implementation
to reflect the change.

Related to https://github.com/osbuild/osbuild/pull/739.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
Tomas Hozza 2021-07-26 16:05:58 +02:00 committed by Tomas Hozza
parent 49aebf1c68
commit cdc65f82da
5 changed files with 53 additions and 27 deletions

View file

@ -81,6 +81,8 @@ func (stage *Stage) UnmarshalJSON(data []byte) error {
options = new(RHSMStageOptions)
case "org.osbuild.systemd":
options = new(SystemdStageOptions)
case "org.osbuild.systemd.unit":
options = new(SystemdUnitStageOptions)
case "org.osbuild.systemd-logind":
options = new(SystemdLogindStageOptions)
case "org.osbuild.script":

View file

@ -448,21 +448,19 @@ func TestStage_UnmarshalJSON(t *testing.T) {
{
name: "systemd-unit-dropins",
fields: fields{
Type: "org.osbuild.systemd",
Options: &SystemdStageOptions{
UnitDropins: map[string]SystemdServiceUnitDropins{
"nm-cloud-setup.service": {
"10-rh-enable-for-ec2.conf": {
Service: &SystemdUnitServiceSection{
Environment: "NM_CLOUD_SETUP_EC2=yes",
},
},
Type: "org.osbuild.systemd.unit",
Options: &SystemdUnitStageOptions{
Unit: "nm-cloud-setup.service",
Dropin: "10-rh-enable-for-ec2.conf",
Config: SystemdServiceUnitDropin{
Service: &SystemdUnitServiceSection{
Environment: "NM_CLOUD_SETUP_EC2=yes",
},
},
},
},
args: args{
data: []byte(`{"type":"org.osbuild.systemd","options":{"unit_dropins":{"nm-cloud-setup.service":{"10-rh-enable-for-ec2.conf":{"Service":{"Environment":"NM_CLOUD_SETUP_EC2=yes"}}}}}}`),
data: []byte(`{"type":"org.osbuild.systemd.unit","options":{"unit":"nm-cloud-setup.service","dropin":"10-rh-enable-for-ec2.conf","config":{"Service":{"Environment":"NM_CLOUD_SETUP_EC2=yes"}}}}`),
},
},
{

View file

@ -4,9 +4,6 @@ type SystemdStageOptions struct {
EnabledServices []string `json:"enabled_services,omitempty"`
DisabledServices []string `json:"disabled_services,omitempty"`
DefaultTarget string `json:"default_target,omitempty"`
// For now we support only .service drop-ins, but this may change in the future
UnitDropins map[string]SystemdServiceUnitDropins `json:"unit_dropins,omitempty"`
}
func (SystemdStageOptions) isStageOptions() {}
@ -17,17 +14,3 @@ func NewSystemdStage(options *SystemdStageOptions) *Stage {
Options: options,
}
}
// Drop-in configurations for a '.service' unit
type SystemdServiceUnitDropins map[string]SystemdServiceUnitDropin
// Drop-in configuration for a '.service' unit
type SystemdServiceUnitDropin struct {
Service *SystemdUnitServiceSection `json:"Service,omitempty"`
}
// 'Service' configuration section of a unit file
type SystemdUnitServiceSection struct {
// Sets environment variables for executed process
Environment string `json:"Environment,omitempty"`
}

View file

@ -0,0 +1,27 @@
package osbuild2
type SystemdUnitStageOptions struct {
Unit string `json:"unit"`
Dropin string `json:"dropin"`
Config SystemdServiceUnitDropin `json:"config"`
}
func (SystemdUnitStageOptions) isStageOptions() {}
func NewSystemdUnitStage(options *SystemdUnitStageOptions) *Stage {
return &Stage{
Type: "org.osbuild.systemd.unit",
Options: options,
}
}
// Drop-in configuration for a '.service' unit
type SystemdServiceUnitDropin struct {
Service *SystemdUnitServiceSection `json:"Service,omitempty"`
}
// 'Service' configuration section of a unit file
type SystemdUnitServiceSection struct {
// Sets environment variables for executed process
Environment string `json:"Environment,omitempty"`
}

View file

@ -0,0 +1,16 @@
package osbuild2
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewSystemdUnitStage(t *testing.T) {
expectedStage := &Stage{
Type: "org.osbuild.systemd.unit",
Options: &SystemdUnitStageOptions{},
}
actualStage := NewSystemdUnitStage(&SystemdUnitStageOptions{})
assert.Equal(t, expectedStage, actualStage)
}