本文整理汇总了Golang中github.com/snapcore/snapd/overlord/snapstate.Set函数的典型用法代码示例。如果您正苦于以下问题:Golang Set函数的具体用法?Golang Set怎么用?Golang Set使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Set函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestAliasSnapCommandSpaceConflict
func (s *snapmgrTestSuite) TestAliasSnapCommandSpaceConflict(c *C) {
s.state.Lock()
defer s.state.Unlock()
snapstate.Set(s.state, "alias-snap", &snapstate.SnapState{
Sequence: []*snap.SideInfo{
{RealName: "alias-snap", Revision: snap.R(11)},
},
Current: snap.R(11),
Active: true,
})
// the command namespace of this one will conflict
snapstate.Set(s.state, "alias1", &snapstate.SnapState{
Sequence: []*snap.SideInfo{
{RealName: "alias1", Revision: snap.R(3)},
},
Current: snap.R(3),
})
chg := s.state.NewChange("alias", "enable an alias")
ts, err := snapstate.Alias(s.state, "alias-snap", []string{"alias1.cmd1"})
c.Assert(err, IsNil)
chg.AddAll(ts)
s.state.Unlock()
s.snapmgr.Ensure()
s.snapmgr.Wait()
s.state.Lock()
c.Check(chg.Status(), Equals, state.ErrorStatus)
c.Check(chg.Err(), ErrorMatches, `(?s).*cannot enable alias "alias1.cmd1" for "alias-snap", it conflicts with the command namespace of installed snap "alias1".*`)
}
示例2: TestAliasNoAlias
func (s *snapmgrTestSuite) TestAliasNoAlias(c *C) {
s.state.Lock()
defer s.state.Unlock()
snapstate.Set(s.state, "some-snap", &snapstate.SnapState{
Sequence: []*snap.SideInfo{
{RealName: "some-snap", Revision: snap.R(11)},
},
Current: snap.R(11),
Active: true,
})
chg := s.state.NewChange("alias", "enable an alias")
ts, err := snapstate.Alias(s.state, "some-snap", []string{"alias1"})
c.Assert(err, IsNil)
chg.AddAll(ts)
s.state.Unlock()
s.snapmgr.Ensure()
s.snapmgr.Wait()
s.state.Lock()
c.Check(chg.Status(), Equals, state.ErrorStatus)
c.Check(chg.Err(), ErrorMatches, `(?s).*cannot enable alias "alias1" for "some-snap", no such alias.*`)
}
示例3: TestDoDiscardSnapErrorsForActive
func (s *discardSnapSuite) TestDoDiscardSnapErrorsForActive(c *C) {
s.state.Lock()
snapstate.Set(s.state, "foo", &snapstate.SnapState{
Sequence: []*snap.SideInfo{
{RealName: "foo", Revision: snap.R(3)},
},
Current: snap.R(3),
Active: true,
SnapType: "app",
})
t := s.state.NewTask("discard-snap", "test")
t.Set("snap-setup", &snapstate.SnapSetup{
SideInfo: &snap.SideInfo{
RealName: "foo",
Revision: snap.R(3),
},
})
chg := s.state.NewChange("dummy", "...")
chg.AddTask(t)
s.state.Unlock()
s.snapmgr.Ensure()
s.snapmgr.Wait()
s.state.Lock()
defer s.state.Unlock()
c.Check(chg.Status(), Equals, state.ErrorStatus)
c.Check(chg.Err(), ErrorMatches, `(?s).*internal error: cannot discard snap "foo": still active.*`)
}
示例4: TestUpdateBootRevisionsOSErrorsLate
func (bs *bootedSuite) TestUpdateBootRevisionsOSErrorsLate(c *C) {
st := bs.state
st.Lock()
defer st.Unlock()
// put core into the state but add no files on disk
// will break in the tasks
snapstate.Set(st, "core", &snapstate.SnapState{
SnapType: "os",
Active: true,
Sequence: []*snap.SideInfo{osSI1, osSI2},
Current: snap.R(2),
})
bs.fakeBackend.linkSnapFailTrigger = filepath.Join(dirs.SnapMountDir, "/core/1")
bs.bootloader.BootVars["snap_kernel"] = "core_1.snap"
err := snapstate.UpdateBootRevisions(st)
c.Assert(err, IsNil)
st.Unlock()
bs.settle()
st.Lock()
c.Assert(st.Changes(), HasLen, 1)
chg := st.Changes()[0]
c.Assert(chg.Kind(), Equals, "update-revisions")
c.Assert(chg.IsReady(), Equals, true)
c.Assert(chg.Err(), ErrorMatches, `(?ms).*Make snap "core" \(1\) available to the system \(fail\).*`)
}
示例5: TestAliasAutoAliasConflict
func (s *snapmgrTestSuite) TestAliasAutoAliasConflict(c *C) {
s.state.Lock()
defer s.state.Unlock()
snapstate.Set(s.state, "alias-snap", &snapstate.SnapState{
Sequence: []*snap.SideInfo{
{RealName: "alias-snap", Revision: snap.R(11)},
},
Current: snap.R(11),
Active: true,
})
s.state.Set("aliases", map[string]map[string]string{
"other-snap": {"alias1": "auto"},
})
chg := s.state.NewChange("alias", "enable an alias")
ts, err := snapstate.Alias(s.state, "alias-snap", []string{"alias1"})
c.Assert(err, IsNil)
chg.AddAll(ts)
s.state.Unlock()
s.snapmgr.Ensure()
s.snapmgr.Wait()
s.state.Lock()
c.Check(chg.Status(), Equals, state.ErrorStatus)
c.Check(chg.Err(), ErrorMatches, `(?s).*cannot enable alias "alias1" for "alias-snap", already enabled for "other-snap".*`)
}
示例6: mockSnap
func (s *interfaceManagerSuite) mockSnap(c *C, yamlText string) *snap.Info {
sideInfo := &snap.SideInfo{
Revision: snap.R(1),
}
snapInfo := snaptest.MockSnap(c, yamlText, "", sideInfo)
sideInfo.RealName = snapInfo.Name()
a, err := s.db.FindMany(asserts.SnapDeclarationType, map[string]string{
"snap-name": sideInfo.RealName,
})
if err == nil {
decl := a[0].(*asserts.SnapDeclaration)
snapInfo.SnapID = decl.SnapID()
sideInfo.SnapID = decl.SnapID()
} else if err == asserts.ErrNotFound {
err = nil
}
c.Assert(err, IsNil)
s.state.Lock()
defer s.state.Unlock()
// Put a side info into the state
snapstate.Set(s.state, snapInfo.Name(), &snapstate.SnapState{
Active: true,
Sequence: []*snap.SideInfo{sideInfo},
Current: sideInfo.Revision,
})
return snapInfo
}
示例7: TestDoDiscardSnapToEmpty
func (s *discardSnapSuite) TestDoDiscardSnapToEmpty(c *C) {
s.state.Lock()
snapstate.Set(s.state, "foo", &snapstate.SnapState{
Sequence: []*snap.SideInfo{
{RealName: "foo", Revision: snap.R(3)},
},
Current: snap.R(3),
SnapType: "app",
})
t := s.state.NewTask("discard-snap", "test")
t.Set("snap-setup", &snapstate.SnapSetup{
SideInfo: &snap.SideInfo{
RealName: "foo",
Revision: snap.R(33),
},
})
s.state.NewChange("dummy", "...").AddTask(t)
s.state.Unlock()
s.snapmgr.Ensure()
s.snapmgr.Wait()
s.state.Lock()
defer s.state.Unlock()
var snapst snapstate.SnapState
err := snapstate.Get(s.state, "foo", &snapst)
c.Assert(err, Equals, state.ErrNoState)
}
示例8: TestDoUndoMountSnap
func (s *mountSnapSuite) TestDoUndoMountSnap(c *C) {
v1 := "name: core\nversion: 1.0\n"
testSnap := snaptest.MakeTestSnapWithFiles(c, v1, nil)
s.state.Lock()
defer s.state.Unlock()
si1 := &snap.SideInfo{
RealName: "core",
Revision: snap.R(1),
}
si2 := &snap.SideInfo{
RealName: "core",
Revision: snap.R(2),
}
snapstate.Set(s.state, "core", &snapstate.SnapState{
Sequence: []*snap.SideInfo{si1},
Current: si1.Revision,
SnapType: "os",
})
t := s.state.NewTask("mount-snap", "test")
t.Set("snap-setup", &snapstate.SnapSetup{
SideInfo: si2,
SnapPath: testSnap,
})
chg := s.state.NewChange("dummy", "...")
chg.AddTask(t)
terr := s.state.NewTask("error-trigger", "provoking total undo")
terr.WaitFor(t)
chg.AddTask(terr)
s.state.Unlock()
for i := 0; i < 3; i++ {
s.snapmgr.Ensure()
s.snapmgr.Wait()
}
s.state.Lock()
// ensure undo was called the right way
c.Check(s.fakeBackend.ops, DeepEquals, fakeOps{
{
op: "current",
old: "/snap/core/1",
},
{
op: "setup-snap",
name: testSnap,
revno: snap.R(2),
},
{
op: "undo-setup-snap",
name: "/snap/core/2",
stype: "os",
},
})
}
示例9: mockSnap
func (s *apiSuite) mockSnap(c *C, yamlText string) *snap.Info {
if s.d == nil {
panic("call s.daemon(c) in your test first")
}
snapInfo := snaptest.MockSnap(c, yamlText, &snap.SideInfo{Revision: snap.R(1)})
snap.AddImplicitSlots(snapInfo)
st := s.d.overlord.State()
st.Lock()
defer st.Unlock()
// Put a side info into the state
snapstate.Set(st, snapInfo.Name(), &snapstate.SnapState{
Active: true,
Sequence: []*snap.SideInfo{
{
RealName: snapInfo.Name(),
Revision: snapInfo.Revision,
SnapID: "ididid",
},
},
Current: snapInfo.Revision,
})
// Put the snap into the interface repository
repo := s.d.overlord.InterfaceManager().Repository()
err := repo.AddSnap(snapInfo)
c.Assert(err, IsNil)
return snapInfo
}
示例10: TestDoUndoSetAutoAliases
func (s *snapmgrTestSuite) TestDoUndoSetAutoAliases(c *C) {
s.state.Lock()
defer s.state.Unlock()
snapstate.AutoAliases = func(st *state.State, info *snap.Info) ([]string, error) {
c.Check(info.Name(), Equals, "alias-snap")
return []string{"alias1", "alias2", "alias4", "alias5"}, nil
}
snapstate.Set(s.state, "alias-snap", &snapstate.SnapState{
Sequence: []*snap.SideInfo{
{RealName: "alias-snap", Revision: snap.R(11)},
},
Current: snap.R(11),
Active: true,
})
s.state.Set("aliases", map[string]map[string]string{
"alias-snap": {
"alias1": "enabled",
"alias2": "auto",
"alias3": "auto",
"alias5": "disabled",
},
})
t := s.state.NewTask("set-auto-aliases", "test")
t.Set("snap-setup", &snapstate.SnapSetup{
SideInfo: &snap.SideInfo{RealName: "alias-snap"},
})
chg := s.state.NewChange("dummy", "...")
chg.AddTask(t)
terr := s.state.NewTask("error-trigger", "provoking total undo")
terr.WaitFor(t)
chg.AddTask(terr)
s.state.Unlock()
for i := 0; i < 3; i++ {
s.snapmgr.Ensure()
s.snapmgr.Wait()
}
s.state.Lock()
c.Check(t.Status(), Equals, state.UndoneStatus, Commentf("%v", chg.Err()))
var allAliases map[string]map[string]string
err := s.state.Get("aliases", &allAliases)
c.Assert(err, IsNil)
c.Check(allAliases, DeepEquals, map[string]map[string]string{
"alias-snap": {
"alias1": "enabled",
"alias2": "auto",
"alias3": "auto",
"alias5": "disabled",
},
})
}
示例11: TestDeviceManagerEnsureBootOkUpdateBootRevisionsHappy
func (s *deviceMgrSuite) TestDeviceManagerEnsureBootOkUpdateBootRevisionsHappy(c *C) {
release.OnClassic = false
bootloader := boottest.NewMockBootloader("mock", c.MkDir())
partition.ForceBootloader(bootloader)
defer partition.ForceBootloader(nil)
// simulate that we have a new core_2, tried to boot it but that failed
bootloader.SetBootVars(map[string]string{
"snap_mode": "",
"snap_try_core": "core_2.snap",
"snap_core": "core_1.snap",
})
s.state.Lock()
defer s.state.Unlock()
siCore1 := &snap.SideInfo{RealName: "core", Revision: snap.R(1)}
siCore2 := &snap.SideInfo{RealName: "core", Revision: snap.R(2)}
snapstate.Set(s.state, "core", &snapstate.SnapState{
SnapType: "os",
Active: true,
Sequence: []*snap.SideInfo{siCore1, siCore2},
Current: siCore2.Revision,
})
s.state.Unlock()
err := s.mgr.EnsureBootOk()
s.state.Lock()
c.Assert(err, IsNil)
c.Check(s.state.Changes(), HasLen, 1)
c.Check(s.state.Changes()[0].Kind(), Equals, "update-revisions")
}
示例12: TestDeviceManagerEnsureBootOkBootloaderHappy
func (s *deviceMgrSuite) TestDeviceManagerEnsureBootOkBootloaderHappy(c *C) {
release.OnClassic = false
bootloader := boottest.NewMockBootloader("mock", c.MkDir())
partition.ForceBootloader(bootloader)
defer partition.ForceBootloader(nil)
bootloader.SetBootVars(map[string]string{
"snap_mode": "trying",
"snap_try_core": "core_1.snap",
})
s.state.Lock()
defer s.state.Unlock()
siCore1 := &snap.SideInfo{RealName: "core", Revision: snap.R(1)}
snapstate.Set(s.state, "core", &snapstate.SnapState{
SnapType: "os",
Active: true,
Sequence: []*snap.SideInfo{siCore1},
Current: siCore1.Revision,
})
s.state.Unlock()
err := s.mgr.EnsureBootOk()
s.state.Lock()
c.Assert(err, IsNil)
m, err := bootloader.GetBootVars("snap_mode")
c.Assert(err, IsNil)
c.Assert(m, DeepEquals, map[string]string{"snap_mode": ""})
}
示例13: TestDoUndoSetupAliases
func (s *snapmgrTestSuite) TestDoUndoSetupAliases(c *C) {
s.state.Lock()
defer s.state.Unlock()
snapstate.Set(s.state, "alias-snap", &snapstate.SnapState{
Sequence: []*snap.SideInfo{
{RealName: "alias-snap", Revision: snap.R(11)},
},
Current: snap.R(11),
Active: true,
})
s.state.Set("aliases", map[string]map[string]string{
"alias-snap": {
"alias1": "enabled",
},
})
t := s.state.NewTask("setup-aliases", "test")
t.Set("snap-setup", &snapstate.SnapSetup{
SideInfo: &snap.SideInfo{RealName: "alias-snap"},
})
chg := s.state.NewChange("dummy", "...")
chg.AddTask(t)
terr := s.state.NewTask("error-trigger", "provoking total undo")
terr.WaitFor(t)
chg.AddTask(terr)
s.state.Unlock()
for i := 0; i < 3; i++ {
s.snapmgr.Ensure()
s.snapmgr.Wait()
}
s.state.Lock()
c.Check(t.Status(), Equals, state.UndoneStatus)
expected := fakeOps{
{
op: "update-aliases",
aliases: []*backend.Alias{{"alias1", "alias-snap.cmd1"}},
},
{
op: "matching-aliases",
aliases: []*backend.Alias{{"alias1", "alias-snap.cmd1"}},
},
{
op: "update-aliases",
rmAliases: []*backend.Alias{{"alias1", "alias-snap.cmd1"}},
},
}
// start with an easier-to-read error if this fails:
c.Assert(s.fakeBackend.ops.Ops(), DeepEquals, expected.Ops())
c.Assert(s.fakeBackend.ops, DeepEquals, expected)
}
示例14: TestAutoAliasesDeltaAll
func (s *snapmgrTestSuite) TestAutoAliasesDeltaAll(c *C) {
seen := make(map[string]bool)
snapstate.AutoAliases = func(st *state.State, info *snap.Info) ([]string, error) {
seen[info.Name()] = true
if info.Name() == "alias-snap" {
return []string{"alias1", "alias2", "alias4", "alias5"}, nil
}
return nil, nil
}
s.state.Lock()
defer s.state.Unlock()
snapstate.Set(s.state, "alias-snap", &snapstate.SnapState{
Sequence: []*snap.SideInfo{
{RealName: "alias-snap", Revision: snap.R(11)},
},
Current: snap.R(11),
Active: true,
})
snapstate.Set(s.state, "other-snap", &snapstate.SnapState{
Sequence: []*snap.SideInfo{
{RealName: "other-snap", Revision: snap.R(2)},
},
Current: snap.R(2),
Active: true,
})
new, retired, err := snapstate.AutoAliasesDelta(s.state, nil)
c.Assert(err, IsNil)
c.Check(new, DeepEquals, map[string][]string{
"alias-snap": {"alias1", "alias2", "alias4", "alias5"},
})
c.Check(retired, HasLen, 0)
c.Check(seen, DeepEquals, map[string]bool{
"alias-snap": true,
"other-snap": true,
})
}
示例15: makeInstalledKernelOS
func (bs *bootedSuite) makeInstalledKernelOS(c *C, st *state.State) {
snaptest.MockSnap(c, "name: core\ntype: os\nversion: 1", osSI1)
snaptest.MockSnap(c, "name: core\ntype: os\nversion: 2", osSI2)
snapstate.Set(st, "core", &snapstate.SnapState{
SnapType: "os",
Active: true,
Sequence: []*snap.SideInfo{osSI1, osSI2},
Current: snap.R(2),
})
snaptest.MockSnap(c, "name: canonical-pc-linux\ntype: os\nversion: 1", kernelSI1)
snaptest.MockSnap(c, "name: canonical-pc-linux\ntype: os\nversion: 2", kernelSI2)
snapstate.Set(st, "canonical-pc-linux", &snapstate.SnapState{
SnapType: "kernel",
Active: true,
Sequence: []*snap.SideInfo{kernelSI1, kernelSI2},
Current: snap.R(2),
})
}