Skip to content

Add platform definitions and default_platform support#4096

Open
NeverBehave wants to merge 3 commits intonetbox-community:masterfrom
NeverBehave:feature/platform-support
Open

Add platform definitions and default_platform support#4096
NeverBehave wants to merge 3 commits intonetbox-community:masterfrom
NeverBehave:feature/platform-support

Conversation

@NeverBehave
Copy link
Copy Markdown
Contributor

Summary

Addresses #4094 — adds platform support to the device type library.

  • New platforms/ directory with <Manufacturer>/<slug>.yaml structure for platform definitions
  • New schema/platformtype.json validating platform YAML (manufacturer, name, slug, description)
  • default_platform field added to schema/devicetype.json as optional slug string
  • Cross-validation ensures default_platform references an existing platform file
  • Seed platforms: Arista EOS, Cisco IOS-XE, Cisco NX-OS, Juniper Junos, Palo Alto PAN-OS

Why a separate platforms/ directory?

A bare default_platform string would be a dangling reference — import tools can't resolve a platform that doesn't exist in the target NetBox instance. The platforms/ directory gives import tools a complete dependency chain: create platforms first, then device types.

Additionally, a device's platform doesn't always match its manufacturer (e.g., Edgecore switches running Cumulus Linux). Platforms need their own manufacturer field, which is why they live in dedicated files under their own manufacturer directory.

Test changes

  • Platform files validated against platformtype.json schema
  • Platform filename must match slug field
  • default_platform in device types must reference an existing platforms/*/<slug>.yaml
  • Duplicate platform slug detection across manufacturers
  • Precomputed platform slug lookup for performance
  • Device-only validations (verify_filename, validate_components) skipped for platforms

Test plan

  • All 5 seed platform files pass schema validation
  • Invalid slug pattern rejected by schema
  • Missing required fields rejected by schema
  • Extra fields rejected by additionalProperties: false
  • Cross-validation correctly resolves valid platform slugs
  • Cross-validation correctly rejects nonexistent platform slugs
  • Filename=slug enforcement verified

NeverBehave and others added 3 commits March 31, 2026 18:51
…test config

- Create schema/platformtype.json for platform definitions
- Add optional default_platform field to device type schema
- Add PlatformType class to tests/device_types.py
- Register platforms in SCHEMAS tuple in test_configuration.py

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Route platform files to PlatformType in test_definitions
- Validate platform filename matches slug field
- Cross-validate default_platform references existing platform file
- Skip device-only validations (verify_filename, validate_components) for platforms
- Add seed platforms: Arista EOS, Cisco IOS-XE, Cisco NX-OS, Juniper Junos, PAN-OS

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… duplicate detection

- Align slug patterns to lowercase-only (^[-a-z0-9_]+$) matching repo convention
- Precompute KNOWN_PLATFORMS map at module level instead of glob per device
- Fail if multiple platform files share the same slug across manufacturers

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@NeverBehave NeverBehave marked this pull request as ready for review April 1, 2026 06:27
Copilot AI review requested due to automatic review settings April 1, 2026 06:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class platform definitions to the devicetype-library test + schema pipeline, enabling default_platform on device types and ensuring it resolves to an in-repo platform definition.

Changes:

  • Introduces platforms/<Manufacturer>/<slug>.yaml definitions validated by a new schema/platformtype.json.
  • Extends schema/devicetype.json to allow optional default_platform (platform slug).
  • Updates test harness to validate platform files, enforce platform filename==slug, and cross-validate device type default_platform references.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_configuration.py Registers the new platformtype.json schema for the platforms/ directory.
tests/device_types.py Adds a PlatformType wrapper used by the shared validation test flow.
tests/definitions_test.py Adds platform discovery + validation and default_platform cross-validation logic.
schema/platformtype.json New JSON schema for platform YAML definitions.
schema/devicetype.json Adds optional default_platform field with slug constraints.
platforms/Arista/arista-eos.yaml Seed Arista EOS platform definition.
platforms/Cisco/cisco-ios-xe.yaml Seed Cisco IOS-XE platform definition.
platforms/Cisco/cisco-nxos.yaml Seed Cisco NX-OS platform definition.
platforms/Juniper/juniper-junos.yaml Seed Juniper Junos platform definition.
platforms/Palo Alto/paloalto-panos.yaml Seed Palo Alto PAN-OS platform definition.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/definitions_test.py
for platform_file in sorted(glob.glob(f"platforms{os.path.sep}*{os.path.sep}*.yaml")) + sorted(glob.glob(f"platforms{os.path.sep}*{os.path.sep}*.yml")):
platform_slug = os.path.basename(platform_file).rsplit(".", 1)[0]
KNOWN_PLATFORMS.setdefault(platform_slug, []).append(platform_file)

Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KNOWN_PLATFORMS is built with the intent of detecting duplicate platform slugs, but duplicates are currently only surfaced when a device-type references default_platform. If two platform files share the same slug and no device-type references it, the tests will still pass. Consider adding an unconditional check (e.g., a small test that asserts every platform_slug maps to exactly one file) so duplicate slugs are always rejected.

Suggested change
def test_unique_platform_slugs():
"""
Ensure each platform slug corresponds to exactly one platform definition file.
This prevents silent duplicates when a platform slug is not referenced
by any device-type via ``default_platform``.
"""
duplicates = {
slug: files for slug, files in KNOWN_PLATFORMS.items() if len(files) > 1
}
assert not duplicates, (
"Duplicate platform slugs detected:\n"
+ "\n".join(
f"{slug}: {', '.join(sorted(files))}"
for slug, files in sorted(duplicates.items())
)
)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants