Permalink
Browse files

overlord, store: move confinement filtering to the overlord (from The…

… Store)
  • Loading branch information...
1 parent c00295e commit 024cf1e66afd36707bd06a45dc961aea5819670e @chipaca chipaca committed Jan 10, 2017
View
@@ -565,7 +565,6 @@ func findOne(c *Command, r *http.Request, user *auth.UserState, name string) Res
spec := store.SnapSpec{
Name: name,
Channel: "",
- Devmode: true,
Revision: snap.R(0),
}
snapInfo, err := theStore.SnapInfo(spec, user)
View
@@ -70,7 +70,6 @@ func DownloadSnap(sto Store, name string, revision snap.Revision, opts *Download
spec := store.SnapSpec{
Name: name,
Channel: opts.Channel,
- Devmode: opts.DevMode,
Revision: revision,
}
snap, err := sto.SnapInfo(spec, opts.User)
@@ -112,6 +112,14 @@ func (f *fakeStore) SnapInfo(spec store.SnapSpec, user *auth.UserState) (*snap.I
}
}
+ confinement := snap.StrictConfinement
+ switch spec.Channel {
+ case "channel-for-devmode":
+ confinement = snap.DevModeConfinement
+ case "channel-for-classic":
+ confinement = snap.ClassicConfinement
+ }
+
info := &snap.Info{
SideInfo: snap.SideInfo{
RealName: strings.Split(spec.Name, ".")[0],
@@ -123,6 +131,7 @@ func (f *fakeStore) SnapInfo(spec store.SnapSpec, user *auth.UserState) (*snap.I
DownloadInfo: snap.DownloadInfo{
DownloadURL: "https://some-server.com/some/path.snap",
},
+ Confinement: confinement,
}
f.fakeBackend.ops = append(f.fakeBackend.ops, fakeOp{op: "storesvc-snap", name: spec.Name, revno: spec.Revision})
@@ -162,8 +171,14 @@ func (f *fakeStore) ListRefresh(cands []*store.RefreshCandidate, _ *auth.UserSta
}
revno := snap.R(11)
- if cand.Channel == "channel-for-7" {
+ confinement := snap.StrictConfinement
+ switch cand.Channel {
+ case "channel-for-7":
revno = snap.R(7)
+ case "channel-for-classic":
+ confinement = snap.ClassicConfinement
+ case "channel-for-devmode":
+ confinement = snap.DevModeConfinement
}
info := &snap.Info{
@@ -177,6 +192,7 @@ func (f *fakeStore) ListRefresh(cands []*store.RefreshCandidate, _ *auth.UserSta
DownloadInfo: snap.DownloadInfo{
DownloadURL: "https://some-server.com/some/path.snap",
},
+ Confinement: confinement,
}
var hit snap.Revision
@@ -259,7 +259,7 @@ func Store(st *state.State) StoreService {
panic("internal error: needing the store before managers have initialized it")
}
-func updateInfo(st *state.State, snapst *SnapState, channel string, userID int, flags Flags) (*snap.Info, error) {
+func updateInfo(st *state.State, snapst *SnapState, channel string, userID int) (*snap.Info, error) {
user, err := userFromUserID(st, userID)
if err != nil {
return nil, err
@@ -275,9 +275,7 @@ func updateInfo(st *state.State, snapst *SnapState, channel string, userID int,
refreshCand := &store.RefreshCandidate{
// the desired channel
- Channel: channel,
- DevMode: flags.DevModeAllowed(),
-
+ Channel: channel,
SnapID: curInfo.SnapID,
Revision: curInfo.Revision,
Epoch: curInfo.Epoch,
@@ -293,10 +291,11 @@ func updateInfo(st *state.State, snapst *SnapState, channel string, userID int,
if len(res) == 0 {
return nil, &snap.NoUpdateAvailableError{Snap: curInfo.Name()}
}
+
return res[0], nil
}
-func snapInfo(st *state.State, name, channel string, revision snap.Revision, userID int, flags Flags) (*snap.Info, error) {
+func snapInfo(st *state.State, name, channel string, revision snap.Revision, userID int) (*snap.Info, error) {
user, err := userFromUserID(st, userID)
if err != nil {
return nil, err
@@ -306,7 +305,6 @@ func snapInfo(st *state.State, name, channel string, revision snap.Revision, use
spec := store.SnapSpec{
Name: name,
Channel: channel,
- Devmode: flags.DevModeAllowed(),
Revision: revision,
}
snap, err := theStore.SnapInfo(spec, user)
@@ -503,7 +501,6 @@ func (m *SnapManager) doDownloadSnap(t *state.Task, tomb *tomb.Tomb) error {
spec := store.SnapSpec{
Name: snapsup.Name(),
Channel: snapsup.Channel,
- Devmode: snapsup.DevModeAllowed(),
Revision: snapsup.Revision(),
}
storeInfo, err = theStore.SnapInfo(spec, user)
@@ -185,6 +185,34 @@ func (s *snapmgrTestSuite) TestLastIndexFindsLast(c *C) {
c.Check(snapst.LastIndex(snap.R(11)), Equals, 2)
}
+func (s *snapmgrTestSuite) TestInstallDevModeConfinementFiltering(c *C) {
+ s.state.Lock()
+ defer s.state.Unlock()
+
+ _, err := snapstate.Install(s.state, "some-snap", "channel-for-devmode", snap.R(0), s.user.ID, snapstate.Flags{})
+ c.Assert(err, ErrorMatches, `cannot find snap "some-snap"`)
+
+ _, err = snapstate.Install(s.state, "some-snap", "channel-for-devmode", snap.R(0), s.user.ID, snapstate.Flags{DevMode: true})
+ c.Assert(err, IsNil)
+
+ _, err = snapstate.Install(s.state, "some-snap", "channel-for-strict", snap.R(0), s.user.ID, snapstate.Flags{DevMode: true})
+ c.Assert(err, IsNil)
+}
+
+func (s *snapmgrTestSuite) TestInstallClassicConfinementFiltering(c *C) {
+ s.state.Lock()
+ defer s.state.Unlock()
+
+ _, err := snapstate.Install(s.state, "some-snap", "channel-for-classic", snap.R(0), s.user.ID, snapstate.Flags{})
+ c.Assert(err, ErrorMatches, `cannot find snap "some-snap"`)
+
+ _, err = snapstate.Install(s.state, "some-snap", "channel-for-classic", snap.R(0), s.user.ID, snapstate.Flags{Classic: true})
+ c.Assert(err, IsNil)
+
+ _, err = snapstate.Install(s.state, "some-snap", "channel-for-strict", snap.R(0), s.user.ID, snapstate.Flags{Classic: true})
+ c.Assert(err, IsNil)
+}
+
func (s *snapmgrTestSuite) TestInstallTasks(c *C) {
s.state.Lock()
defer s.state.Unlock()
@@ -300,6 +328,59 @@ func (s *snapmgrTestSuite) TestUpdateMany(c *C) {
c.Assert(s.state.TaskCount(), Equals, len(ts.Tasks()))
}
+func (s *snapmgrTestSuite) TestUpdateManyDevModeConfinementFiltering(c *C) {
+ s.state.Lock()
+ defer s.state.Unlock()
+
+ snapstate.Set(s.state, "some-snap", &snapstate.SnapState{
+ Active: true,
+ Channel: "channel-for-devmode",
+ Sequence: []*snap.SideInfo{{RealName: "some-snap", SnapID: "some-snap-id", Revision: snap.R(7)}},
+ Current: snap.R(7),
+ SnapType: "app",
+ })
+
+ _, tts, _ := snapstate.UpdateMany(s.state, []string{"some-snap"}, s.user.ID)
+ // FIXME: UpdateMany will not error out in this case (daemon catches this case, with a weird error)
+ c.Assert(tts, HasLen, 0)
+}
+
+func (s *snapmgrTestSuite) TestUpdateManyClassicConfinementFiltering(c *C) {
+ s.state.Lock()
+ defer s.state.Unlock()
+
+ snapstate.Set(s.state, "some-snap", &snapstate.SnapState{
+ Active: true,
+ Channel: "channel-for-classic",
+ Sequence: []*snap.SideInfo{{RealName: "some-snap", SnapID: "some-snap-id", Revision: snap.R(7)}},
+ Current: snap.R(7),
+ SnapType: "app",
+ })
+
+ _, tts, _ := snapstate.UpdateMany(s.state, []string{"some-snap"}, s.user.ID)
+ // FIXME: UpdateMany will not error out in this case (daemon catches this case, with a weird error)
+ c.Assert(tts, HasLen, 0)
+}
+
+func (s *snapmgrTestSuite) TestUpdateManyClassic(c *C) {
+ s.state.Lock()
+ defer s.state.Unlock()
+
+ snapstate.Set(s.state, "some-snap", &snapstate.SnapState{
+ Active: true,
+ Channel: "channel-for-classic",
+ Sequence: []*snap.SideInfo{{RealName: "some-snap", SnapID: "some-snap-id", Revision: snap.R(7)}},
+ Current: snap.R(7),
+ SnapType: "app",
+ Flags: snapstate.Flags{Classic: true},
+ })
+
+ // snap installed with classic: refresh gets classic
+ _, tts, err := snapstate.UpdateMany(s.state, []string{"some-snap"}, s.user.ID)
+ c.Assert(err, IsNil)
+ c.Assert(tts, HasLen, 1)
+}
+
func (s *snapmgrTestSuite) TestUpdateManyDevMode(c *C) {
s.state.Lock()
defer s.state.Unlock()
@@ -646,7 +727,7 @@ func (s *snapmgrTestSuite) TestInstallPathSnapIDRevisionUnset(c *C) {
c.Assert(err, ErrorMatches, fmt.Sprintf(`internal error: snap id set to install %q but revision is unset`, mockSnap))
}
-func (s *snapmgrTestSuite) TestUpdateTasksPropagtesErrors(c *C) {
+func (s *snapmgrTestSuite) TestUpdateTasksPropagatesErrors(c *C) {
s.state.Lock()
defer s.state.Unlock()
@@ -695,54 +776,106 @@ func (s *snapmgrTestSuite) TestUpdateTasks(c *C) {
c.Check(snapsup.Channel, Equals, "some-channel")
}
-func (s *snapmgrTestSuite) TestUpdateChannelFallback(c *C) {
+func (s *snapmgrTestSuite) TestUpdateDevModeConfinementFiltering(c *C) {
s.state.Lock()
defer s.state.Unlock()
snapstate.Set(s.state, "some-snap", &snapstate.SnapState{
Active: true,
- Channel: "edge",
+ Channel: "channel-for-devmode",
Sequence: []*snap.SideInfo{{RealName: "some-snap", SnapID: "some-snap-id", Revision: snap.R(7)}},
Current: snap.R(7),
SnapType: "app",
})
- ts, err := snapstate.Update(s.state, "some-snap", "", snap.R(0), s.user.ID, snapstate.Flags{})
+ _, err := snapstate.Update(s.state, "some-snap", "", snap.R(0), s.user.ID, snapstate.Flags{})
+ c.Assert(err, ErrorMatches, `snap "some-snap" has no updates available`)
+
+ _, err = snapstate.Update(s.state, "some-snap", "", snap.R(0), s.user.ID, snapstate.Flags{DevMode: true})
c.Assert(err, IsNil)
+}
- var snapsup snapstate.SnapSetup
- err = ts.Tasks()[0].Get("snap-setup", &snapsup)
+func (s *snapmgrTestSuite) TestUpdateClassicConfinementFiltering(c *C) {
+ s.state.Lock()
+ defer s.state.Unlock()
+
+ snapstate.Set(s.state, "some-snap", &snapstate.SnapState{
+ Active: true,
+ Channel: "channel-for-classic",
+ Sequence: []*snap.SideInfo{{RealName: "some-snap", SnapID: "some-snap-id", Revision: snap.R(7)}},
+ Current: snap.R(7),
+ SnapType: "app",
+ })
+
+ _, err := snapstate.Update(s.state, "some-snap", "", snap.R(0), s.user.ID, snapstate.Flags{})
+ c.Assert(err, ErrorMatches, `snap "some-snap" has no updates available`)
+
+ _, err = snapstate.Update(s.state, "some-snap", "", snap.R(0), s.user.ID, snapstate.Flags{Classic: true})
c.Assert(err, IsNil)
+}
- c.Check(snapsup.Channel, Equals, "edge")
+func (s *snapmgrTestSuite) TestUpdateClassic(c *C) {
+ s.state.Lock()
+ defer s.state.Unlock()
+
+ snapstate.Set(s.state, "some-snap", &snapstate.SnapState{
+ Active: true,
+ Channel: "channel-for-classic",
+ Sequence: []*snap.SideInfo{{RealName: "some-snap", SnapID: "some-snap-id", Revision: snap.R(7)}},
+ Current: snap.R(7),
+ SnapType: "app",
+ Flags: snapstate.Flags{Classic: true},
+ })
+
+ // snap installed with classic: refresh gets classic
+ _, err := snapstate.Update(s.state, "some-snap", "", snap.R(0), s.user.ID, snapstate.Flags{})
+ c.Assert(err, IsNil)
+
+ _, err = snapstate.Update(s.state, "some-snap", "", snap.R(0), s.user.ID, snapstate.Flags{Classic: true})
+ c.Assert(err, IsNil)
}
-func (s *snapmgrTestSuite) TestUpdatePassDevMode(c *C) {
+func (s *snapmgrTestSuite) TestUpdateStrictFromClassic(c *C) {
s.state.Lock()
defer s.state.Unlock()
snapstate.Set(s.state, "some-snap", &snapstate.SnapState{
Active: true,
+ Channel: "channel",
Sequence: []*snap.SideInfo{{RealName: "some-snap", SnapID: "some-snap-id", Revision: snap.R(7)}},
Current: snap.R(7),
SnapType: "app",
+ Flags: snapstate.Flags{Classic: true},
})
- _, err := snapstate.Update(s.state, "some-snap", "some-channel", snap.R(0), s.user.ID, snapstate.Flags{DevMode: true})
+ // snap installed with classic: refresh gets classic
+ _, err := snapstate.Update(s.state, "some-snap", "", snap.R(0), s.user.ID, snapstate.Flags{})
c.Assert(err, IsNil)
- c.Assert(s.fakeBackend.ops, HasLen, 1)
- c.Check(s.fakeBackend.ops[0], DeepEquals, fakeOp{
- op: "storesvc-list-refresh",
- cand: store.RefreshCandidate{
- SnapID: "some-snap-id",
- Revision: snap.R(7),
- Epoch: "",
- DevMode: true,
- Channel: "some-channel",
- },
- revno: snap.R(11),
+ _, err = snapstate.Update(s.state, "some-snap", "", snap.R(0), s.user.ID, snapstate.Flags{Classic: true})
+ c.Assert(err, IsNil)
+}
+
+func (s *snapmgrTestSuite) TestUpdateChannelFallback(c *C) {
+ s.state.Lock()
+ defer s.state.Unlock()
+
+ snapstate.Set(s.state, "some-snap", &snapstate.SnapState{
+ Active: true,
+ Channel: "edge",
+ Sequence: []*snap.SideInfo{{RealName: "some-snap", SnapID: "some-snap-id", Revision: snap.R(7)}},
+ Current: snap.R(7),
+ SnapType: "app",
})
+
+ ts, err := snapstate.Update(s.state, "some-snap", "", snap.R(0), s.user.ID, snapstate.Flags{})
+ c.Assert(err, IsNil)
+
+ var snapsup snapstate.SnapSetup
+ err = ts.Tasks()[0].Get("snap-setup", &snapsup)
+ c.Assert(err, IsNil)
+
+ c.Check(snapsup.Channel, Equals, "edge")
}
func (s *snapmgrTestSuite) TestUpdateConflict(c *C) {
@@ -992,7 +1125,6 @@ func (s *snapmgrTestSuite) TestUpdateRunThrough(c *C) {
SnapID: "some-snap-id",
Revision: snap.R(7),
Epoch: "",
- DevMode: false,
},
revno: snap.R(11),
},
@@ -1167,7 +1299,6 @@ func (s *snapmgrTestSuite) TestUpdateUndoRunThrough(c *C) {
SnapID: "some-snap-id",
Revision: snap.R(7),
Epoch: "",
- DevMode: false,
},
revno: snap.R(11),
},
@@ -1333,7 +1464,6 @@ func (s *snapmgrTestSuite) TestUpdateTotalUndoRunThrough(c *C) {
SnapID: "some-snap-id",
Revision: snap.R(7),
Epoch: "",
- DevMode: false,
},
revno: snap.R(11),
},
@@ -1593,7 +1723,6 @@ func (s *snapmgrTestSuite) TestSingleUpdateBlockedRevision(c *C) {
SnapID: "some-snap-id",
Revision: snap.R(7),
Epoch: "",
- DevMode: false,
Channel: "some-channel",
},
})
@@ -1633,7 +1762,6 @@ func (s *snapmgrTestSuite) TestMultiUpdateBlockedRevision(c *C) {
cand: store.RefreshCandidate{
SnapID: "some-snap-id",
Revision: snap.R(7),
- DevMode: false,
},
})
@@ -1671,7 +1799,6 @@ func (s *snapmgrTestSuite) TestAllUpdateBlockedRevision(c *C) {
cand: store.RefreshCandidate{
SnapID: "some-snap-id",
Revision: snap.R(7),
- DevMode: false,
Block: []snap.Revision{snap.R(11)},
},
})
Oops, something went wrong.

0 comments on commit 024cf1e

Please sign in to comment.