Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overlord: merge overlord/boot pkg into overlord/devicestate #2118

Merged
merged 1 commit into from
Oct 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 0 additions & 24 deletions overlord/boot/export_test.go

This file was deleted.

5 changes: 2 additions & 3 deletions overlord/devicestate/devicemgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import (
"github.com/snapcore/snapd/logger"
"github.com/snapcore/snapd/overlord/assertstate"
"github.com/snapcore/snapd/overlord/auth"
"github.com/snapcore/snapd/overlord/boot"
"github.com/snapcore/snapd/overlord/configstate"
"github.com/snapcore/snapd/overlord/hookstate"
"github.com/snapcore/snapd/overlord/snapstate"
Expand Down Expand Up @@ -185,7 +184,7 @@ func (m *DeviceManager) ensureOperational() error {
return nil
}

var bootPopulateStateFromSeed = boot.PopulateStateFromSeed
var PopulateStateFromSeed = PopulateStateFromSeedImpl

// ensureSnaps makes sure that the snaps from seed.yaml get installed
// with the matching assertions
Expand Down Expand Up @@ -217,7 +216,7 @@ func (m *DeviceManager) ensureSeedYaml() error {
return nil
}

tsAll, err := bootPopulateStateFromSeed(m.state)
tsAll, err := PopulateStateFromSeed(m.state)
if err != nil {
return err
}
Expand Down
12 changes: 8 additions & 4 deletions overlord/devicestate/devicemgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,11 @@ func (s *deviceMgrSuite) TestDeviceManagerEnsureSeedYamlAlreadySeeded(c *C) {
s.state.Unlock()

called := false
devicestate.MockBootPopulateStateFromSeed(func(*state.State) ([]*state.TaskSet, error) {
restore := devicestate.MockPopulateStateFromSeed(func(*state.State) ([]*state.TaskSet, error) {
called = true
return nil, nil
})
defer restore()

err := s.mgr.EnsureSeedYaml()
c.Assert(err, IsNil)
Expand All @@ -780,10 +781,11 @@ func (s *deviceMgrSuite) TestDeviceManagerEnsureSeedYamlChangeInFlight(c *C) {
s.state.Unlock()

called := false
devicestate.MockBootPopulateStateFromSeed(func(*state.State) ([]*state.TaskSet, error) {
restore := devicestate.MockPopulateStateFromSeed(func(*state.State) ([]*state.TaskSet, error) {
called = true
return nil, nil
})
defer restore()

err := s.mgr.EnsureSeedYaml()
c.Assert(err, IsNil)
Expand All @@ -794,10 +796,11 @@ func (s *deviceMgrSuite) TestDeviceManagerEnsureSeedYamlSkippedOnClassic(c *C) {
release.OnClassic = true

called := false
devicestate.MockBootPopulateStateFromSeed(func(*state.State) ([]*state.TaskSet, error) {
restore := devicestate.MockPopulateStateFromSeed(func(*state.State) ([]*state.TaskSet, error) {
called = true
return nil, nil
})
defer restore()

err := s.mgr.EnsureSeedYaml()
c.Assert(err, IsNil)
Expand All @@ -807,11 +810,12 @@ func (s *deviceMgrSuite) TestDeviceManagerEnsureSeedYamlSkippedOnClassic(c *C) {
func (s *deviceMgrSuite) TestDeviceManagerEnsureSeedYamlHappy(c *C) {
release.OnClassic = false

devicestate.MockBootPopulateStateFromSeed(func(*state.State) (ts []*state.TaskSet, err error) {
restore := devicestate.MockPopulateStateFromSeed(func(*state.State) (ts []*state.TaskSet, err error) {
t := s.state.NewTask("test-task", "a random task")
ts = append(ts, state.NewTaskSet(t))
return ts, nil
})
defer restore()

err := s.mgr.EnsureSeedYaml()
c.Assert(err, IsNil)
Expand Down
10 changes: 6 additions & 4 deletions overlord/devicestate/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ func (m *DeviceManager) EnsureSeedYaml() error {
return m.ensureSeedYaml()
}

func MockBootPopulateStateFromSeed(f func(*state.State) ([]*state.TaskSet, error)) (restore func()) {
old := bootPopulateStateFromSeed
bootPopulateStateFromSeed = f
func MockPopulateStateFromSeed(f func(*state.State) ([]*state.TaskSet, error)) (restore func()) {
old := PopulateStateFromSeed
PopulateStateFromSeed = f
return func() {
bootPopulateStateFromSeed = old
PopulateStateFromSeed = old
}
}

Expand All @@ -89,3 +89,5 @@ func (m *DeviceManager) EnsureBootOk() error {
func (m *DeviceManager) SetBootOkRan(b bool) {
m.bootOkRan = b
}

var ImportAssertionsFromSeed = importAssertionsFromSeed
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
*/

package boot
package devicestate

import (
"fmt"
Expand All @@ -36,7 +36,7 @@ import (
"github.com/snapcore/snapd/snap"
)

func PopulateStateFromSeed(st *state.State) ([]*state.TaskSet, error) {
func PopulateStateFromSeedImpl(st *state.State) ([]*state.TaskSet, error) {
// check that the state is empty
var seeded bool
err := st.Get("seeded", &seeded)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
*
*/

package boot_test
package devicestate_test

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"testing"
"time"

. "gopkg.in/check.v1"
Expand All @@ -38,16 +37,14 @@ import (
"github.com/snapcore/snapd/overlord"
"github.com/snapcore/snapd/overlord/assertstate"
"github.com/snapcore/snapd/overlord/auth"
"github.com/snapcore/snapd/overlord/boot"
"github.com/snapcore/snapd/overlord/devicestate"
"github.com/snapcore/snapd/overlord/snapstate"
"github.com/snapcore/snapd/overlord/state"
"github.com/snapcore/snapd/snap"
"github.com/snapcore/snapd/snap/snaptest"
"github.com/snapcore/snapd/testutil"
)

func Test(t *testing.T) { TestingT(t) }

type FirstBootTestSuite struct {
systemctl *testutil.MockCmd
mockUdevAdm *testutil.MockCmd
Expand Down Expand Up @@ -110,7 +107,7 @@ func (s *FirstBootTestSuite) TestPopulateFromSeedErrorsOnState(c *C) {
defer st.Unlock()
st.Set("seeded", true)

_, err := boot.PopulateStateFromSeed(st)
_, err := devicestate.PopulateStateFromSeed(st)
c.Assert(err, ErrorMatches, "cannot populate state: already seeded")
}

Expand Down Expand Up @@ -191,7 +188,7 @@ snaps:
st := s.overlord.State()
st.Lock()
defer st.Unlock()
tsAll, err := boot.PopulateStateFromSeed(st)
tsAll, err := devicestate.PopulateStateFromSeed(st)
c.Assert(err, IsNil)

// the last task of the last taskset must be mark-seeded
Expand Down Expand Up @@ -358,7 +355,7 @@ snaps:
st.Lock()
defer st.Unlock()

tsAll, err := boot.PopulateStateFromSeed(st)
tsAll, err := devicestate.PopulateStateFromSeed(st)
chg := st.NewChange("run-it", "run the populate from seed changes")
for _, ts := range tsAll {
chg.AddAll(ts)
Expand Down Expand Up @@ -453,7 +450,7 @@ func (s *FirstBootTestSuite) TestImportAssertionsFromSeedHappy(c *C) {
st.Lock()
defer st.Unlock()

err = boot.ImportAssertionsFromSeed(st)
err = devicestate.ImportAssertionsFromSeed(st)
c.Assert(err, IsNil)

// verify that the model was added
Expand Down Expand Up @@ -491,7 +488,7 @@ func (s *FirstBootTestSuite) TestImportAssertionsFromSeedMissingSig(c *C) {

// try import and verify that its rejects because other assertions are
// missing
err := boot.ImportAssertionsFromSeed(st)
err := devicestate.ImportAssertionsFromSeed(st)
c.Assert(err, ErrorMatches, "cannot find account-key .*: assertion not found")
}

Expand All @@ -513,7 +510,7 @@ func (s *FirstBootTestSuite) TestImportAssertionsFromSeedTwoModelAsserts(c *C) {

// try import and verify that its rejects because other assertions are
// missing
err = boot.ImportAssertionsFromSeed(st)
err = devicestate.ImportAssertionsFromSeed(st)
c.Assert(err, ErrorMatches, "cannot add more than one model assertion")
}

Expand All @@ -534,6 +531,6 @@ func (s *FirstBootTestSuite) TestImportAssertionsFromSeedNoModelAsserts(c *C) {

// try import and verify that its rejects because other assertions are
// missing
err := boot.ImportAssertionsFromSeed(st)
err := devicestate.ImportAssertionsFromSeed(st)
c.Assert(err, ErrorMatches, "need a model assertion")
}