Skip to content

Commit

Permalink
o/snapstate: make sure to put aux info from store on SnapSetup (#14482)
Browse files Browse the repository at this point in the history
* o/snapstate: make sure to put aux info from store on SnapSetup

* tests: add test that inspects aux info from snapd

* tests: correct summary and details on spread test

* tests: use snap-store for testing since it will always have some media
  • Loading branch information
andrewphelpsj authored Sep 10, 2024
1 parent c21532e commit 2103a58
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 22 deletions.
13 changes: 13 additions & 0 deletions overlord/snapstate/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,19 @@ func (f *fakeStore) snap(spec snapSpec) (*snap.Info, error) {
},
},
}
case "channel-for-media":
info.Media = snap.MediaInfos{
snap.MediaInfo{
Type: "icon",
URL: "http://example.com/icon.png",
Width: 100,
Height: 100,
},
snap.MediaInfo{
Type: "website",
URL: "http://example.com",
},
}
}

if spec.Name == "provenance-snap" {
Expand Down
63 changes: 41 additions & 22 deletions overlord/snapstate/snapstate_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ func (s *snapmgrTestSuite) TestInstallRunThrough(c *C) {
c.Check(snapstate.AuxStoreInfoFilename("some-snap-id"), testutil.FileAbsent)

chg := s.state.NewChange("install", "install a snap")
opts := &snapstate.RevisionOptions{Channel: "some-channel"}
opts := &snapstate.RevisionOptions{Channel: "channel-for-media"}
ts, err := snapstate.Install(context.Background(), s.state, "some-snap", opts, s.user.ID, snapstate.Flags{})
c.Assert(err, IsNil)
chg.AddAll(ts)
Expand All @@ -1307,7 +1307,7 @@ func (s *snapmgrTestSuite) TestInstallRunThrough(c *C) {
action: store.SnapAction{
Action: "install",
InstanceName: "some-snap",
Channel: "some-channel",
Channel: "channel-for-media",
},
revno: snap.R(11),
userID: 1,
Expand All @@ -1331,7 +1331,7 @@ func (s *snapmgrTestSuite) TestInstallRunThrough(c *C) {
sinfo: snap.SideInfo{
RealName: "some-snap",
SnapID: "some-snap-id",
Channel: "some-channel",
Channel: "channel-for-media",
Revision: snap.R(11),
},
},
Expand Down Expand Up @@ -1360,7 +1360,7 @@ func (s *snapmgrTestSuite) TestInstallRunThrough(c *C) {
sinfo: snap.SideInfo{
RealName: "some-snap",
SnapID: "some-snap-id",
Channel: "some-channel",
Channel: "channel-for-media",
Revision: snap.R(11),
},
},
Expand Down Expand Up @@ -1392,7 +1392,7 @@ func (s *snapmgrTestSuite) TestInstallRunThrough(c *C) {
_, cur, total := task.Progress()
c.Assert(cur, Equals, s.fakeStore.fakeCurrentProgress)
c.Assert(total, Equals, s.fakeStore.fakeTotalProgress)
c.Check(task.Summary(), Equals, `Download snap "some-snap" (11) from channel "some-channel"`)
c.Check(task.Summary(), Equals, `Download snap "some-snap" (11) from channel "channel-for-media"`)

// check install-record present
mountTask := ta[len(ta)-12]
Expand All @@ -1411,22 +1411,22 @@ func (s *snapmgrTestSuite) TestInstallRunThrough(c *C) {
var snapsup snapstate.SnapSetup
err = task.Get("snap-setup", &snapsup)
c.Assert(err, IsNil)
c.Assert(snapsup, DeepEquals, snapstate.SnapSetup{
Channel: "some-channel",
UserID: s.user.ID,
SnapPath: filepath.Join(dirs.SnapBlobDir, "some-snap_11.snap"),
DownloadInfo: &snap.DownloadInfo{
DownloadURL: "https://some-server.com/some/path.snap",
Size: 5,
},
SideInfo: snapsup.SideInfo,
Type: snap.TypeApp,
Version: "some-snapVer",
PlugsOnly: true,

c.Assert(snapsup.Channel, Equals, "channel-for-media")
c.Assert(snapsup.UserID, Equals, s.user.ID)
c.Assert(snapsup.SnapPath, Matches, `.*some-snap_11.snap`)
c.Assert(snapsup.DownloadInfo, DeepEquals, &snap.DownloadInfo{
DownloadURL: "https://some-server.com/some/path.snap",
Size: 5,
})
c.Assert(snapsup.SideInfo, DeepEquals, snapsup.SideInfo)
c.Assert(snapsup.Type, Equals, snap.TypeApp)
c.Assert(snapsup.Version, Equals, "some-snapVer")
c.Assert(snapsup.PlugsOnly, Equals, true)

c.Assert(snapsup.SideInfo, DeepEquals, &snap.SideInfo{
RealName: "some-snap",
Channel: "some-channel",
Channel: "channel-for-media",
Revision: snap.R(11),
SnapID: "some-snap-id",
})
Expand All @@ -1439,17 +1439,36 @@ func (s *snapmgrTestSuite) TestInstallRunThrough(c *C) {
snapst := snaps["some-snap"]
c.Assert(snapst, NotNil)
c.Assert(snapst.Active, Equals, true)
c.Assert(snapst.TrackingChannel, Equals, "some-channel/stable")
c.Assert(snapst.TrackingChannel, Equals, "channel-for-media/stable")
c.Assert(snapst.Sequence.Revisions[0], DeepEquals, sequence.NewRevisionSideState(&snap.SideInfo{
RealName: "some-snap",
SnapID: "some-snap-id",
Channel: "some-channel",
Channel: "channel-for-media",
Revision: snap.R(11),
}, nil))
c.Assert(snapst.Required, Equals, false)

// we end with the auxiliary store info
c.Check(snapstate.AuxStoreInfoFilename("some-snap-id"), testutil.FilePresent)
info := snap.Info{
SideInfo: snap.SideInfo{
SnapID: "some-snap-id",
RealName: "some-snap",
},
}
err = snapstate.RetrieveAuxStoreInfo(&info)
c.Assert(err, IsNil)

c.Assert(info.Media, DeepEquals, snap.MediaInfos{
snap.MediaInfo{
Type: "icon",
URL: "http://example.com/icon.png",
Width: 100,
Height: 100,
},
snap.MediaInfo{
Type: "website",
URL: "http://example.com",
},
})
}

func (s *snapmgrTestSuite) testParallelInstanceInstallRunThrough(c *C, inputFlags, expectedFlags snapstate.Flags) {
Expand Down
5 changes: 5 additions & 0 deletions overlord/snapstate/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ func (t *target) setups(st *state.State, opts Options) (SnapSetup, []ComponentSe
InstanceKey: t.info.InstanceKey,
ExpectedProvenance: t.info.SnapProvenance,
Registries: registries,
auxStoreInfo: auxStoreInfo{
Media: t.info.Media,
// XXX we store this for the benefit of old snapd
Website: t.info.Website(),
},
}, compsups, nil
}

Expand Down
26 changes: 26 additions & 0 deletions tests/main/aux-info/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
summary: Test that snap aux info is correctly stored and returned by the snapd API

details: |
When installing a snap, we should store some auxiliary information about that
snap in /var/cache/snapd/aux. This test verifies that this is properly done,
and then verifies that the information is returned by the snapd API.
systems: [ubuntu-18.04-64, ubuntu-2*, ubuntu-core-*, fedora-*]

prepare: |
snap install snap-store
snap install jq
snap install --devmode --edge test-snapd-curl
execute: |
snap_id=$(snap info snap-store | grep snap-id | awk '{ print $2 }')
jq --sort-keys .media < "/var/cache/snapd/aux/${snap_id}.json" > media.json
# don't depend on the exact number of media files, but there should be
# something here
media_length=$(jq '. | length' < media.json)
test "${media_length}" -gt 0
test-snapd-curl.curl -s --unix-socket /run/snapd.socket --max-time 5 'http://localhost/v2/snaps/snap-store' | jq --sort-keys .result.media > snapd-media.json
diff media.json snapd-media.json

0 comments on commit 2103a58

Please sign in to comment.