diff --git a/fleetctl/fleetctl.go b/fleetctl/fleetctl.go index 35b6a76e9..108e29640 100644 --- a/fleetctl/fleetctl.go +++ b/fleetctl/fleetctl.go @@ -1045,7 +1045,7 @@ func assertUnitState(name string, js job.JobState, out io.Writer) (ret bool) { state = u.CurrentState } - if job.JobState(state) != js { + if jsToBeChanged(job.JobState(state), js) { log.Debugf("Waiting for Unit(%s) state(%s) to be %s", name, job.JobState(state), js) return } @@ -1158,6 +1158,32 @@ func machineState(machID string) (*machine.MachineState, error) { return nil, nil } +// jsToBeChanged returns true if the target state is a more activated state +// than the current state. For example, it returns true if it's a transition +// from inactive to launched, but false for other way around. +func jsToBeChanged(cur job.JobState, tgt job.JobState) bool { + switch tgt { + case job.JobStateInactive: + if cur == job.JobStateLoaded || cur == job.JobStateLaunched { + return true + } + break + case job.JobStateLoaded: + if cur == job.JobStateInactive { + return true + } + break + case job.JobStateLaunched: + if cur == job.JobStateInactive || cur == job.JobStateLoaded { + return true + } + break + default: + break + } + return false +} + // cachedMachineState makes a best-effort to retrieve the MachineState of the given machine ID. // It memoizes MachineState information for the life of a fleetctl invocation. // Any error encountered retrieving the list of machines is ignored.