osbuild2: support for network-scripts option in org.osbuild.sysconfig
Add support for the newly added `network-scripts` option in the `org.osbuild.sysconfig` osbuild stage [1]. The stage allows one to create `ifcfg` configuration files under `/etc/sysconfig/network-scripts`. Add unit test cases for the added functionality as well as for other options of the stage, which were missing. [1] https://github.com/osbuild/osbuild/pull/663 Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
parent
bef4628a08
commit
9957f378ca
2 changed files with 114 additions and 9 deletions
|
|
@ -307,6 +307,57 @@ func TestStage_UnmarshalJSON(t *testing.T) {
|
|||
data: []byte(`{"type":"org.osbuild.selinux","options":{"file_contexts":""}}`),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sysconfig",
|
||||
fields: fields{
|
||||
Type: "org.osbuild.sysconfig",
|
||||
Options: &SysconfigStageOptions{},
|
||||
},
|
||||
args: args{
|
||||
data: []byte(`{"type":"org.osbuild.sysconfig","options":{"kernel":{},"network":{}}}`),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sysconfig-data",
|
||||
fields: fields{
|
||||
Type: "org.osbuild.sysconfig",
|
||||
Options: &SysconfigStageOptions{
|
||||
Kernel: SysconfigKernelOptions{
|
||||
UpdateDefault: true,
|
||||
DefaultKernel: "kernel",
|
||||
},
|
||||
Network: SysconfigNetworkOptions{
|
||||
Networking: true,
|
||||
NoZeroConf: true,
|
||||
},
|
||||
NetworkScripts: &NetworkScriptsOptions{
|
||||
IfcfgFiles: map[string]IfcfgFile{
|
||||
"eth0": {
|
||||
Device: "eth0",
|
||||
Bootproto: IfcfgBootprotoDHCP,
|
||||
OnBoot: common.BoolToPtr(true),
|
||||
Type: IfcfgTypeEthernet,
|
||||
UserCtl: common.BoolToPtr(true),
|
||||
PeerDNS: common.BoolToPtr(true),
|
||||
IPv6Init: common.BoolToPtr(false),
|
||||
},
|
||||
"eth1": {
|
||||
Device: "eth1",
|
||||
Bootproto: IfcfgBootprotoDHCP,
|
||||
OnBoot: common.BoolToPtr(true),
|
||||
Type: IfcfgTypeEthernet,
|
||||
UserCtl: common.BoolToPtr(false),
|
||||
PeerDNS: common.BoolToPtr(true),
|
||||
IPv6Init: common.BoolToPtr(true),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
args: args{
|
||||
data: []byte(`{"type":"org.osbuild.sysconfig","options":{"kernel":{"update_default":true,"default_kernel":"kernel"},"network":{"networking":true,"no_zero_conf":true},"network-scripts":{"ifcfg":{"eth0":{"bootproto":"dhcp","device":"eth0","ipv6init":false,"onboot":true,"peerdns":true,"type":"Ethernet","userctl":true},"eth1":{"bootproto":"dhcp","device":"eth1","ipv6init":true,"onboot":true,"peerdns":true,"type":"Ethernet","userctl":false}}}}}`),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "systemd",
|
||||
fields: fields{
|
||||
|
|
|
|||
|
|
@ -1,8 +1,18 @@
|
|||
package osbuild2
|
||||
|
||||
type SysconfigStageOptions struct {
|
||||
Kernel SysconfigKernelOptions `json:"kernel,omitempty"`
|
||||
Network SysconfigNetworkOptions `json:"network,omitempty"`
|
||||
Kernel SysconfigKernelOptions `json:"kernel,omitempty"`
|
||||
Network SysconfigNetworkOptions `json:"network,omitempty"`
|
||||
NetworkScripts *NetworkScriptsOptions `json:"network-scripts,omitempty"`
|
||||
}
|
||||
|
||||
func (SysconfigStageOptions) isStageOptions() {}
|
||||
|
||||
func NewSysconfigStage(options *SysconfigStageOptions) *Stage {
|
||||
return &Stage{
|
||||
Type: "org.osbuild.sysconfig",
|
||||
Options: options,
|
||||
}
|
||||
}
|
||||
|
||||
type SysconfigNetworkOptions struct {
|
||||
|
|
@ -15,11 +25,55 @@ type SysconfigKernelOptions struct {
|
|||
DefaultKernel string `json:"default_kernel,omitempty"`
|
||||
}
|
||||
|
||||
func (SysconfigStageOptions) isStageOptions() {}
|
||||
|
||||
func NewSysconfigStage(options *SysconfigStageOptions) *Stage {
|
||||
return &Stage{
|
||||
Type: "org.osbuild.sysconfig",
|
||||
Options: options,
|
||||
}
|
||||
type NetworkScriptsOptions struct {
|
||||
// Keys are interface names, values are objects containing interface configuration
|
||||
IfcfgFiles map[string]IfcfgFile `json:"ifcfg,omitempty"`
|
||||
}
|
||||
|
||||
type IfcfgBootprotoValue string
|
||||
|
||||
// Valid values for the 'Bootproto' item of 'IfcfgFile' struct
|
||||
const (
|
||||
IfcfgBootprotoNone IfcfgBootprotoValue = "none"
|
||||
IfcfgBootprotoBootp IfcfgBootprotoValue = "bootp"
|
||||
IfcfgBootprotoDHCP IfcfgBootprotoValue = "dhcp"
|
||||
IfcfgBootprotoStatic IfcfgBootprotoValue = "static"
|
||||
IfcfgBootprotoIbft IfcfgBootprotoValue = "ibft"
|
||||
IfcfgBootprotoAutoIP IfcfgBootprotoValue = "autoip"
|
||||
IfcfgBootprotoShared IfcfgBootprotoValue = "shared"
|
||||
)
|
||||
|
||||
type IfcfgTypeValue string
|
||||
|
||||
// Valid values for the 'Type' item of 'IfcfgFile' struct
|
||||
const (
|
||||
IfcfgTypeEthernet IfcfgTypeValue = "Ethernet"
|
||||
IfcfgTypeWireless IfcfgTypeValue = "Wireless"
|
||||
IfcfgTypeInfiniBand IfcfgTypeValue = "InfiniBand"
|
||||
IfcfgTypeBridge IfcfgTypeValue = "Bridge"
|
||||
IfcfgTypeBond IfcfgTypeValue = "Bond"
|
||||
IfcfgTypeVLAN IfcfgTypeValue = "Vlan"
|
||||
)
|
||||
|
||||
type IfcfgFile struct {
|
||||
// Method used for IPv4 protocol configuration
|
||||
Bootproto IfcfgBootprotoValue `json:"bootproto,omitempty"`
|
||||
|
||||
// Interface name of the device
|
||||
Device string `json:"device,omitempty"`
|
||||
|
||||
// Whether to initialize this device for IPv6 addressing
|
||||
IPv6Init *bool `json:"ipv6init,omitempty"`
|
||||
|
||||
// Whether the connection should be autoconnected
|
||||
OnBoot *bool `json:"onboot,omitempty"`
|
||||
|
||||
// Whether to modify /etc/resolv.conf
|
||||
PeerDNS *bool `json:"peerdns,omitempty"`
|
||||
|
||||
// Base type of the connection
|
||||
Type IfcfgTypeValue `json:"type,omitempty"`
|
||||
|
||||
// Whether non-root users are allowed to control the device
|
||||
UserCtl *bool `json:"userctl,omitempty"`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue