libnetplan: expose coherent generator APIs#239
Conversation
Note that we duplicated a function, as I'd like to remove it from the API seeing as it's really not netplan-specific, but we need to keep it in the ABI. The new API has the ability to report on errors, which allows us to remove all the calls to exit() within networkd.c. Those have nothing to do in library code. We also followed the current convention of using the return value to signal errors, forcing us to use an out-parameter for the "has_been_written" return value.
The NM generator directly called exit() when something went wrong, which is not ideal in library code! We copied the API from the netword generator, hence the has_been_written new capability.
The API is now the same as for the networkd and NM generators. No more exit()ing in the middle of a library call!
0be6e22 to
583917e
Compare
| NETPLAN_INTERNAL gboolean | ||
| netplan_ovs_cleanup(const char* rootdir); | ||
|
|
||
|
|
There was a problem hiding this comment.
Add comment about deprecated API, instead of additional whitespace.
| return TRUE; | ||
| } | ||
| return FALSE; | ||
| *result = FALSE; |
There was a problem hiding this comment.
The result variable name is a bit unclear here. Maybe it could be called needs_ssl instead?
| if (def->ovs_settings.protocols && def->ovs_settings.protocols->len > 0) { | ||
| write_ovs_protocols(&(def->ovs_settings), def->id, cmds); | ||
| } else if (ovs_settings_global.protocols && ovs_settings_global.protocols->len > 0) { | ||
| write_ovs_protocols(&(ovs_settings_global), def->id, cmds); | ||
| } else if (settings->protocols && settings->protocols->len > 0) { | ||
| write_ovs_protocols(settings, def->id, cmds); | ||
| } |
There was a problem hiding this comment.
we could use short-form if clauses here.
Codecov Report
@@ Coverage Diff @@
## main #239 +/- ##
==========================================
+ Coverage 99.06% 99.10% +0.03%
==========================================
Files 58 58
Lines 9713 9792 +79
==========================================
+ Hits 9622 9704 +82
+ Misses 91 88 -3
Continue to review full report at Codecov.
|
slyon
left a comment
There was a problem hiding this comment.
This is another very good PR, removing the exit(1) calls from inside the library (that lintian has been complaining about for a long time). Thank you Simon!
I added only a few inline nits about formatting things. I will push those changes and get this PR merged.
| NETPLAN_INTERNAL gboolean | ||
| netplan_nm_cleanup(const char* rootdir); | ||
|
|
||
|
|
There was a problem hiding this comment.
Add comment about deprecated API, instead of additional whitespace.
| write_search_domains(def, "ipv4", kf); | ||
| write_routes(def, kf, AF_INET); | ||
| if (!write_routes(def, kf, AF_INET, error)) | ||
| return FALSE; |
| /** | ||
| * Generate networkd configuration in @rootdir/run/systemd/network/ from the | ||
| * parsed #netdefs. | ||
| * @rootdir: If not %NULL, generate configuration in this root directory | ||
| * (useful for testing). | ||
| * Returns: TRUE if @def applies to networkd, FALSE otherwise. | ||
| */ |
There was a problem hiding this comment.
We should probably keep that comment in networkd.c (instead of abi_compat.c)
| /** | ||
| * Create enablement symlink for systemd-networkd.service. | ||
| */ |
There was a problem hiding this comment.
Let's not drop this comment, but move it to generate.c, too.
|
passed integration tests with ABI compatibility check: |
Description
New APIs for the generator APIs of libnetplan, with proper error handling and support for the NetplanState feature.
API and ABI compatibility is retained for now. Depends on #232 and #234, as usual see the commits after the merge.
Checklist
make checksuccessfully.make check-coverage).