From 67dc16c9cac663019d155dd83e5b52237457adef Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 14 Feb 2017 18:11:55 -0500 Subject: [PATCH] Make backend/local test pass --- backend/local/backend_apply.go | 2 +- backend/local/backend_local.go | 6 +++++- backend/local/backend_plan.go | 2 +- backend/local/backend_refresh.go | 2 +- command/state/state.go | 18 ++++++++++++------ 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/backend/local/backend_apply.go b/backend/local/backend_apply.go index 62c4fcd1f..caffaa983 100644 --- a/backend/local/backend_apply.go +++ b/backend/local/backend_apply.go @@ -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) } }() diff --git a/backend/local/backend_local.go b/backend/local/backend_local.go index cdcaac1d1..265075675 100644 --- a/backend/local/backend_local.go +++ b/backend/local/backend_local.go @@ -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) } diff --git a/backend/local/backend_plan.go b/backend/local/backend_plan.go index 2e218c79e..70587cb36 100644 --- a/backend/local/backend_plan.go +++ b/backend/local/backend_plan.go @@ -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) } }() diff --git a/backend/local/backend_refresh.go b/backend/local/backend_refresh.go index dc5c9a6e4..6a939d491 100644 --- a/backend/local/backend_refresh.go +++ b/backend/local/backend_refresh.go @@ -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) } }() diff --git a/command/state/state.go b/command/state/state.go index 32a5c8619..3915e8ca2 100644 --- a/command/state/state.go +++ b/command/state/state.go @@ -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)) }