本文整理汇总了Golang中github.com/snapcore/snapd/overlord.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestNew
func (ovs *overlordSuite) TestNew(c *C) {
restore := patch.Mock(42, nil)
defer restore()
o, err := overlord.New()
c.Assert(err, IsNil)
c.Check(o, NotNil)
c.Check(o.SnapManager(), NotNil)
c.Check(o.AssertManager(), NotNil)
c.Check(o.InterfaceManager(), NotNil)
c.Check(o.DeviceManager(), NotNil)
s := o.State()
c.Check(s, NotNil)
c.Check(o.Engine().State(), Equals, s)
s.Lock()
defer s.Unlock()
var patchLevel int
s.Get("patch-level", &patchLevel)
c.Check(patchLevel, Equals, 42)
// store is setup
sto := snapstate.Store(s)
c.Check(sto, FitsTypeOf, &store.Store{})
}
开发者ID:niemeyer,项目名称:snapd,代码行数:27,代码来源:overlord_test.go
示例2: SetUpTest
func (ms *mgrsSuite) SetUpTest(c *C) {
ms.tempdir = c.MkDir()
dirs.SetRootDir(ms.tempdir)
err := os.MkdirAll(filepath.Dir(dirs.SnapStateFile), 0755)
c.Assert(err, IsNil)
os.Setenv("SNAPPY_SQUASHFS_UNPACK_FOR_TESTS", "1")
// create a fake systemd environment
os.MkdirAll(filepath.Join(dirs.SnapServicesDir, "multi-user.target.wants"), 0755)
ms.prevctlCmd = systemd.SystemctlCmd
systemd.SystemctlCmd = func(cmd ...string) ([]byte, error) {
return []byte("ActiveState=inactive\n"), nil
}
ms.aa = testutil.MockCommand(c, "apparmor_parser", "")
ms.udev = testutil.MockCommand(c, "udevadm", "")
ms.umount = testutil.MockCommand(c, "umount", "")
ms.snapDiscardNs = testutil.MockCommand(c, "snap-discard-ns", "")
dirs.LibExecDir = ms.snapDiscardNs.BinDir()
ms.storeSigning = assertstest.NewStoreStack("can0nical", rootPrivKey, storePrivKey)
ms.restoreTrusted = sysdb.InjectTrusted(ms.storeSigning.Trusted)
ms.devAcct = assertstest.NewAccount(ms.storeSigning, "devdevev", map[string]interface{}{
"account-id": "devdevdev",
}, "")
err = ms.storeSigning.Add(ms.devAcct)
c.Assert(err, IsNil)
o, err := overlord.New()
c.Assert(err, IsNil)
ms.o = o
}
开发者ID:clobrano,项目名称:snappy,代码行数:34,代码来源:managers_test.go
示例3: TestTrivialSettle
func (ovs *overlordSuite) TestTrivialSettle(c *C) {
restoreIntv := overlord.MockEnsureInterval(1 * time.Minute)
defer restoreIntv()
o, err := overlord.New()
c.Assert(err, IsNil)
se := o.Engine()
s := se.State()
rm1 := newRunnerManager(s)
se.AddManager(rm1)
defer o.Engine().Stop()
s.Lock()
defer s.Unlock()
chg := s.NewChange("chg", "...")
t1 := s.NewTask("runMgr1", "1...")
chg.AddTask(t1)
s.Unlock()
o.Settle()
s.Lock()
c.Check(t1.Status(), Equals, state.DoneStatus)
var v int
err = s.Get("runMgr1Mark", &v)
c.Check(err, IsNil)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:31,代码来源:overlord_test.go
示例4: TestEnsureBeforeSleepy
func (ovs *overlordSuite) TestEnsureBeforeSleepy(c *C) {
restoreIntv := overlord.MockEnsureInterval(10 * time.Minute)
defer restoreIntv()
o, err := overlord.New()
c.Assert(err, IsNil)
ensure := func(s *state.State) error {
overlord.MockEnsureNext(o, time.Now().Add(-10*time.Hour))
s.EnsureBefore(0)
return nil
}
witness := &witnessManager{
state: o.State(),
expectedEnsure: 2,
ensureCalled: make(chan struct{}),
ensureCallback: ensure,
}
se := o.Engine()
se.AddManager(witness)
o.Loop()
defer o.Stop()
select {
case <-witness.ensureCalled:
case <-time.After(2 * time.Second):
c.Fatal("Ensure calls not happening")
}
}
开发者ID:niemeyer,项目名称:snapd,代码行数:31,代码来源:overlord_test.go
示例5: TestEnsureLoopPrune
func (ovs *overlordSuite) TestEnsureLoopPrune(c *C) {
restoreIntv := overlord.MockPruneInterval(10*time.Millisecond, 5*time.Millisecond, 5*time.Millisecond)
defer restoreIntv()
o, err := overlord.New()
c.Assert(err, IsNil)
st := o.State()
st.Lock()
t1 := st.NewTask("foo", "...")
chg1 := st.NewChange("abort", "...")
chg1.AddTask(t1)
chg2 := st.NewChange("prune", "...")
chg2.SetStatus(state.DoneStatus)
st.Unlock()
o.Loop()
time.Sleep(50 * time.Millisecond)
err = o.Stop()
c.Assert(err, IsNil)
st.Lock()
defer st.Unlock()
c.Assert(st.Change(chg1.ID()), Equals, chg1)
c.Assert(st.Change(chg2.ID()), IsNil)
c.Assert(t1.Status(), Equals, state.HoldStatus)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:28,代码来源:overlord_test.go
示例6: SetUpTest
func (s *FirstBootTestSuite) SetUpTest(c *C) {
tempdir := c.MkDir()
dirs.SetRootDir(tempdir)
// mock the world!
err := os.MkdirAll(filepath.Join(dirs.SnapSeedDir, "snaps"), 0755)
c.Assert(err, IsNil)
err = os.MkdirAll(filepath.Join(dirs.SnapSeedDir, "assertions"), 0755)
c.Assert(err, IsNil)
err = os.MkdirAll(dirs.SnapServicesDir, 0755)
c.Assert(err, IsNil)
os.Setenv("SNAPPY_SQUASHFS_UNPACK_FOR_TESTS", "1")
s.systemctl = testutil.MockCommand(c, "systemctl", "")
s.mockUdevAdm = testutil.MockCommand(c, "udevadm", "")
err = ioutil.WriteFile(filepath.Join(dirs.SnapSeedDir, "seed.yaml"), nil, 0644)
c.Assert(err, IsNil)
rootPrivKey, _ := assertstest.GenerateKey(1024)
storePrivKey, _ := assertstest.GenerateKey(752)
s.storeSigning = assertstest.NewStoreStack("can0nical", rootPrivKey, storePrivKey)
s.restore = sysdb.InjectTrusted(s.storeSigning.Trusted)
s.brandPrivKey, _ = assertstest.GenerateKey(752)
s.brandSigning = assertstest.NewSigningDB("my-brand", s.brandPrivKey)
ovld, err := overlord.New()
c.Assert(err, IsNil)
s.overlord = ovld
}
开发者ID:pedronis,项目名称:snappy,代码行数:31,代码来源:firstboot_test.go
示例7: TestEnsureLoopRunAndStop
func (ovs *overlordSuite) TestEnsureLoopRunAndStop(c *C) {
restoreIntv := overlord.MockEnsureInterval(10 * time.Millisecond)
defer restoreIntv()
o, err := overlord.New()
c.Assert(err, IsNil)
witness := &witnessManager{
state: o.State(),
expectedEnsure: 3,
ensureCalled: make(chan struct{}),
}
o.Engine().AddManager(witness)
o.Loop()
defer o.Stop()
t0 := time.Now()
select {
case <-witness.ensureCalled:
case <-time.After(2 * time.Second):
c.Fatal("Ensure calls not happening")
}
c.Check(time.Since(t0) >= 10*time.Millisecond, Equals, true)
err = o.Stop()
c.Assert(err, IsNil)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:27,代码来源:overlord_test.go
示例8: TestNewWithPatches
func (ovs *overlordSuite) TestNewWithPatches(c *C) {
p := func(s *state.State) error {
s.Set("patched", true)
return nil
}
patch.Mock(1, map[int]func(*state.State) error{1: p})
fakeState := []byte(fmt.Sprintf(`{"data":{"patch-level":0}}`))
err := ioutil.WriteFile(dirs.SnapStateFile, fakeState, 0600)
c.Assert(err, IsNil)
o, err := overlord.New()
c.Assert(err, IsNil)
state := o.State()
c.Assert(err, IsNil)
state.Lock()
defer state.Unlock()
var level int
err = state.Get("patch-level", &level)
c.Assert(err, IsNil)
c.Check(level, Equals, 1)
var b bool
err = state.Get("patched", &b)
c.Assert(err, IsNil)
c.Check(b, Equals, true)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:29,代码来源:overlord_test.go
示例9: Execute
func (x *cmdBooted) Execute(args []string) error {
if len(args) > 0 {
return ErrExtraArgs
}
if release.OnClassic {
fmt.Fprintf(Stdout, i18n.G("Ignoring 'booted' on classic"))
return nil
}
bootloader, err := partition.FindBootloader()
if err != nil {
return fmt.Errorf(i18n.G("cannot mark boot successful: %s"), err)
}
if err := partition.MarkBootSuccessful(bootloader); err != nil {
return err
}
ovld, err := overlord.New()
if err != nil {
return err
}
return boot.UpdateRevisions(ovld)
}
开发者ID:clobrano,项目名称:snappy,代码行数:25,代码来源:cmd_booted.go
示例10: TestImportAssertionsFromSeedHappy
func (s *FirstBootTestSuite) TestImportAssertionsFromSeedHappy(c *C) {
ovld, err := overlord.New()
c.Assert(err, IsNil)
st := ovld.State()
// add a bunch of assert files
assertsChain := s.makeModelAssertionChain(c)
for i, as := range assertsChain {
fn := filepath.Join(dirs.SnapSeedDir, "assertions", strconv.Itoa(i))
err := ioutil.WriteFile(fn, asserts.Encode(as), 0644)
c.Assert(err, IsNil)
}
// import them
err = boot.ImportAssertionsFromSeed(st)
c.Assert(err, IsNil)
// verify that the model was added
st.Lock()
defer st.Unlock()
db := assertstate.DB(st)
as, err := db.Find(asserts.ModelType, map[string]string{
"series": "16",
"brand-id": "my-brand",
"model": "my-model",
})
c.Assert(err, IsNil)
_, ok := as.(*asserts.Model)
c.Check(ok, Equals, true)
ds, err := auth.Device(st)
c.Assert(err, IsNil)
c.Check(ds.Brand, Equals, "my-brand")
c.Check(ds.Model, Equals, "my-model")
}
开发者ID:clobrano,项目名称:snappy,代码行数:35,代码来源:firstboot_test.go
示例11: TestNewWithInvalidState
func (ovs *overlordSuite) TestNewWithInvalidState(c *C) {
fakeState := []byte(``)
err := ioutil.WriteFile(dirs.SnapStateFile, fakeState, 0600)
c.Assert(err, IsNil)
_, err = overlord.New()
c.Assert(err, ErrorMatches, "EOF")
}
开发者ID:niemeyer,项目名称:snapd,代码行数:8,代码来源:overlord_test.go
示例12: TestTrivialRunAndStop
func (ovs *overlordSuite) TestTrivialRunAndStop(c *C) {
o, err := overlord.New()
c.Assert(err, IsNil)
o.Loop()
err = o.Stop()
c.Assert(err, IsNil)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:9,代码来源:overlord_test.go
示例13: New
// New Daemon
func New() (*Daemon, error) {
ovld, err := overlord.New()
if err != nil {
return nil, err
}
return &Daemon{
overlord: ovld,
// TODO: Decide when this should be disabled by default.
enableInternalInterfaceActions: true,
}, nil
}
开发者ID:pedronis,项目名称:snappy,代码行数:12,代码来源:daemon.go
示例14: TestRequestRestartHandler
func (ovs *overlordSuite) TestRequestRestartHandler(c *C) {
o, err := overlord.New()
c.Assert(err, IsNil)
restartRequested := false
o.SetRestartHandler(func(t state.RestartType) {
restartRequested = true
})
o.State().RequestRestart(state.RestartDaemon)
c.Check(restartRequested, Equals, true)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:14,代码来源:overlord_test.go
示例15: SetUpTest
func (bs *bootedSuite) SetUpTest(c *C) {
dirs.SetRootDir(c.MkDir())
err := os.MkdirAll(filepath.Dir(dirs.SnapStateFile), 0755)
c.Assert(err, IsNil)
// booted is not running on classic
release.MockOnClassic(false)
bs.bootloader = boottest.NewMockBootloader("mock", c.MkDir())
bs.bootloader.BootVars["snap_core"] = "ubuntu-core_2.snap"
bs.bootloader.BootVars["snap_kernel"] = "canonical-pc-linux_2.snap"
partition.ForceBootloader(bs.bootloader)
ovld, err := overlord.New()
c.Assert(err, IsNil)
bs.overlord = ovld
}
开发者ID:clobrano,项目名称:snappy,代码行数:17,代码来源:booted_test.go
示例16: TestCheckpoint
func (ovs *overlordSuite) TestCheckpoint(c *C) {
oldUmask := syscall.Umask(0)
defer syscall.Umask(oldUmask)
o, err := overlord.New()
c.Assert(err, IsNil)
s := o.State()
s.Lock()
s.Set("mark", 1)
s.Unlock()
st, err := os.Stat(dirs.SnapStateFile)
c.Assert(err, IsNil)
c.Assert(st.Mode(), Equals, os.FileMode(0600))
content, err := ioutil.ReadFile(dirs.SnapStateFile)
c.Assert(err, IsNil)
c.Check(string(content), testutil.Contains, `"mark":1`)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:20,代码来源:overlord_test.go
示例17: TestImportAssertionsFromSeedNoModelAsserts
func (s *FirstBootTestSuite) TestImportAssertionsFromSeedNoModelAsserts(c *C) {
ovld, err := overlord.New()
c.Assert(err, IsNil)
st := ovld.State()
assertsChain := s.makeModelAssertionChain(c)
for _, as := range assertsChain {
if as.Type() != asserts.ModelType {
fn := filepath.Join(dirs.SnapSeedDir, "assertions", "model")
err := ioutil.WriteFile(fn, asserts.Encode(as), 0644)
c.Assert(err, IsNil)
break
}
}
// try import and verify that its rejects because other assertions are
// missing
err = boot.ImportAssertionsFromSeed(st)
c.Assert(err, ErrorMatches, "need a model assertion")
}
开发者ID:clobrano,项目名称:snappy,代码行数:20,代码来源:firstboot_test.go
示例18: TestImportAssertionsFromSeedTwoModelAsserts
func (s *FirstBootTestSuite) TestImportAssertionsFromSeedTwoModelAsserts(c *C) {
ovld, err := overlord.New()
c.Assert(err, IsNil)
st := ovld.State()
// write out two model assertions
model := s.makeModelAssertion(c, "my-model")
fn := filepath.Join(dirs.SnapSeedDir, "assertions", "model")
err = ioutil.WriteFile(fn, asserts.Encode(model), 0644)
c.Assert(err, IsNil)
model2 := s.makeModelAssertion(c, "my-second-model")
fn = filepath.Join(dirs.SnapSeedDir, "assertions", "model2")
err = ioutil.WriteFile(fn, asserts.Encode(model2), 0644)
c.Assert(err, IsNil)
// try import and verify that its rejects because other assertions are
// missing
err = boot.ImportAssertionsFromSeed(st)
c.Assert(err, ErrorMatches, "cannot add more than one model assertion")
}
开发者ID:clobrano,项目名称:snappy,代码行数:21,代码来源:firstboot_test.go
示例19: TestSettleExplicitEnsureBefore
func (ovs *overlordSuite) TestSettleExplicitEnsureBefore(c *C) {
restoreIntv := overlord.MockEnsureInterval(1 * time.Minute)
defer restoreIntv()
o, err := overlord.New()
c.Assert(err, IsNil)
se := o.Engine()
s := se.State()
rm1 := newRunnerManager(s)
rm1.ensureCallback = func() {
s.Lock()
defer s.Unlock()
v := 0
s.Get("ensureCount", &v)
s.Set("ensureCount", v+1)
}
se.AddManager(rm1)
defer o.Engine().Stop()
s.Lock()
defer s.Unlock()
chg := s.NewChange("chg", "...")
t := s.NewTask("runMgrEnsureBefore", "...")
chg.AddTask(t)
s.Unlock()
o.Settle()
s.Lock()
c.Check(t.Status(), Equals, state.DoneStatus)
var v int
err = s.Get("ensureCount", &v)
c.Check(err, IsNil)
c.Check(v, Equals, 2)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:39,代码来源:overlord_test.go
示例20: TestNewWithGoodState
func (ovs *overlordSuite) TestNewWithGoodState(c *C) {
fakeState := []byte(fmt.Sprintf(`{"data":{"patch-level":%d,"some":"data"},"changes":null,"tasks":null,"last-change-id":0,"last-task-id":0}`, patch.Level))
err := ioutil.WriteFile(dirs.SnapStateFile, fakeState, 0600)
c.Assert(err, IsNil)
o, err := overlord.New()
c.Assert(err, IsNil)
state := o.State()
c.Assert(err, IsNil)
state.Lock()
defer state.Unlock()
d, err := state.MarshalJSON()
c.Assert(err, IsNil)
var got, expected map[string]interface{}
err = json.Unmarshal(d, &got)
c.Assert(err, IsNil)
err = json.Unmarshal(fakeState, &expected)
c.Assert(err, IsNil)
c.Check(got, DeepEquals, expected)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:24,代码来源:overlord_test.go
注:本文中的github.com/snapcore/snapd/overlord.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论