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

YAML consolidation: netplan get (FR-702) #252

Merged
merged 4 commits into from
Jan 26, 2022

Conversation

schopin-pro
Copy link
Contributor

Description

Port the netplan get command to use the internal YAML generator, originally written for the NM-to-netplan system.
In order to make this work, we had to add a notion of "dirtyness" to the input data, as the user would want their explicit settings displayed even if they match the default value.

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.

@schopin-pro
Copy link
Contributor Author

Draft as it depends on #250 and #251 , and would also benefit from #249 being merged

@codecov-commenter
Copy link

Codecov Report

Merging #252 (d5148e6) into main (2190567) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #252      +/-   ##
==========================================
+ Coverage   99.10%   99.13%   +0.03%     
==========================================
  Files          58       60       +2     
  Lines       10038    10386     +348     
==========================================
+ Hits         9948    10296     +348     
  Misses         90       90              
Impacted Files Coverage Δ
tests/parser/test_keyfile.py 100.00% <ø> (ø)
tests/test_utils.py 100.00% <ø> (ø)
netplan/cli/commands/get.py 100.00% <100.00%> (ø)
netplan/cli/commands/set.py 100.00% <100.00%> (ø)
netplan/cli/utils.py 100.00% <100.00%> (ø)
netplan/libnetplan.py 100.00% <100.00%> (ø)
src/abi_compat.c 100.00% <100.00%> (ø)
src/netplan.c 100.00% <100.00%> (ø)
src/parse.c 99.82% <100.00%> (+<0.01%) ⬆️
src/types.c 100.00% <100.00%> (ø)
... and 5 more

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 2190567...d5148e6. Read the comment docs.

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 for another great PR, Simon!
The dirty tracking functionality is really nice and should help us cleaning up some parts of the test environment, too, where we're currently doing some "normalization" of default values.

I left some inline comments. But again, nothing critical.

src/parse.c Outdated Show resolved Hide resolved
src/parse.c Outdated Show resolved Hide resolved
src/parse.c Outdated Show resolved Hide resolved
src/netplan.c Outdated Show resolved Hide resolved
src/netplan.c Outdated Show resolved Hide resolved
src/netplan.c Outdated Show resolved Hide resolved
src/netplan.c Outdated Show resolved Hide resolved
src/netplan.c Outdated
Comment on lines 640 to 644
} else if (DIRTY(def, def->backend) ||
( def->backend != get_default_backend_for_type(np_state->backend, def->type)
&& def->backend != np_state->backend
&& def->backend != NETPLAN_BACKEND_OVS)) {
YAML_STRING_PLAIN(event, emitter, "renderer", netplan_backend_name(def->backend));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not to self: we should verify that this still works correctly with the NM snap integration. It should as parse-nm.c is setting each netdef's backend to NETPLAN_BACKEND_NM which is not equal to the default backend type.

tests/generator/base.py Outdated Show resolved Hide resolved
netplan/cli/commands/get.py Show resolved Hide resolved
This new structure, while more complex, will allow us to extend some
callback signatures (i.e. adding a prefix parameter for null-handling)
without having to change the whole world.

V2:
* simplify the map handling structure, getting rid of the tagged union
in favor of simpler NULL-handling.
* remove the fancy space alignment for the handler declarations as they
got out of control.
This will allow us to output those fields even if their value is the
default one, to clearly reflect the user's intent.

V2: Fix conditional bracing style
If the user touched those fields, we want to retranscribe the value even
if it matches the default!

Squashed in this commit is a test fix for the on-link field.
on-link is a boolean, and its output format was wrong. We want literals
as much as possible! The behaviour change is entangled with the dirty
changes, so we change the test here.

V2: Change the macro names to remove the DIRTY_ bit and make the default
values more explicit
This patch rewrites the entire command to use our internal YAML helpers
instead, notably the APIs introduced in the few previous commits.

This also changes the tests to parse the output YAML instead of checking
for a *specific* output, which makes them less susceptible of breaking
when there's a small formatting change.

V2:
* add a test for the networkINVALID query
* remove a spurious change in tests/generator/base.py
@schopin-pro
Copy link
Contributor Author

Tests run on my local LXD, as GH ACtions seems to be having troubles today:

autopkgtest [11:31:23]: @@@@@@@@@@@@@@@@@@@@ summary
ovs                  PASS
ethernets            PASS
bridges              PASS
bonds                PASS
routing              PASS
vlans                PASS
wifi                 PASS
tunnels              PASS
scenarios            PASS
regressions          PASS
autostart            PASS
cloud-init           PASS

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 for the V2 improvements and for running the integration tests locally!

LGTM 👀

@slyon slyon merged commit 331ca01 into canonical:main Jan 26, 2022
@schopin-pro schopin-pro deleted the yaml-consolidation-get branch May 5, 2022 10:05
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