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 set (FR-702) #254

Merged
merged 11 commits into from
May 3, 2022

Conversation

schopin-pro
Copy link
Contributor

@schopin-pro schopin-pro commented Jan 11, 2022

Description

As part of the larger PyYAML cleanup effort, this patch set rewrites the netplan set to use libnetplan's own YAML parser instead of PyYAML. This meant enriching the parser to deal with null fields, that need to be tracked out-of-band, as well as creating new APIs to create YAML files out of a Netplan state, with different nuances to match the previous behavior.

Checklist

  • Runs make check successfully.
  • Retains 100% code coverage (make check-coverage).

@schopin-pro
Copy link
Contributor Author

This builds up on #252 hence the draft status.

@codecov-commenter
Copy link

codecov-commenter commented Jan 11, 2022

Codecov Report

Merging #254 (a4a8ac8) into main (a4a8ac8) will not change coverage.
The diff coverage is n/a.

❗ Current head a4a8ac8 differs from pull request most recent head f4bbd76. Consider uploading reports for the commit f4bbd76 to get more accurate results

@@           Coverage Diff           @@
##             main     #254   +/-   ##
=======================================
  Coverage   99.07%   99.07%           
=======================================
  Files          61       61           
  Lines       10862    10862           
=======================================
  Hits        10762    10762           
  Misses        100      100           

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 a4a8ac8...f4bbd76. Read the comment docs.

@schopin-pro schopin-pro marked this pull request as ready for review January 26, 2022 15:35
@schopin-pro
Copy link
Contributor Author

Ran the autopkgtests manually:

autopkgtest [17:20:13]: @@@@@@@@@@@@@@@@@@@@ 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.

This is another big PR, but the change makes the implementation so much cleaner and more explicit. I really like your overall approach!

I left several comments inline about some details that we should address in a 2nd version of PR.

src/types.h Outdated Show resolved Hide resolved
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/parse.c Outdated Show resolved Hide resolved
tests/test_cli_get_set.py Show resolved Hide resolved
tests/test_cli_get_set.py Show resolved Hide resolved
tests/test_cli_get_set.py Outdated Show resolved Hide resolved
tests/test_cli_get_set.py Show resolved Hide resolved
tests/test_cli_get_set.py Outdated Show resolved Hide resolved
@schopin-pro
Copy link
Contributor Author

For the sake of being able to test stuff, I included the commit of #257 since without it the null-handling breaks stuff.

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 very much, we're making good progress with this big PR and are getting much closer to a unified YAML parser. kudos!

I've left some smaller inline comments, nothing critical.

Another thing to mention is that make check-coverage currently fails, due to netplan/cli/sriov.py:363, which can probably just be marked as "nocover", as it's just about (non-existing) hardware specific quirks.

tests/test_libnetplan.py Outdated Show resolved Hide resolved
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/parse.c Outdated Show resolved Hide resolved
netplan/cli/commands/set.py Outdated Show resolved Hide resolved
src/parse.c Show resolved Hide resolved
src/parse.c Outdated Show resolved Hide resolved
src/types.c Outdated Show resolved Hide resolved
tests/test_cli_get_set.py Show resolved Hide resolved
@schopin-pro schopin-pro force-pushed the yaml-consolidation-set branch 3 times, most recently from ed51f04 to eaa64fd Compare April 26, 2022 11:21
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! All my remarks have been addressed. This is ready to be merged IMO.

Abigail is detecting some ABI changes, but they are all compatible (added functions & appended sources to NetplanState). Feel free to update the ABI XML to something like this (after a rebase, to have abi-compat/focal_0.104.xml available): https://paste.ubuntu.com/p/BK8HGnzPrG/ and merge this PR afterwards.

abidiff abi-compat/focal_0.104.xml libnetplan.so.0.0 --headers-dir2 include/ --header-file2 src/abi.h
Functions changes summary: 0 Removed, 0 Changed (26 filtered out), 5 Added functions
Variables changes summary: 0 Removed, 1 Changed, 0 Added variable

5 Added functions:

  [A] 'function gboolean netplan_parser_load_nullable_fields(NetplanParser*, int, GError**)'    {netplan_parser_load_nullable_fields}
  [A] 'function gboolean netplan_parser_load_yaml_from_fd(NetplanParser*, int, GError**)'    {netplan_parser_load_yaml_from_fd}
  [A] 'function gboolean netplan_state_update_yaml_hierarchy(const NetplanState*, const char*, const char*, GError**)'    {netplan_state_update_yaml_hierarchy}
  [A] 'function gboolean netplan_state_write_yaml_file(const NetplanState*, const char*, const char*, GError**)'    {netplan_state_write_yaml_file}
  [A] 'function gboolean netplan_util_create_yaml_patch(const char*, const char*, int, GError**)'    {netplan_util_create_yaml_patch}

1 Changed variable:

  [C] 'NetplanState global_state' was changed at abi_compat.c:64:1:
    size of symbol changed from 168 to 176

@slyon slyon added the ABI-compatible ABI changed in a compatible way label Apr 27, 2022
@schopin-pro
Copy link
Contributor Author

schopin-pro commented Apr 28, 2022 via email

@slyon
Copy link
Collaborator

slyon commented Apr 29, 2022

IMHO we should completely exclude global_state from the ABI check

ACK. Should be resolved by a4a8ac8

src/netplan.c Show resolved Hide resolved
src/netplan.c Outdated Show resolved Hide resolved
This hidden option makes things much easier to debug. Inserting
unconditional breakpoint() statements in the code is somewhat
error-prone as shelling out to new `netplan` process is fairly common
throughout the code base, and there are also some systemd services that
spawn netplan instances.
This will be useful for `netplan set` to remove emptied-out config
files.

V2: Fix white space
Any data that is parsed from such a file is considered as having no
source file. Existing netdefs retain their original filename, and new
ones have a NULL one, which will be exploited later on.

V2: Remove erroneous copy-pasted comment
This support is done by pre-processing the input files to identify the
null fields, and when we find a key that matches a null field we simply
skip to the next key.

This necessitates to keep track of the complete key throughout the
parser, hence the relatively big size of the patch.

V2:
* Rename prefix arguments to key_prefix
* Use \t rather than . as prefix segment separator
This new function does a targetted update of a given config file,
exporting all relevant netdefs (including those without defined config
file, e.g. those that have been created via a patch)

V2:
* Use the tempfile+rename trick to avoid data loss on error
* Style fixes

V3:
* Add a test for removal of unremovable files
This new function basically refreshes all the configuration files that
have been used to create the current state. This is where the global
source file tracking comes into play, as it allows us to delete config
files that didn't result in any actual settings in the final state, i.e.
because their defs were removed in a subsequent patch.

This function will be used in the netplan set rewrite.

V2:
* Do some default_filename early sanity checks
* Error out if removal of obsolete files fails.
A "set expression" here consists of a path formed of TAB-separated
keys, indicating where in the YAML doc we want to make our changes, and
a valid YAML expression that will be the payload to insert at that
place. The result is a well-formed YAML document.
snapd uses a JSON serializer to format their payloads, which makes
sense. Also, the previous version wasn't technically valid YAML anyway.
This removes the dependency on PyYAML from this subcommand.

V2: Remove superfluous test data
V3: Fix code comment left over from previous version on string escaping
The last use case of this function was in the previous implementation of
`netplan set`, and it isn't considered part of our public API.
@schopin-pro
Copy link
Contributor Author

Regarding editing the ABI doc, shouldn't we hold until release? That way we can still tweak symbols introduced in previous PRs

@slyon
Copy link
Collaborator

slyon commented May 3, 2022

Regarding editing the ABI doc, shouldn't we hold until release? That way we can still tweak symbols introduced in previous PRs

Yes, makes sense, especially as it does not break ABI in its current form! Feel free to merge this PR.

@slyon slyon merged commit fa245b8 into canonical:main May 3, 2022
@schopin-pro schopin-pro deleted the yaml-consolidation-set branch May 5, 2022 10:05
@schopin-pro schopin-pro restored the yaml-consolidation-set branch May 5, 2022 10:05
@schopin-pro schopin-pro deleted the yaml-consolidation-set branch May 5, 2022 10:06
@schopin-pro schopin-pro restored the yaml-consolidation-set branch May 5, 2022 10:06
slyon added a commit to slyon/netplan that referenced this pull request Jul 19, 2023
…27584)

The "unlink" part at the bottom of netplan.c:netplan_state_update_yaml_hierarchy
seems to ignore any global values (such as "renderer") and operates on netdefs only.

The issue is happens due to a combination of the following PRs:
canonical#254
canonical#299

Which got SRUed into Jammy via 0.105-0ubuntu2~22.04.2

Here's a minimal reproducer:
```
netplan set network.renderer=NetworkManager --origin-hint=00-no-netdefs-just-globals
netplan set network.ethernets.eth99.dhcp4=true --origin-hint=90-some-netdefs
ls -l /etc/netplan/
netplan set network.ethernets.eth99=NULL
cat /etc/netplan/00-no-netdefs-just-globals.yaml
```

FR-4793
slyon added a commit to slyon/netplan that referenced this pull request Jul 20, 2023
…27584)

The "unlink" part at the bottom of netplan.c:netplan_state_update_yaml_hierarchy
seems to ignore any global values (such as "renderer") and operates on files
containing netdefs only.

The issue is happens due to a combination of the following PRs:
canonical#254
canonical#299

Which got SRUed into Jammy via 0.105-0ubuntu2~22.04.2

Here's a minimal reproducer:
```
netplan set network.renderer=NetworkManager --origin-hint=00-no-netdefs-just-globals
netplan set network.ethernets.eth99.dhcp4=true --origin-hint=90-some-netdefs
ls -l /etc/netplan/
netplan set network.ethernets.eth99=NULL
cat /etc/netplan/00-no-netdefs-just-globals.yaml
```

FR-4793
slyon added a commit to slyon/netplan that referenced this pull request Jul 20, 2023
…27584)

The "unlink" part at the bottom of netplan.c:netplan_state_update_yaml_hierarchy
seems to ignore any global values (such as "renderer") and operates on files
containing netdefs only.

The issue is happens due to a combination of the following PRs:
canonical#254
canonical#299

Which got SRUed into Jammy via 0.105-0ubuntu2~22.04.2

Here's a minimal reproducer:
```
netplan set network.renderer=NetworkManager --origin-hint=00-no-netdefs-just-globals
netplan set network.ethernets.eth99.dhcp4=true --origin-hint=90-some-netdefs
ls -l /etc/netplan/
netplan set network.ethernets.eth99=NULL
cat /etc/netplan/00-no-netdefs-just-globals.yaml
```

FR-4793
slyon added a commit to slyon/netplan that referenced this pull request Jul 24, 2023
…27584)

The "unlink" part at the bottom of netplan.c:netplan_state_update_yaml_hierarchy
seems to ignore any global values (such as "renderer") and operates on files
containing netdefs only.

The issue is happens due to a combination of the following PRs:
canonical#254
canonical#299

Which got SRUed into Jammy via 0.105-0ubuntu2~22.04.2

Here's a minimal reproducer:
```
netplan set network.renderer=NetworkManager --origin-hint=00-no-netdefs-just-globals
netplan set network.ethernets.eth99.dhcp4=true --origin-hint=90-some-netdefs
ls -l /etc/netplan/
netplan set network.ethernets.eth99=NULL
cat /etc/netplan/00-no-netdefs-just-globals.yaml
```

FR-4793
slyon added a commit that referenced this pull request Jul 24, 2023
…27584)

The "unlink" part at the bottom of netplan.c:netplan_state_update_yaml_hierarchy
seems to ignore any global values (such as "renderer") and operates on files
containing netdefs only.

The issue is happens due to a combination of the following PRs:
#254
#299

Which got SRUed into Jammy via 0.105-0ubuntu2~22.04.2

Here's a minimal reproducer:
```
netplan set network.renderer=NetworkManager --origin-hint=00-no-netdefs-just-globals
netplan set network.ethernets.eth99.dhcp4=true --origin-hint=90-some-netdefs
ls -l /etc/netplan/
netplan set network.ethernets.eth99=NULL
cat /etc/netplan/00-no-netdefs-just-globals.yaml
```

FR-4793
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ABI-compatible ABI changed in a compatible way
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants