Пример #1
0
// processUnitAndAgentStatus retrieves status information for both unit and unitAgents.
func processUnitAndAgentStatus(unit *state.Unit, status *params.UnitStatus) {
	status.UnitAgent, status.Workload = processUnitStatus(unit)

	// Legacy fields required until Juju 2.0.
	// We only display pending, started, error, stopped.
	var ok bool
	legacyState, ok := state.TranslateToLegacyAgentState(
		state.Status(status.UnitAgent.Status),
		state.Status(status.Workload.Status),
		status.Workload.Info,
	)
	if !ok {
		logger.Warningf(
			"translate to legacy status encounted unexpected workload status %q and agent status %q",
			status.Workload.Status, status.UnitAgent.Status)
	}
	status.AgentState = params.Status(legacyState)
	if status.AgentState == params.StatusError {
		status.AgentStateInfo = status.Workload.Info
	}
	status.AgentVersion = status.UnitAgent.Version
	status.Life = status.UnitAgent.Life
	status.Err = status.UnitAgent.Err

	processUnitLost(unit, status)

	return
}
Пример #2
0
func (s *statusSuite) TestTranslateLegacyAgentState(c *gc.C) {
	for i, test := range []struct {
		agentStatus     state.Status
		workloadStatus  state.Status
		workloadMessage string
		expected        state.Status
	}{
		{
			agentStatus: state.StatusAllocating,
			expected:    state.StatusPending,
		}, {
			agentStatus: state.StatusError,
			expected:    state.StatusError,
		}, {
			agentStatus:     state.StatusIdle,
			workloadStatus:  state.StatusMaintenance,
			expected:        state.StatusPending,
			workloadMessage: "installing charm software",
		}, {
			agentStatus:     state.StatusIdle,
			workloadStatus:  state.StatusMaintenance,
			expected:        state.StatusStarted,
			workloadMessage: "backing up",
		}, {
			agentStatus:    state.StatusIdle,
			workloadStatus: state.StatusTerminated,
			expected:       state.StatusStopped,
		}, {
			agentStatus:    state.StatusIdle,
			workloadStatus: state.StatusBlocked,
			expected:       state.StatusStarted,
		},
	} {
		c.Logf("test %d", i)
		legacy, ok := state.TranslateToLegacyAgentState(test.agentStatus, test.workloadStatus, test.workloadMessage)
		c.Check(ok, jc.IsTrue)
		c.Check(legacy, gc.Equals, test.expected)
	}
}