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
configcore: implement netplan write support via dbus #10752
Conversation
The netplan configuration will need to check if the store is reachable before and after the network configuration got updated. This commit adds the needed helper and tests to ensure that the store is reachable.
Implement writing netplan configuration using the dbus interface. This works by creating a configuration snapshot that is then `Try()ed` and if the store is reachable after the try (or was never reachable in the first place) then it it `Apply()ed`.
…. always clear config first)
Codecov Report
@@ Coverage Diff @@
## master #10752 +/- ##
==========================================
- Coverage 78.31% 78.26% -0.06%
==========================================
Files 920 923 +3
Lines 104871 105473 +602
==========================================
+ Hits 82131 82548 +417
- Misses 17611 17783 +172
- Partials 5129 5142 +13
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
8e75cbe
to
8bccfb2
Compare
Having a different than the default config file seems to also cause grief with netplan so avoid it by just using the default ubuntu core netplan configuration.
8bccfb2
to
42336f4
Compare
I think this is ready for a review - it still contains a workaround for unexpected netplan dbus behavior but most of the core of the change is ready. |
This fails right now in GCE because there is only |
4211d2f
to
31d2961
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.
LGTM!
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.
clarification
// Use a origin hint that is sorted before the console-conf | ||
// "00-snapd-config.yaml" so that console-conf can override | ||
// our settings when it runs. | ||
originHint := "0-snap-set" |
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.
sorry, maybe my remark was not clear. We can't just do this either. I fear we need to use different hints at different times:
- 0-snapd-defaults if seeded is false
- 90-snapd-config if seeded is true
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.
Sorry for that misunderstanding on my part, updated and tests added (including an early config test).
… during seeding or later (thansk to Samuele)
Fwiw, I ran the nested test manually:
|
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.
thanks for the change. Question about testing. I think @slyon should look at this again.
@@ -64,6 +68,9 @@ execute: | | |||
tests.nested exec "cat /var/snap/pc/common/debug.txt" | MATCH "hostname: foo" | |||
tests.nested exec "cat /etc/hostname" | MATCH "foo" | |||
tests.nested exec "hostname" | MATCH "foo" | |||
|
|||
# netplan config | |||
tests.nested exec "cat /etc/netplan/0-snapd-defaults.yaml" | MATCH br54 |
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.
can we somehow check that setting dhcp4 to false or similar works as expected at this point?
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.
I added two more tests for this, one that uses a static IP during boot and one that checks that incremental network settings work.
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.
the extra testing is good, but is different from what I was thinking. My question was to test that setting later on top of the defaults works
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.
@pedronis oh, sorry again that I misunderstood - I added extra checks for this now as well. Good catch!
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.
mvo's test cases look good to me. I can confirm that an interface definition in 0-snapd-defaults.yaml
of the same name as an interface definition in 90-snapd-config.yaml
would be overridden (the 90-snapd-config.yaml
settings be in place).
And that is being tested in the # and updating netplan works
section.
@pedronis Is there anything more specific that you wanted me to have a look at?
Thanks to Samuele for the suggestion.
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.
still a testing question
@@ -64,6 +68,9 @@ execute: | | |||
tests.nested exec "cat /var/snap/pc/common/debug.txt" | MATCH "hostname: foo" | |||
tests.nested exec "cat /etc/hostname" | MATCH "foo" | |||
tests.nested exec "hostname" | MATCH "foo" | |||
|
|||
# netplan config | |||
tests.nested exec "cat /etc/netplan/0-snapd-defaults.yaml" | MATCH br54 |
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.
the extra testing is good, but is different from what I was thinking. My question was to test that setting later on top of the defaults works
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.
question about canceling vs errors
tests.nested exec "netplan get bridges.br54.dhcp4" | MATCH false | ||
tests.nested exec "sudo snap get system system.network.netplan.network.bridges.br54.dhcp4" | MATCH false | ||
# ensure the test can be repeated | ||
tests.nested exec "sudo rm -f /etc/netplan/90-snapd-config.yaml" |
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.
do we need something also in the restore stanza?
@@ -113,5 +282,14 @@ func getNetplanFromSystem(key string) (result interface{}, err error) { | |||
return nil, err | |||
} | |||
|
|||
// and discard the config snapshot | |||
var wasCancelled bool | |||
if err := netplanCfgSnapshot.Call("io.netplan.Netplan.Config.Cancel", 0).Store(&wasCancelled); err != nil { |
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.
does it make sense to do this as a defer instead?
|
||
if storeReachableBefore && !storeReachableAfter { | ||
var wasCancelled bool | ||
if err := netplanCfgSnapshot.Call("io.netplan.Netplan.Config.Cancel", 0).Store(&wasCancelled); err != nil { |
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.
should we have this as a defer that checks if we are returning an error?
…en if something failed
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.
I like the extensive testing of this PR!
I recently had a call with the Field Engineering team and we were wondering if the new snap get/set functionality for networking/netplan settings would be tested in combination with the NetworkManager snap. I do not see any NetworkManager related tests in this PR, would it be possible to add some E2E test for that scenario as well? Something like snap set system system.network.netplan.network ...
&& nmcli con show ...
(and the other way around, to check the bidirectional propagation of (supported) settings).
Thanks for the suggestion and review and I'm happy to do this, I will poke at it a bit but maybe this should be a followup given that this is already quite a big PR. |
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.
thank you
Uhhh - sorry only now saw that the review from Mardy got dismissed (for the right reasons) - sorry, too trigger happy, happy to fix anything that mardy will find. |
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.
Still LGTM! Added one comment, but it's irrelevant :-)
var snapstateStore = func(st *state.State, deviceCtx snapstate.DeviceContext) connectivityCheckStore { | ||
return snapstate.Store(st, deviceCtx) | ||
} |
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.
Any reason why this is not just var snapstateStore = snapstate.Store
?
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.
Probably not, silly me! I can look into this next.
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.
Aha, actually I remember now - I think the reaosn is that I wanted to return the connectivityCheckStore interface only so that I need to mock less :)
Implement writing netplan configuration using the dbus interface.
This works by creating a configuration snapshot that is then
Try()ed
and if the store is reachable after the try (or wasnever reachable in the first place) then it it
Apply()ed
.