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

netplan: set: make it possible to unset a whole devtype subtree (LP: #1942930) (FR-1685) #236

Merged
merged 4 commits into from
Oct 4, 2021

Conversation

schopin-pro
Copy link
Contributor

@schopin-pro schopin-pro commented Oct 2, 2021

Description

Previously, trying to unset a whole devtype subtree, such as netplan set network.ethernets=null would fail. This PR fixes it by detecting this special case and manually deleting each netdef assigned to the subtype.

This approach is far from being performant, but it has the merit of working without needing too much new code.

Checklist

  • Runs make check successfully.
  • Retains 100% code coverage (make check-coverage).
  • New/changed keys in YAML format are documented.
  • (Optional) Closes an open bug in Launchpad: LP#1942930

This allows the test machinery to do some better error reporting when an
exception is raised, as it understands that the issue is an uncaught
exception, not a failed comparison.
As I'm expecting this kind of function to be useful for the parser, the
implementation is directly in the form of a macro modelled after its
counterpart.
@schopin-pro schopin-pro force-pushed the lp1942930-unset-tree branch 4 times, most recently from 8d821f6 to 7923612 Compare October 2, 2021 08:07
@codecov-commenter
Copy link

codecov-commenter commented Oct 2, 2021

Codecov Report

Merging #236 (c216be9) into main (467e88a) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #236   +/-   ##
=======================================
  Coverage   99.05%   99.06%           
=======================================
  Files          57       57           
  Lines        9633     9706   +73     
=======================================
+ Hits         9542     9615   +73     
  Misses         91       91           
Impacted Files Coverage Δ
netplan/cli/commands/set.py 100.00% <100.00%> (ø)
netplan/cli/utils.py 100.00% <100.00%> (ø)
src/util.c 100.00% <100.00%> (ø)
tests/test_cli_get_set.py 100.00% <100.00%> (ø)
tests/test_utils.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 467e88a...c216be9. Read the comment docs.

@schopin-pro schopin-pro requested review from slyon and mvo5 October 4, 2021 07:30
@schopin-pro
Copy link
Contributor Author

To whoever wants to backport this onto older releases, the first commit can be dropped, the second will mostly likely need some form of rewrite as it builds upon very recent work (#230). AFAICT the last two commits shouldn't pose any problem.

This is implemented via iterators to limit the knowledge Python has of
the underlying memory model. The new symbols are prefixed with '_' to
denote that they are not to be used by public consumers.

We also expose process_yaml_hierarchy which was already part of the ABI,
as it seems needed for the Python helper implementation.

Contrary to the usual FFI calls, this one explicitly checks the
existence of the symbols and raises an exception if the symbols are not
found, as it is not totally unlikely that netplan.io and libnetplan0 be
upgraded out of sync.

V2: rename the C internal iterator struct, which hadn't evolved along
with the successive iterations on the code

fixup itar
Copy link
Collaborator

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

Thank you Simon, I like how you're using libnetplan's internal data structure here, instead of relying on the deprecated configmanager.py.

The performance isn't good, but still I like that you implemented it in a way that can be backported (relatively) easy, without relying on all the new API code. Clearing a full devtype subtree isn't on the critical path, so this is fine IMO.

+1 from my side! I left two small inline comments, but nothing that would block merging of this PR.

src/util.c Show resolved Hide resolved
tests/test_cli_get_set.py Outdated Show resolved Hide resolved
See LP: #1942930

Note that performance for this are horrendous, as we parse the whole
tree once for *each* removed netdef!

V2:
* Lukas as co-author, as he wrote the test!
* Clean up commented-out code in the tests

Co-authored-by: Lukas Märdian <[email protected]>
@slyon slyon merged commit bc6eb0b into canonical:main Oct 4, 2021
@schopin-pro schopin-pro deleted the lp1942930-unset-tree branch April 13, 2022 09:04
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.

3 participants