Пример #1
0
func (s *prepareSnapSuite) SetUpTest(c *C) {
	s.fakeBackend = &fakeSnappyBackend{}
	s.state = state.New(nil)

	var err error
	s.snapmgr, err = snapstate.Manager(s.state)
	c.Assert(err, IsNil)
	s.snapmgr.AddForeignTaskHandlers(s.fakeBackend)

	snapstate.SetSnapManagerBackend(s.snapmgr, s.fakeBackend)

	s.reset = snapstate.MockReadInfo(s.fakeBackend.ReadInfo)
}
Пример #2
0
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"] = "core_2.snap"
	bs.bootloader.BootVars["snap_kernel"] = "canonical-pc-linux_2.snap"
	partition.ForceBootloader(bs.bootloader)

	bs.fakeBackend = &fakeSnappyBackend{}
	bs.state = state.New(nil)
	bs.snapmgr, err = snapstate.Manager(bs.state)
	c.Assert(err, IsNil)
	bs.snapmgr.AddForeignTaskHandlers(bs.fakeBackend)

	snapstate.SetSnapManagerBackend(bs.snapmgr, bs.fakeBackend)
}
Пример #3
0
func (s *downloadSnapSuite) SetUpTest(c *C) {
	s.fakeBackend = &fakeSnappyBackend{}
	s.state = state.New(nil)
	s.state.Lock()
	defer s.state.Unlock()

	s.fakeStore = &fakeStore{
		state:       s.state,
		fakeBackend: s.fakeBackend,
	}
	snapstate.ReplaceStore(s.state, s.fakeStore)

	var err error
	s.snapmgr, err = snapstate.Manager(s.state)
	c.Assert(err, IsNil)
	s.snapmgr.AddForeignTaskHandlers(s.fakeBackend)

	snapstate.SetSnapManagerBackend(s.snapmgr, s.fakeBackend)

	s.reset = snapstate.MockReadInfo(s.fakeBackend.ReadInfo)
}
Пример #4
0
// 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
}