Skip to content

Commit

Permalink
chore: remove redundant manual schema validation
Browse files Browse the repository at this point in the history
Schema validation is automatically checked and reported through
cloud-init status. Eliminate unnecessary manual verification as well as
the autoinstall key check which is unnecessary due to activation_key.
  • Loading branch information
holmanb committed Jan 9, 2025
1 parent 2231fbc commit b0a6df8
Showing 1 changed file with 0 additions and 53 deletions.
53 changes: 0 additions & 53 deletions cloudinit/config/cc_ubuntu_autoinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
from cloudinit.config import Config
from cloudinit.config.schema import (
MetaSchema,
SchemaProblem,
SchemaValidationError,
)
from cloudinit.settings import PER_ONCE

Expand All @@ -30,13 +28,6 @@

def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None:

if "autoinstall" not in cfg:
LOG.debug(
"Skipping module named %s, no 'autoinstall' key in configuration",
name,
)
return

util.wait_for_snap_seeded(cloud)
snap_list, _ = subp.subp(["snap", "list"])
installer_present = None
Expand All @@ -50,51 +41,7 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None:
", ".join(LIVE_INSTALLER_SNAPS),
)
return
validate_config_schema(cfg)
LOG.debug(
"Valid autoinstall schema. Config will be processed by %s",
installer_present,
)


def validate_config_schema(cfg):
"""Supplemental runtime schema validation for autoinstall yaml.
Schema validation issues currently result in a warning log currently which
can be easily ignored because warnings do not bubble up to cloud-init
status output.
In the case of the live-installer, we want cloud-init to raise an error
to set overall cloud-init status to 'error' so it is more discoverable
in installer environments.
# TODO(Drop this validation When cloud-init schema is strict and errors)
:raise: SchemaValidationError if any known schema values are present.
"""
autoinstall_cfg = cfg["autoinstall"]
if not isinstance(autoinstall_cfg, dict):
raise SchemaValidationError(
[
SchemaProblem(
"autoinstall",
"Expected dict type but found:"
f" {type(autoinstall_cfg).__name__}",
)
]
)

if "version" not in autoinstall_cfg:
raise SchemaValidationError(
[SchemaProblem("autoinstall", "Missing required 'version' key")]
)
elif not isinstance(autoinstall_cfg.get("version"), int):
raise SchemaValidationError(
[
SchemaProblem(
"autoinstall.version",
f"Expected int type but found:"
f" {type(autoinstall_cfg['version']).__name__}",
)
]
)

0 comments on commit b0a6df8

Please sign in to comment.