Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ COPY files/clustershell/clush.conf /etc/clustershell/clush.conf
COPY files/clustershell/groups.conf /etc/clustershell/groups.conf

COPY files/sonic/port_config/ /etc/sonic/port_config/
COPY files/sonic/yang_models/ /etc/sonic/yang_models/
COPY files/sonic/config_db.json /etc/sonic/config_db.json

COPY files/netbox-manager/settings.toml /usr/local/config/settings.toml
Expand All @@ -46,7 +45,6 @@ apk add --no-cache \
coreutils \
git \
less \
libyang \
openssh-client \
procps \
skopeo \
Expand Down
34 changes: 10 additions & 24 deletions osism/commands/sonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,8 @@ def take_action(self, parsed_args):
class Validate(SonicCommandBase):
"""Validate SONiC config_db.json against the bundled YANG models.

Validation runs against Pydantic schemas generated from the SONiC YANG
models in files/sonic/yang_models/ via tools/sonic_yang_to_pydantic.py.
Configurations can be sourced from a local file, NetBox local context,
the on-disk export directory, or generated on-the-fly from NetBox.
"""
Expand Down Expand Up @@ -1187,13 +1189,6 @@ def get_parser(self, prog_name):
action="store_true",
help="Generate config from NetBox in-memory and validate it.",
)
parser.add_argument(
"--yang-dir",
dest="yang_dir",
type=str,
default=None,
help="Override YANG model directory (default: SONIC_YANG_MODELS_DIR).",
)
parser.add_argument(
"--format",
dest="output_format",
Expand All @@ -1205,24 +1200,11 @@ def get_parser(self, prog_name):

def take_action(self, parsed_args):
try:
from osism.tasks.conductor.sonic.validator import (
ValidatorUnavailable,
load_yang_context,
validate_config,
)
from osism.tasks.conductor.sonic.validator import validate_config
except ImportError as exc:
logger.error(f"Validator module unavailable: {exc}")
return 2

try:
ctx = load_yang_context(parsed_args.yang_dir)
except ValidatorUnavailable as exc:
logger.error(str(exc))
return 2
except Exception as exc:
logger.error(f"Failed to load YANG models: {exc}")
return 2

try:
sources = self._collect_sources(parsed_args)
except ValueError as exc:
Expand All @@ -1240,7 +1222,7 @@ def take_action(self, parsed_args):
results.append((label, None))
worst_rc = max(worst_rc, 2)
continue
result = validate_config(config, ctx=ctx)
result = validate_config(config)
results.append((label, result))
if not result.valid:
worst_rc = max(worst_rc, 1)
Expand Down Expand Up @@ -1376,8 +1358,12 @@ def _print_text_report(self, results):
else:
print(f"[FAIL] {label}: {len(result.errors)} error(s)")
for err in result.errors:
if err.path:
print(f" - {err.message} ({err.path})")
table_prefix = f"{err.table}." if err.table else ""
location = f"{table_prefix}{err.path}" if err.path else err.table
if location:
print(f" - {err.message} ({location})")
else:
print(f" - {err.message}")
for warning in getattr(result, "warnings", []) or []:
print(f"[WARN] {label}: {warning}")
print(f"\nSummary: {ok} valid, {fail} failed, {len(results)} total")
6 changes: 0 additions & 6 deletions osism/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ def read_secret(secret_name):
SONIC_EXPORT_SUFFIX = os.getenv("SONIC_EXPORT_SUFFIX", "_config_db.json")
SONIC_EXPORT_IDENTIFIER = os.getenv("SONIC_EXPORT_IDENTIFIER", "serial-number")

SONIC_YANG_MODELS_DIR = os.getenv(
"SONIC_YANG_MODELS_DIR",
os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "files", "sonic", "yang_models")
),
)

NETBOX_SECONDARIES = (
os.getenv("NETBOX_SECONDARIES", read_secret("NETBOX_SECONDARIES")) or "[]"
Expand Down
7 changes: 7 additions & 0 deletions osism/tasks/conductor/sonic/_generated/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# AUTO-GENERATED — DO NOT EDIT BY HAND.
"""Generated SONiC ConfigDB schemas."""

from ._schemas import TABLE_MODELS

__all__ = ["TABLE_MODELS"]
Loading