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

Implement YAML generator (FR-1046) #211

Merged
merged 70 commits into from
Jun 18, 2021
Merged

Implement YAML generator (FR-1046) #211

merged 70 commits into from
Jun 18, 2021

Conversation

slyon
Copy link
Collaborator

@slyon slyon commented May 20, 2021

Description

This is introducing a new YAML (netplan v2) rendere, enabling (lib-)netplan to write its own YAML config format from the currently parsed, internal data structures or a single, given NetplanNetDefiniton struct.

A big test coverage is achieved by extending the generator's TestBase class (from generator/base.py) to parse and re-generate all YAML passed to the generate() method and comparing the (normalized) original YAML input with the re-generated and normalized YAML output of this new renderer. That way the new YAML renderer is automatically tested for all existing and future test cases of the other renderers.

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.

@slyon slyon changed the title Generate YAML from internal NetplanNetDefinition data structure Generate YAML from internal NetplanNetDefinition data May 20, 2021
@codecov-commenter
Copy link

codecov-commenter commented May 20, 2021

Codecov Report

Merging #211 (5177df0) into master (2a7fc68) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #211      +/-   ##
==========================================
+ Coverage   98.92%   98.96%   +0.04%     
==========================================
  Files          54       54              
  Lines        8428     8830     +402     
==========================================
+ Hits         8337     8739     +402     
  Misses         91       91              
Impacted Files Coverage Δ
src/networkd.c 100.00% <ø> (ø)
src/nm.c 99.46% <ø> (ø)
tests/generator/test_common.py 100.00% <ø> (ø)
tests/generator/test_modems.py 100.00% <ø> (ø)
tests/generator/test_passthrough.py 100.00% <ø> (ø)
tests/test_serialize.py 100.00% <ø> (ø)
src/netplan.c 100.00% <100.00%> (ø)
src/parse.c 100.00% <100.00%> (ø)
tests/generator/base.py 100.00% <100.00%> (ø)
tests/generator/test_bridges.py 100.00% <100.00%> (ø)
... and 2 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 2a7fc68...5177df0. Read the comment docs.

@slyon slyon changed the title Generate YAML from internal NetplanNetDefinition data Generate YAML from internal NetplanNetDefinition data (FR-1046) May 25, 2021
@slyon slyon changed the title Generate YAML from internal NetplanNetDefinition data (FR-1046) Implement YAML renderer (FR-1046) May 25, 2021
@slyon slyon requested a review from sil2100 May 25, 2021 13:16
@slyon slyon marked this pull request as ready for review May 25, 2021 13:16
@slyon slyon changed the title Implement YAML renderer (FR-1046) Implement YAML generator (FR-1046) May 25, 2021
Copy link
Collaborator

@sil2100 sil2100 left a comment

Choose a reason for hiding this comment

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

Looks crisp! Extensive testing, like the idea to validate existing generated yaml in tests. I just hope that non-standard yaml output is tested as well, like when users omit some quotes that the netplan generator otherwise always adds!
Anyway, this is good to go. Awesome work as always!

src/netplan.c Show resolved Hide resolved
src/netplan.h Show resolved Hide resolved
@slyon
Copy link
Collaborator Author

slyon commented Jun 18, 2021

Looks crisp! Extensive testing, like the idea to validate existing generated yaml in tests. I just hope that non-standard yaml output is tested as well, like when users omit some quotes that the netplan generator otherwise always adds!
Anyway, this is good to go. Awesome work as always!

Cool! Thank you very much for the (big) review!
I accepted your one-line cleanup/fix and rebased on top of master.
This should be good for merging now!

@slyon slyon merged commit 922ac81 into master Jun 18, 2021
slyon added a commit that referenced this pull request Jul 7, 2021
This PR builds upon #211 to implement a basic NetworkManager Keyfile parser, by providing the other part of the Keyfile -> YAML conversion.

I did some refactoring here, to move tests/test_serialize.py and tests/test_nm_backend.py into tests/test_libnetplan.py and tests/parser/test_keyfile.py, splitting it up to have all the library functions/utils tested in test_libnetplan.py and all the keyfile parsing logic tested in test_keyfile.py, using the new tests/parser/base.py class to provide Keyfile -> YAML conversion testing utils. In the new parser/base.py I'm also checking the reverse conversion (i.e. automatically doing a Keyfile -> YAML -> Keyfile conversion) to make sure we don't lose information on the way.

The primary keyfile parsing/conversion logic is implemented in src/parse-nm.c by reading different (and currently supported) settings form a NetworkManager keyfile, using GLib's g_key_file_get_... reader and setting up a NetplanNetDefinition struct in memory where the (converted and adapted) values can be stored for netplan to handle them.

Also, I added several test-cases to parser/test_keyfile.py to test the Keyfile->YAML conversion for supported settings. All unsupported settings will still be keep in the passthrough dict. That's each setting which doesn't get cleared using _kf_clear_key(...) during the parsing.

COMMITS:
* parse-nm: handle dhcp4/6
* parse-nm: improve set_true_on_match()
* parse-nm: parse manual IPv4/6 addresses
* parse-nm: add gateway4/6
* parse-nm: some cleanup, using handle_generic_str()
* parse-nm: handle dhcp4/6-overrides
* test: refactor libnetplan & keyfile parser testing a bit
* test:parser:libnetplan: catch and check/assert output (stderr) from the C/libnetplan library
* parse-nm: handle wowlan
* parse-nm: improve wake-on-lan
* parse-nm: handle_common set_mac+mtu for wifi/ethernet
* parse-nm: handle_common match.macaddress
* parse-nm: parse_routes from keyfile
* parse-nm: handle DNS search domains
* parse-nm: handle DNS nameservers
* parse-nm: handle addr-gen-mode/token
* parse-nm: handle wifi band/channel/bssid
* parse-nm: handle wifi-security & 802.1x
* parse-nm: handle more cases for 'method'
* parse-nm: missing GSM/CDMA keys
* parse-nm: handle some vlan/bridge keys
* parse-nm: handle bond options
* parse-nm: fix dns list separator
* parse-nm: fix addr-gen-* handling
* parse-nm: fix dns-search list separator
* test:parser:base: re-generate keyfile during testing
* test:parser:keyfile: add some customer use-cases
* test:parser: improve wording in keyfile_parser
* test:parser:base: cleanup
* test:parser:keyfile: cleanup
* test:parser:keyfile: cleanup 2
* parse-nm: some cleanup
* parse-nm: some fixups
* test:parser: improve base class naming
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants