-
Notifications
You must be signed in to change notification settings - Fork 183
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
b8854b8
to
8981649
Compare
There was a problem hiding this 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!
Delete duplicated empty line in the netplan YAML generator. Co-authored-by: Łukasz Zemczak <sil2100@vexillium.org>
affc983
to
5177df0
Compare
Cool! Thank you very much for the (big) review! |
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
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 (fromgenerator/base.py
) to parse and re-generate all YAML passed to thegenerate()
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
make check
successfully.make check-coverage
).