[Output]
CacheDirectory=mkosi.cache
+
+[Content]
+Autologin=yes
+BiosBootloader=grub
KernelCommandLine=console=ttyS0
systemd.unit=mkosi-check-and-shutdown.service
systemd.log_target=console
systemd.default_standard_output=journal+console
-[Content]
-BiosBootloader=grub
-
[Host]
-Autologin=yes
QemuVsock=yes
if path.exists():
logging.debug(f"Including configuration file {Path.cwd() / path}")
- for _, k, v in parse_ini(path, only_sections=["Distribution", "Output", "Content", "Validation", "Host", "Preset"]):
+ for section, k, v in parse_ini(path, only_sections=["Distribution", "Output", "Content", "Validation", "Host", "Preset"]):
ns = defaults if k.startswith("@") else namespace
if not (s := settings_lookup_by_name.get(k.removeprefix("@"))):
die(f"Unknown setting {k}")
+ if section != s.section:
+ logging.warning(f"Setting {k} should be configured in [{s.section}], not [{section}].")
+
setattr(ns, s.dest, s.parse(v, getattr(ns, s.dest, None)))
if extras:
import argparse
import itertools
+import logging
import operator
from pathlib import Path
from typing import Optional
"""\
[Content]
Packages=
+
+ [Output]
ImageId=
"""
)
f"""\
[Distribution]
Distribution=fedora
+
+ [Output]
ImageId={image1}
"""
)
"""\
[Distribution]
Distribution=fedora
+
+ [Output]
ImageId=testimage
ImageVersion=123
"""
assert conf.skeleton_trees == skel_expected
assert conf.package_manager_trees == pkgmngr_expected
+
+
+@pytest.mark.parametrize(
+ "sections,args,warning_count",
+ [
+ (["Output"], [], 0),
+ (["Content"], [], 1),
+ (["Content", "Output"], [], 1),
+ (["Output", "Content"], [], 1),
+ (["Output", "Content", "Distribution"], [], 2),
+ (["Content"], ["--image-id=testimage"], 1),
+ ],
+)
+def test_wrong_section_warning(
+ tmp_path: Path,
+ caplog: pytest.LogCaptureFixture,
+ sections: list[str],
+ args: list[str],
+ warning_count: int,
+) -> None:
+ with chdir(tmp_path):
+ # Create a config with ImageId in the wrong section,
+ # and sometimes in the correct section
+ Path("mkosi.conf").write_text(
+ "\n".join(
+ f"""\
+ [{section}]
+ ImageId=testimage
+ """
+ for section in sections
+ )
+ )
+
+ with caplog.at_level(logging.WARNING):
+ # Parse the config, with --image-id sometimes given on the command line
+ parse_config(args)
+
+ assert len(caplog.records) == warning_count