本文整理汇总了Golang中github.com/snapcore/snapd/overlord.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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{})
}
示例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
}
示例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)
}
示例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")
}
}
示例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)
}
示例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
}
示例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)
}
示例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)
}
示例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)
}
示例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")
}
示例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")
}
示例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)
}
示例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
}
示例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)
}
示例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
}