Make backend/local test pass
This commit is contained in:
parent
6d32b70637
commit
67dc16c9ca
|
@ -38,7 +38,7 @@ func (b *Local) opApply(
|
|||
// If we're locking state, unlock when we're done
|
||||
if op.LockState {
|
||||
defer func() {
|
||||
if err := clistate.Unlock(opState, b.CLI, b.Colorize()); err != nil {
|
||||
if err := clistate.Unlock(opState, "", b.CLI, b.Colorize()); err != nil {
|
||||
runningOp.Err = multierror.Append(runningOp.Err, err)
|
||||
}
|
||||
}()
|
||||
|
|
|
@ -30,7 +30,11 @@ func (b *Local) context(op *backend.Operation) (*terraform.Context, state.State,
|
|||
}
|
||||
|
||||
if op.LockState {
|
||||
err := clistate.Lock(s, op.Type.String(), b.CLI, b.Colorize())
|
||||
lockInfo := &state.LockInfo{
|
||||
Info: op.Type.String(),
|
||||
}
|
||||
|
||||
_, err := clistate.Lock(s, lockInfo, b.CLI, b.Colorize())
|
||||
if err != nil {
|
||||
return nil, nil, errwrap.Wrapf("Error locking state: {{err}}", err)
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ func (b *Local) opPlan(
|
|||
// If we're locking state, unlock when we're done
|
||||
if op.LockState {
|
||||
defer func() {
|
||||
if err := clistate.Unlock(opState, b.CLI, b.Colorize()); err != nil {
|
||||
if err := clistate.Unlock(opState, "", b.CLI, b.Colorize()); err != nil {
|
||||
runningOp.Err = multierror.Append(runningOp.Err, err)
|
||||
}
|
||||
}()
|
||||
|
|
|
@ -51,7 +51,7 @@ func (b *Local) opRefresh(
|
|||
// If we're locking state, unlock when we're done
|
||||
if op.LockState {
|
||||
defer func() {
|
||||
if err := clistate.Unlock(opState, b.CLI, b.Colorize()); err != nil {
|
||||
if err := clistate.Unlock(opState, "", b.CLI, b.Colorize()); err != nil {
|
||||
runningOp.Err = multierror.Append(runningOp.Err, err)
|
||||
}
|
||||
}()
|
||||
|
|
|
@ -49,14 +49,18 @@ that no one else is holding a lock.
|
|||
|
||||
// Lock locks the given state and outputs to the user if locking
|
||||
// is taking longer than the threshold.
|
||||
func Lock(s state.State, info string, ui cli.Ui, color *colorstring.Colorize) error {
|
||||
func Lock(s state.State, info *state.LockInfo, ui cli.Ui, color *colorstring.Colorize) (string, error) {
|
||||
sl, ok := s.(state.Locker)
|
||||
if !ok {
|
||||
return nil
|
||||
return "", nil
|
||||
}
|
||||
|
||||
var lockID string
|
||||
|
||||
err := slowmessage.Do(LockThreshold, func() error {
|
||||
return sl.Lock(info)
|
||||
id, err := sl.Lock(info)
|
||||
lockID = id
|
||||
return err
|
||||
}, func() {
|
||||
if ui != nil {
|
||||
ui.Output(color.Color(LockMessage))
|
||||
|
@ -67,18 +71,20 @@ func Lock(s state.State, info string, ui cli.Ui, color *colorstring.Colorize) er
|
|||
err = errwrap.Wrapf(strings.TrimSpace(LockErrorMessage), err)
|
||||
}
|
||||
|
||||
return err
|
||||
return lockID, err
|
||||
}
|
||||
|
||||
// Unlock unlocks the given state and outputs to the user if the
|
||||
// unlock fails what can be done.
|
||||
func Unlock(s state.State, ui cli.Ui, color *colorstring.Colorize) error {
|
||||
func Unlock(s state.State, id string, ui cli.Ui, color *colorstring.Colorize) error {
|
||||
sl, ok := s.(state.Locker)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
err := slowmessage.Do(LockThreshold, sl.Unlock, func() {
|
||||
err := slowmessage.Do(LockThreshold, func() error {
|
||||
return sl.Unlock(id)
|
||||
}, func() {
|
||||
if ui != nil {
|
||||
ui.Output(color.Color(UnlockMessage))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue