-
Notifications
You must be signed in to change notification settings - Fork 576
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: cleanup system actions supported by recover mode #8686
Changes from all commits
0955d89
11ae8eb
ac040e2
17bda66
c0a9eef
e2421c9
bf59e74
b0be1ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -337,8 +337,8 @@ func (s *deviceMgrSystemsSuite) TestRequestSameModeSameSystem(c *C) { | |
|
||
label := s.mockedSystemSeeds[0].label | ||
|
||
happyModes := []string{"run", "recover"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't we have just moved recover to sadModes, are we not testing that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, silly me. I'll restore the test. |
||
sadModes := []string{"install"} | ||
happyModes := []string{"run"} | ||
sadModes := []string{"install", "recover"} | ||
|
||
for _, mode := range append(happyModes, sadModes...) { | ||
c.Logf("checking mode: %q", mode) | ||
|
@@ -393,6 +393,24 @@ func (s *deviceMgrSystemsSuite) TestRequestNotYetSeeded(c *C) { | |
} | ||
} | ||
|
||
func (s *deviceMgrSystemsSuite) testRequestModeWithRestart(c *C, toModes []string, label string) { | ||
for _, mode := range toModes { | ||
c.Logf("checking mode: %q", mode) | ||
err := s.mgr.RequestSystemAction(label, | ||
devicestate.SystemAction{Mode: mode}) | ||
c.Assert(err, IsNil) | ||
m, err := s.bootloader.GetBootVars("snapd_recovery_mode", "snapd_recovery_system") | ||
c.Assert(err, IsNil) | ||
c.Check(m, DeepEquals, map[string]string{ | ||
"snapd_recovery_system": label, | ||
"snapd_recovery_mode": mode, | ||
}) | ||
c.Check(s.restartRequests, DeepEquals, []state.RestartType{state.RestartSystemNow}) | ||
s.restartRequests = nil | ||
s.bootloader.BootVars = map[string]string{} | ||
} | ||
} | ||
|
||
func (s *deviceMgrSystemsSuite) TestRequestModeRunInstallForRecover(c *C) { | ||
// we are in recover mode here | ||
devicestate.SetSystemMode(s.mgr, "recover") | ||
|
@@ -414,21 +432,7 @@ func (s *deviceMgrSystemsSuite) TestRequestModeRunInstallForRecover(c *C) { | |
}) | ||
s.state.Unlock() | ||
|
||
for _, mode := range []string{"install", "run"} { | ||
c.Logf("checking mode: %q", mode) | ||
err := s.mgr.RequestSystemAction(s.mockedSystemSeeds[0].label, | ||
devicestate.SystemAction{Mode: mode}) | ||
c.Assert(err, IsNil) | ||
m, err := s.bootloader.GetBootVars("snapd_recovery_mode", "snapd_recovery_system") | ||
c.Assert(err, IsNil) | ||
c.Check(m, DeepEquals, map[string]string{ | ||
"snapd_recovery_system": s.mockedSystemSeeds[0].label, | ||
"snapd_recovery_mode": mode, | ||
}) | ||
c.Check(s.restartRequests, DeepEquals, []state.RestartType{state.RestartSystemNow}) | ||
s.restartRequests = nil | ||
s.bootloader.BootVars = map[string]string{} | ||
} | ||
s.testRequestModeWithRestart(c, []string{"install", "run"}, s.mockedSystemSeeds[0].label) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice |
||
} | ||
|
||
func (s *deviceMgrSystemsSuite) TestRequestModeInstallRecoverForCurrent(c *C) { | ||
|
@@ -450,21 +454,7 @@ func (s *deviceMgrSystemsSuite) TestRequestModeInstallRecoverForCurrent(c *C) { | |
}) | ||
s.state.Unlock() | ||
|
||
for _, mode := range []string{"install", "recover"} { | ||
c.Logf("checking mode: %q", mode) | ||
err := s.mgr.RequestSystemAction(s.mockedSystemSeeds[0].label, | ||
devicestate.SystemAction{Mode: mode}) | ||
c.Assert(err, IsNil) | ||
m, err := s.bootloader.GetBootVars("snapd_recovery_mode", "snapd_recovery_system") | ||
c.Assert(err, IsNil) | ||
c.Check(m, DeepEquals, map[string]string{ | ||
"snapd_recovery_system": s.mockedSystemSeeds[0].label, | ||
"snapd_recovery_mode": mode, | ||
}) | ||
c.Check(s.restartRequests, DeepEquals, []state.RestartType{state.RestartSystemNow}) | ||
s.restartRequests = nil | ||
s.bootloader.BootVars = map[string]string{} | ||
} | ||
s.testRequestModeWithRestart(c, []string{"install", "recover"}, s.mockedSystemSeeds[0].label) | ||
} | ||
|
||
func (s *deviceMgrSystemsSuite) TestRequestModeErrInBoot(c *C) { | ||
|
@@ -523,3 +513,25 @@ func (s *deviceMgrSystemsSuite) TestRequestModeForNonCurrent(c *C) { | |
c.Assert(err, Equals, devicestate.ErrUnsupportedAction) | ||
c.Check(s.restartRequests, HasLen, 0) | ||
} | ||
|
||
func (s *deviceMgrSystemsSuite) TestRequestInstallForOther(c *C) { | ||
devicestate.SetSystemMode(s.mgr, "run") | ||
// non run modes use modeenv | ||
modeenv := boot.Modeenv{ | ||
Mode: "run", | ||
} | ||
err := modeenv.WriteTo("") | ||
c.Assert(err, IsNil) | ||
|
||
s.state.Lock() | ||
s.state.Set("seeded-systems", []devicestate.SeededSystem{ | ||
{ | ||
System: s.mockedSystemSeeds[0].label, | ||
Model: s.mockedSystemSeeds[0].model.Model(), | ||
BrandID: s.mockedSystemSeeds[0].brand.AccountID(), | ||
}, | ||
}) | ||
s.state.Unlock() | ||
// reinstall from different system seed is ok | ||
s.testRequestModeWithRestart(c, []string{"install"}, s.mockedSystemSeeds[1].label) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still feel this should actually be integrated back in systemFromSeed by passing all the needed info in, but can be done when moving it to systems.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, we'll do this after #8689 lands.