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

o/snapstate: check disk space w/o store if possible #11159

Merged
merged 4 commits into from Dec 14, 2021

Conversation

MiguelPires
Copy link
Contributor

The disk space checks were obtaining the size of the snaps' prerequisites and
base via a call to the store. However, an InstallPathMany should allow the
user to install without calls to the store, if all requirements are
available locally. This change makes it so that, if the required bases and
prereqs are included in the install, those are used for the disk check instead
of gotten through the store. Note that for Install/UpdateMany with
prerequisites the already downloaded prereqs are also used, instead of
redownloaded.

The disk space checks were obtaining the size of the snaps' prerequisites and
base via a call to the store. However, an InstallPathMany should allow the
user to install without calls to the store, if all requirements are
available locally. This change makes it so that, if the required bases and
prereqs are included in the install, those are used for the disk check instead
of gotten through the store. Note that for Install/UpdateMany with
prerequisites the already downloaded prereqs are also used, instead of
redownloaded.
@pedronis pedronis self-requested a review December 9, 2021 15:49
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!

Replaced the snapstate tests that assert the install size can work
locally with more focused storehelpers tests. Changed the snapstate
tests that assert that the InstallPathMany works w/o the store to
include the disk space checks as well.
@MiguelPires
Copy link
Contributor Author

I refactored the long snapstate tests into more focused storehelper tests for the installSize code and one snapstate test that asserts that InstallPathMany (including disk space checks) doesn't call the store. I think in terms of testing this achieves the same goal while cutting the PR diff almost in half.

Copy link
Contributor

@stolowski stolowski left a comment

Choose a reason for hiding this comment

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

A few comments.

overlord/snapstate/storehelpers_test.go Show resolved Hide resolved

// core is already installed
s.mockCoreSnap(c)
coreSize := getInstalledSnapSize(c, st, "core")
Copy link
Contributor

Choose a reason for hiding this comment

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

This could use a c.Assert(coreSize, Not(Equals), int64(0)) check (or a precise check for expected size), and it will currently fail, but see my other comment.

overlord/snapstate/storehelpers_test.go Show resolved Hide resolved
sz, err := snapstate.InstallSize(st, []snapstate.MinimalInstallInfo{
snapstate.InstallSnapInfo{Info: snap1}, snapstate.InstallSnapInfo{Info: snap2}}, 0)
c.Assert(err, IsNil)
c.Check(sz, Equals, uint64(snap1.Size+snap2.Size+coreSize))
Copy link
Contributor

Choose a reason for hiding this comment

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

Existing tests in this suite use predefined const for expected sizes (see snap1Size, snap2Size etc.) so that any unexpected size would fail; can we do the same here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I think all snaps are locally installed as well in this test. Maybe we should have one more test where one snap is available locally and the other isn't, and we hit the store.

i, err := snapst.CurrentInfo()
c.Assert(err, IsNil)

return i.DownloadInfo.Size
Copy link
Contributor

Choose a reason for hiding this comment

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

Download size inside info is ephemeral and only available when we have snap.Info coming right from the store - see snap.Info struct, the comment above embedded DownloadInfo, so I think we will get 0 here.

I think for local snaps installed via InstallPathMany, to avoid store calls, we should check the size of the snap blobs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

as we discussed elsewhere:

I was checking the same, it's set in ReadInfoFromSnapFile
maybe though for symmetry DownloadSize of pathInfo should do simply: return Info.Size

@@ -113,6 +113,11 @@ var installSize = func(st *state.State, snaps []minimalInstallInfo, userID int)
accountedSnaps[snap.InstanceName] = true
}

// if prerequisites are included in the install, don't download them again
Copy link
Contributor

Choose a reason for hiding this comment

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

We aren't technically downloading them, only querying for size, the comment should probably be tweaked.

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.

lgtm but please take into account @stolowski comments

@MiguelPires
Copy link
Contributor Author

@stolowski thanks for the feedback. The last commits add the test you mention as well as the other improvements

@codecov-commenter
Copy link

Codecov Report

Merging #11159 (f6b4176) into master (5f5e786) will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #11159      +/-   ##
==========================================
+ Coverage   78.26%   78.32%   +0.06%     
==========================================
  Files         918      920       +2     
  Lines      104403   104874     +471     
==========================================
+ Hits        81706    82141     +435     
- Misses      17580    17604      +24     
- Partials     5117     5129      +12     
Flag Coverage Δ
unittests 78.32% <100.00%> (+0.06%) ⬆️

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

Impacted Files Coverage Δ
overlord/snapstate/handlers.go 71.12% <ø> (+0.07%) ⬆️
snap/info.go 86.79% <ø> (ø)
overlord/snapstate/snapstate.go 83.16% <100.00%> (+0.15%) ⬆️
overlord/snapstate/storehelpers.go 77.35% <100.00%> (+0.11%) ⬆️
snap/helpers.go 4.16% <0.00%> (-95.84%) ⬇️
overlord/snapstate/backend/copydata.go 51.82% <0.00%> (-2.03%) ⬇️
store/cache.go 69.23% <0.00%> (-1.93%) ⬇️
systemd/emulation.go 40.54% <0.00%> (-0.75%) ⬇️
daemon/api.go 100.00% <0.00%> (ø)
interfaces/builtin/mount_control.go 98.13% <0.00%> (ø)
... and 6 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 5f5e786...f6b4176. Read the comment docs.

Copy link
Contributor

@stolowski stolowski 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 improvements, LGTM.

@mvo5 mvo5 merged commit 0190c13 into snapcore:master Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants