stages/dracut: write only one config file

Instead of supporting writing an arbitrary number of configuration
files, just write one. This makes the stage and its schema clearer
and simpler. If more than one config file is needed, the stage can
be repeated multiple times. It is also more flexible since we can
in the future specify additional options at the top level which
will then be per-file, like a top-level comment.
This commit is contained in:
Christian Kellner 2021-07-21 08:41:55 +00:00
parent a1703dc298
commit 0190c991ae
3 changed files with 99 additions and 116 deletions

View file

@ -2,20 +2,13 @@
"""
Configure dracut.
The 'config' option allows to create dracut configuration files under
`/usr/lib/dracut/dracut.conf.d/`. Only a subset of configuration options is
supported, with the intention to provide functional parity with
`org.osbuild.dracut` stage.
Each stage option represents a "*.conf" file, which will be created. Its value
is a dictionary with keys representing the allowed `dracut.conf` options
representing the option value. The value type is specific to each configuration
option and may be string, list of strings or boolean value.
The 'config' option allows to create a dracut configuration file under
`/usr/lib/dracut/dracut.conf.d/` with the name `filename`. Only a subset
of configuration options is supported, with the intention to provide
functional parity with `org.osbuild.dracut` stage.
Constrains:
- At least one configuration file must be defined in the stage options.
- At least one configuration option must be specified for each configuration
file.
Supported configuration options:
- compress
@ -38,96 +31,94 @@ import osbuild.api
SCHEMA = r"""
"additionalProperties": false,
"required": ["config", "filename"],
"properties": {
"filename": {
"type": "string",
"description": "Name of the dracut configuration file.",
"pattern": "^[\\w.-]{1,250}\\.conf$"
},
"config": {
"additionalProperties": false,
"type": "object",
"description": "dracut configuration files.",
"description": "dracut configuration.",
"minProperties": 1,
"patternProperties": {
"^[\\w.-]{1,250}\\.conf$": {
"additionalProperties": false,
"type": "object",
"description": "dracut configuration file.",
"minProperties": 1,
"properties": {
"compress": {
"description": "Compress the generated initramfs using the passed compression program.",
"type": "string"
},
"dracutmodules": {
"description": "Exact list of dracut modules to use.",
"type": "array",
"items": {
"type": "string",
"description": "A dracut module, e.g. base, nfs, network ..."
}
},
"add_dracutmodules": {
"description": "Additional dracut modules to include.",
"type": "array",
"items": {
"type": "string",
"description": "A dracut module, e.g. base, nfs, network ..."
}
},
"omit_dracutmodules": {
"description": "Dracut modules to not include.",
"type": "array",
"items": {
"type": "string",
"description": "A dracut module, e.g. base, nfs, network ..."
}
},
"drivers": {
"description": "Kernel modules to exclusively include.",
"type": "array",
"items": {
"type": "string",
"description": "A kernel module without the .ko extension."
}
},
"add_drivers": {
"description": "Add a specific kernel modules.",
"type": "array",
"items": {
"type": "string",
"description": "A kernel module without the .ko extension."
}
},
"force_drivers": {
"description": "Add driver and ensure that they are tried to be loaded.",
"type": "array",
"items": {
"type": "string",
"description": "A kernel module without the .ko extension."
}
},
"filesystems": {
"description": "Kernel filesystem modules to exclusively include.",
"type": "array",
"items": {
"type": "string",
"description": "A kernel module without the .ko extension."
}
},
"install_items": {
"description": "Install the specified files.",
"type": "array",
"items": {
"type": "string",
"description": "Specify additional files to include in the initramfs."
}
},
"early_microcode": {
"description": "Combine early microcode with the initramfs.",
"type": "boolean"
},
"reproducible": {
"description": "Create reproducible images.",
"type": "boolean"
}
"properties": {
"compress": {
"description": "Compress the generated initramfs using the passed compression program.",
"type": "string"
},
"dracutmodules": {
"description": "Exact list of dracut modules to use.",
"type": "array",
"items": {
"type": "string",
"description": "A dracut module, e.g. base, nfs, network ..."
}
},
"add_dracutmodules": {
"description": "Additional dracut modules to include.",
"type": "array",
"items": {
"type": "string",
"description": "A dracut module, e.g. base, nfs, network ..."
}
},
"omit_dracutmodules": {
"description": "Dracut modules to not include.",
"type": "array",
"items": {
"type": "string",
"description": "A dracut module, e.g. base, nfs, network ..."
}
},
"drivers": {
"description": "Kernel modules to exclusively include.",
"type": "array",
"items": {
"type": "string",
"description": "A kernel module without the .ko extension."
}
},
"add_drivers": {
"description": "Add a specific kernel modules.",
"type": "array",
"items": {
"type": "string",
"description": "A kernel module without the .ko extension."
}
},
"force_drivers": {
"description": "Add driver and ensure that they are tried to be loaded.",
"type": "array",
"items": {
"type": "string",
"description": "A kernel module without the .ko extension."
}
},
"filesystems": {
"description": "Kernel filesystem modules to exclusively include.",
"type": "array",
"items": {
"type": "string",
"description": "A kernel module without the .ko extension."
}
},
"install_items": {
"description": "Install the specified files.",
"type": "array",
"items": {
"type": "string",
"description": "Specify additional files to include in the initramfs."
}
},
"early_microcode": {
"description": "Combine early microcode with the initramfs.",
"type": "boolean"
},
"reproducible": {
"description": "Create reproducible images.",
"type": "boolean"
}
}
}
@ -158,7 +149,10 @@ def bool_option_writer(f, option, value):
f.write(f'{option}="{bool_to_string(value)}"\n')
def create_configuration_file(tree, filename, options):
def main(tree, options):
config = options["config"]
filename = options["filename"]
config_files_dir = f"{tree}/usr/lib/dracut/dracut.conf.d"
SUPPORTED_OPTIONS = {
@ -179,7 +173,7 @@ def create_configuration_file(tree, filename, options):
}
with open(f"{config_files_dir}/{filename}", "w") as f:
for option, value in options.items():
for option, value in config.items():
try:
writter_func = SUPPORTED_OPTIONS[option]
writter_func(f, option, value)
@ -187,15 +181,6 @@ def create_configuration_file(tree, filename, options):
raise ValueError(f"unsupported configuration option '{option}'") from e
def main(tree, options):
configuration_files_options = options.get("config", {})
for configuration_file, configuration_options in configuration_files_options.items():
create_configuration_file(tree, configuration_file, configuration_options)
return 0
if __name__ == '__main__':
args = osbuild.api.arguments()
r = main(args["tree"], args["options"])

View file

@ -457,12 +457,11 @@
{
"name": "org.osbuild.dracut.conf",
"options": {
"filename": "sgdisk.conf",
"config": {
"sgdisk.conf": {
"install_items": [
"sgdisk"
]
}
"install_items": [
"sgdisk"
]
}
}
}

View file

@ -32,12 +32,11 @@
{
"name": "org.osbuild.dracut.conf",
"options": {
"filename": "sgdisk.conf",
"config": {
"sgdisk.conf": {
"install_items": [
"sgdisk"
]
}
"install_items": [
"sgdisk"
]
}
}
}