Add platform definitions and default_platform support#4096
Add platform definitions and default_platform support#4096NeverBehave wants to merge 3 commits intonetbox-community:masterfrom
Conversation
…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>
There was a problem hiding this comment.
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>.yamldefinitions validated by a newschema/platformtype.json. - Extends
schema/devicetype.jsonto allow optionaldefault_platform(platform slug). - Updates test harness to validate platform files, enforce platform filename==slug, and cross-validate device type
default_platformreferences.
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.
| 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) | ||
|
|
There was a problem hiding this comment.
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.
| 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()) | |
| ) | |
| ) |
Summary
Addresses #4094 — adds platform support to the device type library.
platforms/directory with<Manufacturer>/<slug>.yamlstructure for platform definitionsschema/platformtype.jsonvalidating platform YAML (manufacturer, name, slug, description)default_platformfield added toschema/devicetype.jsonas optional slug stringdefault_platformreferences an existing platform fileWhy a separate
platforms/directory?A bare
default_platformstring would be a dangling reference — import tools can't resolve a platform that doesn't exist in the target NetBox instance. Theplatforms/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
platformtype.jsonschemaslugfielddefault_platformin device types must reference an existingplatforms/*/<slug>.yamlTest plan
additionalProperties: false