func (s *MachineStatusSuite) TestDown(c *gc.C) { s.machine.agentDead = true agent, err := common.MachineStatus(s.machine) c.Assert(err, jc.ErrorIsNil) c.Assert(agent, jc.DeepEquals, status.StatusInfo{ Status: status.Down, Message: "agent is not communicating with the server", }) }
// processMachine retrieves version and status information for the given machine. // It also returns deprecated legacy status information. func processMachine(machine *state.Machine) (out params.DetailedStatus) { statusInfo, err := common.MachineStatus(machine) populateStatusFromStatusInfoAndErr(&out, statusInfo, err) out.Life = processLife(machine) if t, err := machine.AgentTools(); err == nil { out.Version = t.Version.Number.String() } return }
func checkMachines(backend PrecheckBackend) error { modelVersion, err := backend.AgentVersion() if err != nil { return errors.Annotate(err, "retrieving model version") } machines, err := backend.AllMachines() if err != nil { return errors.Annotate(err, "retrieving machines") } for _, machine := range machines { if machine.Life() != state.Alive { return errors.Errorf("machine %s is %s", machine.Id(), machine.Life()) } if statusInfo, err := machine.InstanceStatus(); err != nil { return errors.Annotatef(err, "retrieving machine %s instance status", machine.Id()) } else if statusInfo.Status != status.Running { return newStatusError("machine %s not running", machine.Id(), statusInfo.Status) } if statusInfo, err := common.MachineStatus(machine); err != nil { return errors.Annotatef(err, "retrieving machine %s status", machine.Id()) } else if statusInfo.Status != status.Started { return newStatusError("machine %s agent not functioning at this time", machine.Id(), statusInfo.Status) } if rebootAction, err := machine.ShouldRebootOrShutdown(); err != nil { return errors.Annotatef(err, "retrieving machine %s reboot status", machine.Id()) } else if rebootAction != state.ShouldDoNothing { return errors.Errorf("machine %s is scheduled to %s", machine.Id(), rebootAction) } if err := checkAgentTools(modelVersion, machine, "machine "+machine.Id()); err != nil { return errors.Trace(err) } } return nil }
func (s *MachineStatusSuite) TestErrors(c *gc.C) { s.machine.statusErr = errors.New("status error") _, err := common.MachineStatus(s.machine) c.Assert(err, gc.ErrorMatches, "status error") }
func (s *MachineStatusSuite) checkUntouched(c *gc.C) { agent, err := common.MachineStatus(s.machine) c.Check(err, jc.ErrorIsNil) c.Assert(agent.Status, jc.DeepEquals, s.machine.status) }