func (a *MachineAgent) executeRebootOrShutdown(action params.RebootAction) error { // At this stage, all API connections would have been closed // We need to reopen the API to clear the reboot flag after // scheduling the reboot. It may be cleaner to do this in the reboot // worker, before returning the ErrRebootMachine. conn, err := apicaller.OnlyConnect(a, apicaller.APIOpen) if err != nil { logger.Infof("Reboot: Error connecting to state") return errors.Trace(err) } // block until all units/containers are ready, and reboot/shutdown finalize, err := reboot.NewRebootWaiter(conn, a.CurrentConfig()) if err != nil { return errors.Trace(err) } logger.Infof("Reboot: Executing reboot") err = finalize.ExecuteReboot(action) if err != nil { logger.Infof("Reboot: Error executing reboot: %v", err) return errors.Trace(err) } // On windows, the shutdown command is asynchronous. We return ErrRebootMachine // so the agent will simply exit without error pending reboot/shutdown. return worker.ErrRebootMachine }
func (s *RebootSuite) TestShutdownNoContainers(c *gc.C) { w, err := reboot.NewRebootWaiter(s.st, s.acfg) c.Assert(err, jc.ErrorIsNil) expectedShutdownParams := s.shutdownCommandParams(c) err = w.ExecuteReboot(params.ShouldShutdown) c.Assert(err, jc.ErrorIsNil) testing.AssertEchoArgs(c, rebootBin, expectedShutdownParams...) }
func (s *RebootSuite) TestRebootNoContainers(c *gc.C) { w, err := reboot.NewRebootWaiter(s.st, s.acfg) c.Assert(err, jc.ErrorIsNil) expectedRebootParams := s.rebootCommandParams(c) err = w.ExecuteReboot(params.ShouldReboot) c.Assert(err, jc.ErrorIsNil) testing.AssertEchoArgs(c, rebootBin, expectedRebootParams...) ft.File{s.rebootScriptName, expectedRebootScript, 0755}.Check(c, s.tmpDir) }
func (s *RebootSuite) TestRebootWithMissbehavingContainers(c *gc.C) { testing.PatchExecutable(c, s, "lxc-ls", lxcLsScript) testing.PatchExecutable(c, s, "lxc-info", lxcInfoScriptMissbehave) s.PatchValue(reboot.Timeout, time.Duration(1*time.Second)) w, err := reboot.NewRebootWaiter(s.st, s.acfg) c.Assert(err, jc.ErrorIsNil) err = w.ExecuteReboot(params.ShouldReboot) c.Assert(err, gc.ErrorMatches, "Timeout reached waiting for containers to shutdown") }
func (s *RebootSuite) TestRebootWithContainers(c *gc.C) { testing.PatchExecutable(c, s, "lxc-ls", lxcLsScript) testing.PatchExecutable(c, s, "lxc-info", lxcInfoScript) expectedRebootParams := s.rebootCommandParams(c) s.PatchValue(reboot.Timeout, time.Duration(5*time.Second)) w, err := reboot.NewRebootWaiter(s.st, s.acfg) c.Assert(err, jc.ErrorIsNil) err = w.ExecuteReboot(params.ShouldReboot) c.Assert(err, jc.ErrorIsNil) testing.AssertEchoArgs(c, rebootBin, expectedRebootParams...) ft.File{s.rebootScriptName, expectedRebootScript, 0755}.Check(c, s.tmpDir) }