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 *RetryStrategySuite) TestOnlyConnectSuccess(c *gc.C) { stub := &testing.Stub{} stub.SetErrors( errNotProvisioned, // initial attempt, outside strategy errNotProvisioned, // first strategy attempt nil, // success on second strategy attempt ) strategy := utils.AttemptStrategy{Min: 3} conn, err := strategyTest(stub, strategy, func(apiOpen api.OpenFunc) (api.Connection, error) { return apicaller.OnlyConnect(&mockAgent{stub: stub}, apiOpen) }) checkOpenCalls(c, stub, "new", "new", "new") c.Check(conn, gc.NotNil) c.Check(err, jc.ErrorIsNil) }
func (s *RetryStrategySuite) TestOnlyConnectOldPasswordSuccess(c *gc.C) { stub := &testing.Stub{} stub.SetErrors( errNotAuthorized, // initial attempt, outside strategy errNotProvisioned, // fallback attempt, outside strategy errNotProvisioned, // first strategy attempt nil, // second strategy attempt ) // TODO(katco): 2016-08-09: lp:1611427 strategy := utils.AttemptStrategy{Min: 3} conn, err := strategyTest(stub, strategy, func(apiOpen api.OpenFunc) (api.Connection, error) { return apicaller.OnlyConnect(&mockAgent{stub: stub}, apiOpen) }) checkOpenCalls(c, stub, "new", "old", "old", "old") c.Check(err, jc.ErrorIsNil) c.Check(conn, gc.NotNil) }