[substitutions] [packages] Address review feedback

- Seed `resolve_include` context with `command_line_substitutions` so
  `substitutions: !include ${var}.yaml` can reference CLI-provided vars
  in the include filename (parallels the `packages: !include` path).
- Validate shape of resolved substitutions in `do_packages_pass` and raise
  `cv.Invalid` under `CONF_SUBSTITUTIONS` instead of letting `UserDict()`
  fail with a low-level exception on a non-mapping.
- Fixture 17 exercises the CLI-templated include filename.
This commit is contained in:
J. Nick Koston
2026-04-19 02:42:03 -05:00
parent ba8e729443
commit e67b65b669
4 changed files with 33 additions and 5 deletions
+13 -4
View File
@@ -517,11 +517,20 @@ def do_packages_pass(
return config
raw_substitutions = config.pop(CONF_SUBSTITUTIONS, {})
if isinstance(raw_substitutions, yaml_util.IncludeFile):
# Resolve `substitutions: !include file.yaml` before feeding into UserDict.
with cv.prepend_path(CONF_SUBSTITUTIONS):
with cv.prepend_path(CONF_SUBSTITUTIONS):
if isinstance(raw_substitutions, yaml_util.IncludeFile):
# Resolve `substitutions: !include file.yaml` before feeding into UserDict.
# Seed with command-line substitutions so `!include ${var}.yaml` can
# reference CLI-provided vars in the filename.
raw_substitutions, _ = resolve_include(
raw_substitutions, [], ContextVars(), strict_undefined=False
raw_substitutions,
[],
ContextVars(command_line_substitutions or {}),
strict_undefined=False,
)
if not isinstance(raw_substitutions, dict):
raise cv.Invalid(
f"Substitutions must be a key to value mapping, got {type(raw_substitutions)}"
)
substitutions = UserDict(raw_substitutions)
processor = _PackageProcessor(
+6 -1
View File
@@ -431,8 +431,13 @@ def do_substitution_pass(
with cv.prepend_path(CONF_SUBSTITUTIONS):
if isinstance(substitutions, IncludeFile):
# Resolve `substitutions: !include file.yaml` before validating the shape.
# Seed with command-line substitutions so `!include ${var}.yaml` can
# reference CLI-provided vars in the filename.
substitutions, _ = resolve_include(
substitutions, [], ContextVars(), strict_undefined=False
substitutions,
[],
ContextVars(command_line_substitutions or {}),
strict_undefined=False,
)
if not isinstance(substitutions, dict):
raise cv.Invalid(
@@ -0,0 +1,6 @@
substitutions:
subs_file: 15-substitutions_inc
wifi_password: sub_password
wifi:
ssid: main_ssid
password: sub_password
@@ -0,0 +1,8 @@
command_line_substitutions:
subs_file: 15-substitutions_inc
substitutions: !include ${subs_file}.yaml
wifi:
ssid: main_ssid
password: $wifi_password