-
Notifications
You must be signed in to change notification settings - Fork 56
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
Merge snapcore/snapd/state changes #259
Changes from all commits
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 |
---|---|---|
|
@@ -385,6 +385,10 @@ func (d *Daemon) Init() error { | |
return nil | ||
} | ||
|
||
func (d *Daemon) Overlord() *overlord.Overlord { | ||
return d.overlord | ||
} | ||
|
||
Comment on lines
+388
to
+391
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. Currently, I think we should either stick to the earlier scheme, or update all the |
||
// SetDegradedMode puts the daemon into a degraded mode which will the | ||
// error given in the "err" argument for commands that are not marked | ||
// as readonlyOK. | ||
|
@@ -452,20 +456,24 @@ func (d *Daemon) initStandbyHandling() { | |
d.standbyOpinions.Start() | ||
} | ||
|
||
func (d *Daemon) Start() { | ||
func (d *Daemon) Start() error { | ||
if d.rebootIsMissing { | ||
// we need to schedule and wait for a system restart | ||
d.tomb.Kill(nil) | ||
// avoid systemd killing us again while we wait | ||
systemdSdNotify("READY=1") | ||
return | ||
return nil | ||
} | ||
if d.overlord == nil { | ||
panic("internal error: no Overlord") | ||
} | ||
|
||
d.StartTime = time.Now() | ||
|
||
// now perform expensive overlord/manages initialization | ||
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. I think the comment intends to read: |
||
if err := d.overlord.StartUp(); err != nil { | ||
return err | ||
} | ||
d.connTracker = &connTracker{conns: make(map[net.Conn]struct{})} | ||
d.serve = &http.Server{ | ||
Handler: logit(d.router), | ||
|
@@ -505,6 +513,7 @@ func (d *Daemon) Start() { | |
|
||
// notify systemd that we are ready | ||
systemdSdNotify("READY=1") | ||
return nil | ||
} | ||
|
||
// HandleRestart implements overlord.RestartBehavior. | ||
|
@@ -673,7 +682,7 @@ func (d *Daemon) rebootDelay() (time.Duration, error) { | |
// see whether a reboot had already been scheduled | ||
var rebootAt time.Time | ||
err := d.state.Get("daemon-system-restart-at", &rebootAt) | ||
if err != nil && err != state.ErrNoState { | ||
if err != nil && !errors.Is(err, state.ErrNoState) { | ||
return 0, err | ||
} | ||
rebootDelay := 1 * time.Minute | ||
|
@@ -758,7 +767,7 @@ var errExpectedReboot = errors.New("expected reboot did not happen") | |
func (d *Daemon) RebootIsMissing(st *state.State) error { | ||
var nTentative int | ||
err := st.Get("daemon-system-restart-tentative", &nTentative) | ||
if err != nil && err != state.ErrNoState { | ||
if err != nil && !errors.Is(err, state.ErrNoState) { | ||
return err | ||
} | ||
nTentative++ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,7 +103,8 @@ func (s *daemonSuite) TestExplicitPaths(c *C) { | |
|
||
d := s.newDaemon(c) | ||
d.Init() | ||
d.Start() | ||
err := d.Start() | ||
c.Assert(err, check.IsNil) | ||
defer d.Stop(nil) | ||
|
||
info, err := os.Stat(s.socketPath) | ||
|
@@ -459,7 +460,8 @@ func (s *daemonSuite) TestStartStop(c *check.C) { | |
untrustedAccept := make(chan struct{}) | ||
d.untrustedListener = &witnessAcceptListener{Listener: l2, accept: untrustedAccept} | ||
|
||
d.Start() | ||
err = d.Start() | ||
c.Assert(err, check.IsNil) | ||
|
||
generalDone := make(chan struct{}) | ||
go func() { | ||
|
@@ -500,7 +502,8 @@ func (s *daemonSuite) TestRestartWiring(c *check.C) { | |
untrustedAccept := make(chan struct{}) | ||
d.untrustedListener = &witnessAcceptListener{Listener: l, accept: untrustedAccept} | ||
|
||
d.Start() | ||
err = d.Start() | ||
c.Assert(err, check.IsNil) | ||
defer d.Stop(nil) | ||
|
||
generalDone := make(chan struct{}) | ||
|
@@ -567,7 +570,8 @@ func (s *daemonSuite) TestGracefulStop(c *check.C) { | |
untrustedAccept := make(chan struct{}) | ||
d.untrustedListener = &witnessAcceptListener{Listener: untrustedL, accept: untrustedAccept} | ||
|
||
d.Start() | ||
err = d.Start() | ||
c.Assert(err, check.IsNil) | ||
|
||
generalAccepting := make(chan struct{}) | ||
go func() { | ||
|
@@ -634,7 +638,8 @@ func (s *daemonSuite) TestRestartSystemWiring(c *check.C) { | |
untrustedAccept := make(chan struct{}) | ||
d.untrustedListener = &witnessAcceptListener{Listener: l, accept: untrustedAccept} | ||
|
||
d.Start() | ||
err = d.Start() | ||
c.Assert(err, check.IsNil) | ||
defer d.Stop(nil) | ||
|
||
st := d.overlord.State() | ||
|
@@ -781,7 +786,8 @@ func (s *daemonSuite) TestRestartShutdownWithSigtermInBetween(c *check.C) { | |
d := s.newDaemon(c) | ||
makeDaemonListeners(c, d) | ||
|
||
d.Start() | ||
err := d.Start() | ||
c.Assert(err, check.IsNil) | ||
st := d.overlord.State() | ||
|
||
st.Lock() | ||
|
@@ -791,7 +797,7 @@ func (s *daemonSuite) TestRestartShutdownWithSigtermInBetween(c *check.C) { | |
ch := make(chan os.Signal, 2) | ||
ch <- syscall.SIGTERM | ||
// stop will check if we got a sigterm in between (which we did) | ||
err := d.Stop(ch) | ||
err = d.Stop(ch) | ||
c.Assert(err, check.IsNil) | ||
} | ||
|
||
|
@@ -813,7 +819,8 @@ func (s *daemonSuite) TestRestartShutdown(c *check.C) { | |
d := s.newDaemon(c) | ||
makeDaemonListeners(c, d) | ||
|
||
d.Start() | ||
err := d.Start() | ||
c.Assert(err, check.IsNil) | ||
st := d.overlord.State() | ||
|
||
st.Lock() | ||
|
@@ -860,7 +867,8 @@ func (s *daemonSuite) TestRestartExpectedRebootIsMissing(c *check.C) { | |
c.Check(err, check.IsNil) | ||
c.Check(n, check.Equals, 1) | ||
|
||
d.Start() | ||
err = d.Start() | ||
c.Assert(err, check.IsNil) | ||
|
||
c.Check(s.notified, check.DeepEquals, []string{"READY=1"}) | ||
|
||
|
@@ -896,8 +904,8 @@ func (s *daemonSuite) TestRestartExpectedRebootOK(c *check.C) { | |
defer st.Unlock() | ||
var v interface{} | ||
// these were cleared | ||
c.Check(st.Get("daemon-system-restart-at", &v), check.Equals, state.ErrNoState) | ||
c.Check(st.Get("system-restart-from-boot-id", &v), check.Equals, state.ErrNoState) | ||
c.Check(st.Get("daemon-system-restart-at", &v), testutil.ErrorIs, state.ErrNoState) | ||
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. Only in Furthermore, it really feels like having |
||
c.Check(st.Get("system-restart-from-boot-id", &v), testutil.ErrorIs, state.ErrNoState) | ||
} | ||
|
||
func (s *daemonSuite) TestRestartExpectedRebootGiveUp(c *check.C) { | ||
|
@@ -920,9 +928,9 @@ func (s *daemonSuite) TestRestartExpectedRebootGiveUp(c *check.C) { | |
defer st.Unlock() | ||
var v interface{} | ||
// these were cleared | ||
c.Check(st.Get("daemon-system-restart-at", &v), check.Equals, state.ErrNoState) | ||
c.Check(st.Get("system-restart-from-boot-id", &v), check.Equals, state.ErrNoState) | ||
c.Check(st.Get("daemon-system-restart-tentative", &v), check.Equals, state.ErrNoState) | ||
c.Check(st.Get("daemon-system-restart-at", &v), testutil.ErrorIs, state.ErrNoState) | ||
c.Check(st.Get("system-restart-from-boot-id", &v), testutil.ErrorIs, state.ErrNoState) | ||
c.Check(st.Get("daemon-system-restart-tentative", &v), testutil.ErrorIs, state.ErrNoState) | ||
} | ||
|
||
func (s *daemonSuite) TestRestartIntoSocketModeNoNewChanges(c *check.C) { | ||
|
@@ -936,7 +944,8 @@ func (s *daemonSuite) TestRestartIntoSocketModeNoNewChanges(c *check.C) { | |
d := s.newDaemon(c) | ||
makeDaemonListeners(c, d) | ||
|
||
d.Start() | ||
err := d.Start() | ||
c.Assert(err, check.IsNil) | ||
|
||
// pretend some ensure happened | ||
for i := 0; i < 5; i++ { | ||
|
@@ -955,7 +964,7 @@ func (s *daemonSuite) TestRestartIntoSocketModeNoNewChanges(c *check.C) { | |
case <-time.After(15 * time.Second): | ||
c.Errorf("daemon did not stop after 15s") | ||
} | ||
err := d.Stop(nil) | ||
err = d.Stop(nil) | ||
c.Check(err, check.Equals, ErrRestartSocket) | ||
c.Check(d.restartSocket, check.Equals, true) | ||
} | ||
|
@@ -972,7 +981,8 @@ func (s *daemonSuite) TestRestartIntoSocketModePendingChanges(c *check.C) { | |
|
||
st := d.overlord.State() | ||
|
||
d.Start() | ||
err := d.Start() | ||
c.Assert(err, check.IsNil) | ||
// pretend some ensure happened | ||
for i := 0; i < 5; i++ { | ||
d.overlord.StateEngine().Ensure() | ||
|
@@ -998,7 +1008,7 @@ func (s *daemonSuite) TestRestartIntoSocketModePendingChanges(c *check.C) { | |
c.Errorf("daemon did not stop after 5s") | ||
} | ||
// when the daemon got a pending change it just restarts | ||
err := d.Stop(nil) | ||
err = d.Stop(nil) | ||
c.Check(err, check.IsNil) | ||
c.Check(d.restartSocket, check.Equals, false) | ||
} | ||
|
@@ -1058,7 +1068,8 @@ func (s *daemonSuite) TestHTTPAPI(c *check.C) { | |
s.httpAddress = ":0" // Go will choose port (use listener.Addr() to find it) | ||
d := s.newDaemon(c) | ||
d.Init() | ||
d.Start() | ||
err := d.Start() | ||
c.Assert(err, check.IsNil) | ||
port := d.httpListener.Addr().(*net.TCPAddr).Port | ||
|
||
request, err := http.NewRequest("GET", fmt.Sprintf("http://localhost:%d/v1/health", port), nil) | ||
|
@@ -1101,7 +1112,8 @@ services: | |
d := s.newDaemon(c) | ||
err := d.Init() | ||
c.Assert(err, IsNil) | ||
d.Start() | ||
err = d.Start() | ||
c.Assert(err, check.IsNil) | ||
|
||
// Start the test service. | ||
payload := bytes.NewBufferString(`{"action": "start", "services": ["test1"]}`) | ||
|
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 think we can simplify this for error only returns to mimic
d.Init()
?