Skip to content

parser: return the correct error on failure (LP#2000324) #308

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

Merged
merged 2 commits into from
Jan 19, 2023

Conversation

Image for: Conversation
Copy link
Contributor

daniloegea commented Jan 5, 2023

If the parsing process finishes with an error, we should return this error instead of assuming it's a missing interface.

For instance, the configuration below will fail with "br0: interface 'ens3' is not defined" when the actual error is "invalid IP family '-1'" due to the invalid IP used as the default route:

network:
  bridges:
    br0:
      interfaces:
        - ens3
      routes:
        - to: 0/0
          via: 100.64.0.1
  ethernets:
    ens3: {}
  version: 2

Description

Image for: Description

This PR addresses LP#2000324

The configuration above was failing with:

$ netplan generate --root-dir /workspace/netplan-issues/fakeroot
/workspace/netplan-issues/fakeroot/etc/netplan/static.yaml:5:11: Error in network definition: br0: interface 'ens3' is not defined
        - ens3
          ^

With this change this is the result:

$ LD_LIBRARY_PATH=build/src/ PYTHONPATH=. src/netplan.script generate --root-dir /workspace/netplan-issues/fakeroot
/workspace/netplan-issues/fakeroot/etc/netplan/static.yaml:7:15: Error in network definition: invalid IP family '-1'
        - to: 0/0
              ^

Checklist

Image for: 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.
If the parsing process finishes with an error, we should return this
error instead of assuming it's a missing interface.

For instance, the configuration below will fail with "br0: interface
'ens3' is not defined" when the actual error is "invalid IP family '-1'"
due to the invalid IP used as the default route:

network:
  bridges:
    br0:
      interfaces:
        - ens3
      routes:
        - to: 0/0
          via: 100.64.0.1
  ethernets:
    ens3: {}
  version: 2
daniloegea requested a review from slyon January 11, 2023 16:28
Copy link
Collaborator

slyon left a comment

Choose a reason for hiding this comment

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

Thanks, lgtm. I've added some small bits to cleanup the npp->missing_id hashmap in the error case. WDYT?

slyon merged commit 2623fb5 into canonical:main Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants