osbuild2: support 'install' command in the modprobe stage
Add support for the 'install' modprobe command in the modprobe osbuild stage implementation. Extend unit tests to verify marshalling the stage options into JSON. Related to https://github.com/osbuild/osbuild/pull/867. Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
parent
dd0f01edf5
commit
801c9fadab
2 changed files with 36 additions and 1 deletions
|
|
@ -55,6 +55,16 @@ func (configFile *ModprobeConfigCmdList) UnmarshalJSON(data []byte) error {
|
|||
return fmt.Errorf("'modulename' item should be string, not %T", configCmdMap["modulename"])
|
||||
}
|
||||
modprobeCmd = NewModprobeConfigCmdBlacklist(modulename)
|
||||
case "install":
|
||||
modulename, ok := configCmdMap["modulename"].(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("'modulename' item should be string, not %T", configCmdMap["modulename"])
|
||||
}
|
||||
cmdline, ok := configCmdMap["cmdline"].(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("'cmdline' item should be string, not %T", configCmdMap["cmdline"])
|
||||
}
|
||||
modprobeCmd = NewModprobeConfigCmdInstall(modulename, cmdline)
|
||||
default:
|
||||
return fmt.Errorf("unexpected modprobe command: %s", command)
|
||||
}
|
||||
|
|
@ -90,3 +100,23 @@ func NewModprobeConfigCmdBlacklist(modulename string) *ModprobeConfigCmdBlacklis
|
|||
Modulename: modulename,
|
||||
}
|
||||
}
|
||||
|
||||
// ModprobeConfigCmdInstall represents the 'install' command in the
|
||||
// modprobe configuration.
|
||||
type ModprobeConfigCmdInstall struct {
|
||||
Command string `json:"command"`
|
||||
Modulename string `json:"modulename"`
|
||||
Cmdline string `json:"cmdline"`
|
||||
}
|
||||
|
||||
func (ModprobeConfigCmdInstall) isModprobeConfigCmd() {}
|
||||
|
||||
// NewModprobeConfigCmdInstall creates a new instance of ModprobeConfigCmdInstall
|
||||
// for the provided modulename.
|
||||
func NewModprobeConfigCmdInstall(modulename, cmdline string) *ModprobeConfigCmdInstall {
|
||||
return &ModprobeConfigCmdInstall{
|
||||
Command: "install",
|
||||
Modulename: modulename,
|
||||
Cmdline: cmdline,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -321,11 +321,16 @@ func TestStage_UnmarshalJSON(t *testing.T) {
|
|||
Command: "blacklist",
|
||||
Modulename: "floppy",
|
||||
},
|
||||
&ModprobeConfigCmdInstall{
|
||||
Command: "install",
|
||||
Modulename: "nf_conntrack",
|
||||
Cmdline: "/usr/sbin/modprobe --ignore-install nf_conntrack $CMDLINE_OPTS && /usr/sbin/sysctl --quiet --pattern 'net[.]netfilter[.]nf_conntrack.*' --system",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
args: args{
|
||||
data: []byte(`{"type":"org.osbuild.modprobe","options":{"filename":"disallow-modules.conf","commands":[{"command":"blacklist","modulename":"nouveau"},{"command":"blacklist","modulename":"floppy"}]}}`),
|
||||
data: []byte(`{"type":"org.osbuild.modprobe","options":{"filename":"disallow-modules.conf","commands":[{"command":"blacklist","modulename":"nouveau"},{"command":"blacklist","modulename":"floppy"},{"command":"install","modulename":"nf_conntrack","cmdline":"/usr/sbin/modprobe --ignore-install nf_conntrack $CMDLINE_OPTS \u0026\u0026 /usr/sbin/sysctl --quiet --pattern 'net[.]netfilter[.]nf_conntrack.*' --system"}]}}`),
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue