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

o/devicestate: raise conflict when requesting system action while seeding #8689

Merged
merged 14 commits into from May 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions overlord/devicestate/devicemgr.go
Expand Up @@ -818,6 +818,14 @@ var ErrUnsupportedAction = errors.New("unsupported action")
// system reboot will be requested when the request can be successfully carried
// out.
func (m *DeviceManager) RequestSystemAction(systemLabel string, action SystemAction) error {
if systemLabel == "" {
return fmt.Errorf("internal error: system label is unset")
}
if m.systemMode == "" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmh, we don't do this anywhere else, usually we use the grade unset of the model to know if we are on uc16/18. we need to think a bit.

// uc16/uc18 have no mode
return ErrUnsupportedAction
}

if err := checkSystemRequestConflict(m.state, systemLabel); err != nil {
return err
}
Expand Down
41 changes: 41 additions & 0 deletions overlord/devicestate/devicestate_systems_test.go
Expand Up @@ -549,6 +549,11 @@ func (s *deviceMgrSystemsSuite) TestRequestModeNonUC20(c *C) {
c.Check(s.restartRequests, HasLen, 0)
}

func (s *deviceMgrSystemsSuite) TestRequestActionNoLabel(c *C) {
err := s.mgr.RequestSystemAction("", devicestate.SystemAction{Mode: "install"})
c.Assert(err, ErrorMatches, "internal error: system label is unset")
}

func (s *deviceMgrSystemsSuite) TestRequestModeForNonCurrent(c *C) {
s.state.Lock()
s.state.Set("seeded-systems", []devicestate.SeededSystem{
Expand Down Expand Up @@ -590,3 +595,39 @@ func (s *deviceMgrSystemsSuite) TestRequestInstallForOther(c *C) {
// reinstall from different system seed is ok
s.testRequestModeWithRestart(c, []string{"install"}, s.mockedSystemSeeds[1].label)
}

func (s *deviceMgrSystemsSuite) TestRequestAction1618(c *C) {
s.setPCModelInState(c)
// system mode is unset in 16/18
devicestate.SetSystemMode(s.mgr, "")
// no modeenv either
err := os.Remove(dirs.SnapModeenvFileUnder(dirs.GlobalRootDir))
c.Assert(err, IsNil)

s.state.Lock()
s.state.Set("seeded-systems", nil)
s.state.Set("seeded", nil)
s.state.Unlock()
// a label exists
err = s.mgr.RequestSystemAction(s.mockedSystemSeeds[0].label, devicestate.SystemAction{Mode: "install"})
c.Assert(err, Equals, devicestate.ErrUnsupportedAction)

s.state.Lock()
s.state.Set("seeded", true)
s.state.Unlock()

// even with system mode explicitly set, the action is not executed
devicestate.SetSystemMode(s.mgr, "run")

err = s.mgr.RequestSystemAction(s.mockedSystemSeeds[0].label, devicestate.SystemAction{Mode: "install"})
c.Assert(err, ErrorMatches, "cannot set device to boot .*: system mode is unsupported")

devicestate.SetSystemMode(s.mgr, "")
// also no UC20 style system seeds
for _, m := range s.mockedSystemSeeds {
os.RemoveAll(filepath.Join(dirs.SnapSeedDir, "systems", m.label))
}

err = s.mgr.RequestSystemAction(s.mockedSystemSeeds[0].label, devicestate.SystemAction{Mode: "install"})
c.Assert(err, Equals, devicestate.ErrUnsupportedAction)
}