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

configcore: implement netplan write support via dbus #10752

Merged
merged 45 commits into from Jan 21, 2022

Conversation

mvo5
Copy link
Contributor

@mvo5 mvo5 commented Sep 7, 2021

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.

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`.
@codecov-commenter
Copy link

codecov-commenter commented Sep 9, 2021

Codecov Report

Merging #10752 (68d1c34) into master (eec64b4) will decrease coverage by 0.05%.
The diff coverage is 9.39%.

Impacted file tree graph

@@            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     
Flag Coverage Δ
unittests 78.26% <9.39%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
overlord/configstate/configcore/netplan.go 9.83% <8.78%> (-11.32%) ⬇️
overlord/configstate/configcore/runwithstate.go 92.47% <100.00%> (ø)
store/cache.go 69.23% <0.00%> (-1.93%) ⬇️
sandbox/cgroup/tracking.go 92.72% <0.00%> (-1.27%) ⬇️
usersession/client/client.go 81.68% <0.00%> (-0.80%) ⬇️
dirs/dirs.go 94.02% <0.00%> (-0.70%) ⬇️
overlord/overlord.go 80.69% <0.00%> (-0.20%) ⬇️
overlord/ifacestate/handlers.go 64.87% <0.00%> (-0.15%) ⬇️
... and 53 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 eec64b4...68d1c34. Read the comment docs.

@mvo5 mvo5 force-pushed the netplan-read-write branch 2 times, most recently from 8e75cbe to 8bccfb2 Compare November 4, 2021 16:51
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.
@mvo5 mvo5 marked this pull request as ready for review November 4, 2021 21:31
@mvo5
Copy link
Contributor Author

mvo5 commented Nov 4, 2021

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.

@mvo5
Copy link
Contributor Author

mvo5 commented Nov 5, 2021

This fails right now in GCE because there is only /etc/netplan/50-cloud-init.yaml in our test uc20 and netplan will crash if there is no origin hint file on disk https://bugs.launchpad.net/netplan/+bug/1949884

Copy link
Contributor

@mardy mardy left a comment

Choose a reason for hiding this comment

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

LGTM!

overlord/configstate/configcore/netplan.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@pedronis pedronis left a 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"
Copy link
Collaborator

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

Copy link
Contributor Author

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).

@mvo5 mvo5 added the Run nested The PR also runs tests inluded in nested suite label Jan 4, 2022
@mvo5
Copy link
Contributor Author

mvo5 commented Jan 4, 2022

Fwiw, I ran the nested test manually:

$ spread -v -debug google-nested:ubuntu-20.04-64:tests/nested/manual/core20-early-config
...
2022-01-04 16:56:51 Preparing google-nested:ubuntu-20.04-64:tests/nested/manual/ (jan041549-956268)...
2022-01-04 16:57:22 Preparing google-nested:ubuntu-20.04-64:tests/nested/manual/core20-early-config (jan041549-956268)...
2022-01-04 17:05:23 Executing google-nested:ubuntu-20.04-64:tests/nested/manual/core20-early-config (jan041549-956268) (1/1)...
2022-01-04 17:06:30 Restoring google-nested:ubuntu-20.04-64:tests/nested/manual/core20-early-config (jan041549-956268)...
2022-01-04 17:06:31 Restoring google-nested:ubuntu-20.04-64:tests/nested/manual/ (jan041549-956268)...
2022-01-04 17:06:37 Restoring google-nested:ubuntu-20.04-64 (jan041549-956268)...
2022-01-04 17:06:38 Discarding google-nested:ubuntu-20.04-64 (jan041549-956268)...
2022-01-04 17:06:39 Successful tasks: 1
2022-01-04 17:06:39 Aborted tasks: 0

@pedronis pedronis self-requested a review January 10, 2022 10:13
Copy link
Collaborator

@pedronis pedronis left a 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
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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

Copy link
Contributor Author

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!

Copy link
Contributor

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?

Copy link
Collaborator

@pedronis pedronis left a 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
Copy link
Collaborator

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

@pedronis pedronis self-requested a review January 13, 2022 10:11
Copy link
Collaborator

@pedronis pedronis left a 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"
Copy link
Collaborator

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 {
Copy link
Collaborator

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 {
Copy link
Collaborator

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?

Copy link
Contributor

@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.

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).

@mvo5
Copy link
Contributor Author

mvo5 commented Jan 17, 2022

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.

@pedronis pedronis self-requested a review January 20, 2022 12:55
Copy link
Collaborator

@pedronis pedronis 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

@pedronis pedronis dismissed mardy’s stale review January 20, 2022 17:03

this has changed quite a bit since

@mvo5 mvo5 merged commit 4e01535 into snapcore:master Jan 21, 2022
@mvo5
Copy link
Contributor Author

mvo5 commented Jan 21, 2022

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.

Copy link
Contributor

@mardy mardy left a 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 :-)

Comment on lines +64 to +66
var snapstateStore = func(st *state.State, deviceCtx snapstate.DeviceContext) connectivityCheckStore {
return snapstate.Store(st, deviceCtx)
}
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Samuele review Needs a review from Samuele before it can land Run nested The PR also runs tests inluded in nested suite
Projects
None yet
6 participants