Skip to content

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

Merged
slyon merged 2 commits intocanonical:mainfrom
daniloegea:lp2000324
Jan 19, 2023
Merged

parser: return the correct error on failure (LP#2000324)#308
slyon merged 2 commits intocanonical:mainfrom
daniloegea:lp2000324

Conversation

@daniloegea
Copy link
Copy Markdown
Contributor

@daniloegea 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

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

  • 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 daniloegea requested a review from slyon January 11, 2023 16:28
Copy link
Copy Markdown
Contributor

@slyon 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?

Comment thread src/parse.c
@slyon 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants