Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce netplan validate #335

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

daniloegea
Copy link
Collaborator

@daniloegea daniloegea commented Mar 13, 2023

Description

netplan validate will parse and report any issues in the current configuration files without generating or applying it to the system.

The --debug parameter can be used to show what files are being loaded and in what order. It will also show any shadowing that happened during the parsing. A useful feature during troubleshooting. It implements the same logic from:

/* Files with asciibetically higher names override/append settings from

Example:

# netplan validate --debug --root-dir /tmp/dir
Order in which your files are parsed:
/tmp/dir/etc/netplan/00-ethernet-set-name.yaml
/tmp/dir/run/netplan/00-network.yaml
/tmp/dir/etc/netplan/01-ethernet-set-name-and-match.yaml
/tmp/dir/etc/netplan/02-bridge.yaml
/tmp/dir/run/netplan/03-bridge.yaml
/tmp/dir/etc/netplan/03-ethernet.yaml
/tmp/dir/run/netplan/bad_boolean.yaml
/tmp/dir/run/netplan/bad_ethernet.yaml
/tmp/dir/run/netplan/bad_mac_address.yaml
/tmp/dir/run/netplan/bad_vlan.yaml
/tmp/dir/etc/netplan/change_type.yaml
/tmp/dir/etc/netplan/config.yaml
/tmp/dir/run/netplan/duplicate_addresses.yaml
/tmp/dir/run/netplan/good_ethernet.yaml
/tmp/dir/run/netplan/good_vlan.yaml
/tmp/dir/run/netplan/invalid_value.yaml
/tmp/dir/run/netplan/out_of_range.yaml
/tmp/dir/etc/netplan/wireless.yaml

The following files were shadowed:
/tmp/dir/lib/netplan/03-ethernet.yaml shadowed by /tmp/dir/etc/netplan/03-ethernet.yaml
/tmp/dir/etc/netplan/03-bridge.yaml shadowed by /tmp/dir/run/netplan/03-bridge.yaml
/tmp/dir/etc/netplan/00-network.yaml shadowed by /tmp/dir/run/netplan/00-network.yaml

Validation failed: /tmp/dir/etc/netplan/00-ethernet-set-name.yaml:4:7: Error in network definition: enp3s0: 'set-name:' requires 'match:' properties
      set-name: "external"
      ^

Checklist

  • Runs make check successfully.
  • Retains 100% code coverage (make check-coverage).
  • New/changed keys in YAML format are documented.
  • (Optional) Adds example YAML for new feature.
  • (Optional) Closes an open bug in Launchpad.

Netplan validate can be used to check the configuration before trying to
apply it. It's useful when one is making changes in the configuration
and want to periodically check if it is still valid without having to call
"apply" or "generate".

The validate command will load, parse and validate the configuration
without saving anything to disk.
Due to the change in netplan.cli.core (which prevents it of raising
exception (which were not being handled and resulting in crashes)), a
small change was made in the cli tests so the main() method is not
called directly anymore.
Add the new "netplan validate" command to it.
--debug will show what files are being processed and which ones were
shadowed.
: Print debugging output during the process.

--root-dir
: Read YAML files from this root instead of /

Choose a reason for hiding this comment

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

Is it worth growing generally a machine readable output so callers can invoke this with a --format=json or do we really prefer machine-readable consumers really to just use the libnetplan.State.import_parser_results directly and process the state errors?

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