func (s *hookManagerSuite) SetUpTest(c *C) { dirs.SetRootDir(c.MkDir()) s.state = state.New(nil) manager, err := hookstate.Manager(s.state) c.Assert(err, IsNil) s.manager = manager s.state.Lock() s.task = hookstate.HookTask(s.state, "test summary", "test-snap", snap.R(1), "test-hook") c.Assert(s.task, NotNil, Commentf("Expected HookTask to return a task")) s.change = s.state.NewChange("kind", "summary") s.change.AddTask(s.task) s.state.Unlock() s.command = testutil.MockCommand(c, "snap", "") }
func (s *hookManagerSuite) SetUpTest(c *C) { dirs.SetRootDir(c.MkDir()) s.state = state.New(nil) manager, err := hookstate.Manager(s.state) c.Assert(err, IsNil) s.manager = manager hooksup := &hookstate.HookSetup{ Snap: "test-snap", Hook: "configure", Revision: snap.R(1), } initialContext := map[string]interface{}{ "test-key": "test-value", } s.state.Lock() s.task = hookstate.HookTask(s.state, "test summary", hooksup, initialContext) c.Assert(s.task, NotNil, Commentf("Expected HookTask to return a task")) s.change = s.state.NewChange("kind", "summary") s.change.AddTask(s.task) sideInfo := &snap.SideInfo{RealName: "test-snap", SnapID: "some-snap-id", Revision: snap.R(1)} snaptest.MockSnap(c, snapYaml, snapContents, sideInfo) snapstate.Set(s.state, "test-snap", &snapstate.SnapState{ Active: true, Sequence: []*snap.SideInfo{sideInfo}, Current: snap.R(1), }) s.state.Unlock() s.command = testutil.MockCommand(c, "snap", "") s.context = nil s.mockHandler = hooktest.NewMockHandler() s.manager.Register(regexp.MustCompile("configure"), func(context *hookstate.Context) hookstate.Handler { s.context = context return s.mockHandler }) }
func (s *deviceMgrSuite) SetUpTest(c *C) { dirs.SetRootDir(c.MkDir()) rootPrivKey, _ := assertstest.GenerateKey(1024) storePrivKey, _ := assertstest.GenerateKey(752) s.storeSigning = assertstest.NewStoreStack("canonical", rootPrivKey, storePrivKey) s.state = state.New(nil) db, err := asserts.OpenDatabase(&asserts.DatabaseConfig{ Backstore: asserts.NewMemoryBackstore(), Trusted: s.storeSigning.Trusted, }) c.Assert(err, IsNil) s.state.Lock() assertstate.ReplaceDB(s.state, db) s.state.Unlock() err = db.Add(s.storeSigning.StoreAccountKey("")) c.Assert(err, IsNil) hookMgr, err := hookstate.Manager(s.state) c.Assert(err, IsNil) mgr, err := devicestate.Manager(s.state, hookMgr) c.Assert(err, IsNil) s.db = db s.hookMgr = hookMgr s.mgr = mgr s.state.Lock() snapstate.ReplaceStore(s.state, &fakeStore{ state: s.state, db: s.storeSigning, }) s.state.Unlock() }
// New creates a new Overlord with all its state managers. func New() (*Overlord, error) { o := &Overlord{ loopTomb: new(tomb.Tomb), } backend := &overlordStateBackend{ path: dirs.SnapStateFile, ensureBefore: o.ensureBefore, requestRestart: o.requestRestart, } s, err := loadState(backend) if err != nil { return nil, err } o.stateEng = NewStateEngine(s) snapMgr, err := snapstate.Manager(s) if err != nil { return nil, err } o.snapMgr = snapMgr o.stateEng.AddManager(o.snapMgr) assertMgr, err := assertstate.Manager(s) if err != nil { return nil, err } o.assertMgr = assertMgr o.stateEng.AddManager(o.assertMgr) ifaceMgr, err := ifacestate.Manager(s, nil) if err != nil { return nil, err } o.ifaceMgr = ifaceMgr o.stateEng.AddManager(o.ifaceMgr) hookMgr, err := hookstate.Manager(s) if err != nil { return nil, err } o.hookMgr = hookMgr o.stateEng.AddManager(o.hookMgr) configMgr, err := configstate.Manager(s, hookMgr) if err != nil { return nil, err } o.configMgr = configMgr deviceMgr, err := devicestate.Manager(s) if err != nil { return nil, err } o.deviceMgr = deviceMgr o.stateEng.AddManager(o.deviceMgr) // setting up the store authContext := auth.NewAuthContext(s, o.deviceMgr) sto := storeNew(nil, authContext) s.Lock() snapstate.ReplaceStore(s, sto) s.Unlock() return o, nil }