stages/systemd.unit.create: validate filename sections
Based on the filename, different sections of the unit configuration are valid. Service (.service) units require a [Service] section and mount (.mount) units requires a [Mount] section. It might be possible to validate this in the schema but it would probably require a major rewrite and could get complicated. For now, validate it in the stage code itself.
This commit is contained in:
parent
835b49d052
commit
5d57f84d4d
1 changed files with 8 additions and 0 deletions
|
|
@ -13,6 +13,14 @@ def main(tree, options):
|
|||
|
||||
cfg = options["config"]
|
||||
|
||||
# Filename extension must match the config:
|
||||
# .service requires a Service section
|
||||
# .mount requires a Mount section
|
||||
if filename.endswith(".service") and "Service" not in cfg:
|
||||
raise ValueError(f"Error: {filename} unit requires Service section")
|
||||
if filename.endswith(".mount") and "Mount" not in cfg:
|
||||
raise ValueError(f"Error: {filename} unit requires Mount section")
|
||||
|
||||
# We trick configparser into letting us write multiple instances of the same option by writing them as keys with no
|
||||
# value, so we enable allow_no_value
|
||||
config = configparser.ConfigParser(allow_no_value=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue