From 5d48d658b477c303ba65595e40cd2aca121534c4 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Mon, 22 Jan 2018 15:29:42 -0800 Subject: [PATCH] Wire context through misc steps Some steps actually need to pass the context around, so let's create a ctx variable and pass it. --- .../virtualbox/common/step_download_guest_additions.go | 10 +++++----- common/multistep_runner.go | 9 +++++---- helper/communicator/step_connect.go | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/builder/virtualbox/common/step_download_guest_additions.go b/builder/virtualbox/common/step_download_guest_additions.go index 1aebca144..facc60b6a 100644 --- a/builder/virtualbox/common/step_download_guest_additions.go +++ b/builder/virtualbox/common/step_download_guest_additions.go @@ -37,7 +37,7 @@ type StepDownloadGuestAdditions struct { Ctx interpolate.Context } -func (s *StepDownloadGuestAdditions) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { +func (s *StepDownloadGuestAdditions) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { var action multistep.StepAction driver := state.Get("driver").(Driver) ui := state.Get("ui").(packer.Ui) @@ -114,7 +114,7 @@ func (s *StepDownloadGuestAdditions) Run(_ context.Context, state multistep.Stat if s.GuestAdditionsSHA256 != "" { checksum = s.GuestAdditionsSHA256 } else { - checksum, action = s.downloadAdditionsSHA256(state, version, additionsName) + checksum, action = s.downloadAdditionsSHA256(ctx, state, version, additionsName) if action != multistep.ActionContinue { return action } @@ -141,12 +141,12 @@ func (s *StepDownloadGuestAdditions) Run(_ context.Context, state multistep.Stat Url: []string{url}, } - return downStep.Run(state) + return downStep.Run(ctx, state) } func (s *StepDownloadGuestAdditions) Cleanup(state multistep.StateBag) {} -func (s *StepDownloadGuestAdditions) downloadAdditionsSHA256(state multistep.StateBag, additionsVersion string, additionsName string) (string, multistep.StepAction) { +func (s *StepDownloadGuestAdditions) downloadAdditionsSHA256(ctx context.Context, state multistep.StateBag, additionsVersion string, additionsName string) (string, multistep.StepAction) { // First things first, we get the list of checksums for the files available // for this version. checksumsUrl := fmt.Sprintf( @@ -170,7 +170,7 @@ func (s *StepDownloadGuestAdditions) downloadAdditionsSHA256(state multistep.Sta Url: []string{checksumsUrl}, } - action := downStep.Run(state) + action := downStep.Run(ctx, state) if action == multistep.ActionHalt { return "", action } diff --git a/common/multistep_runner.go b/common/multistep_runner.go index c10c0879e..e3c16e7cf 100644 --- a/common/multistep_runner.go +++ b/common/multistep_runner.go @@ -1,6 +1,7 @@ package common import ( + "context" "fmt" "log" "os" @@ -65,8 +66,8 @@ func (s abortStep) InnerStepName() string { return typeName(s.step) } -func (s abortStep) Run(state multistep.StateBag) multistep.StepAction { - return s.step.Run(state) +func (s abortStep) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { + return s.step.Run(ctx, state) } func (s abortStep) Cleanup(state multistep.StateBag) { @@ -90,9 +91,9 @@ func (s askStep) InnerStepName() string { return typeName(s.step) } -func (s askStep) Run(state multistep.StateBag) (action multistep.StepAction) { +func (s askStep) Run(ctx context.Context, state multistep.StateBag) (action multistep.StepAction) { for { - action = s.step.Run(state) + action = s.step.Run(ctx, state) if action != multistep.ActionHalt { return diff --git a/helper/communicator/step_connect.go b/helper/communicator/step_connect.go index 541f88fe1..273935710 100644 --- a/helper/communicator/step_connect.go +++ b/helper/communicator/step_connect.go @@ -44,7 +44,7 @@ type StepConnect struct { substep multistep.Step } -func (s *StepConnect) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { +func (s *StepConnect) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { typeMap := map[string]multistep.Step{ "none": nil, "ssh": &StepConnectSSH{ @@ -85,7 +85,7 @@ func (s *StepConnect) Run(_ context.Context, state multistep.StateBag) multistep } s.substep = step - return s.substep.Run(state) + return s.substep.Run(ctx, state) } func (s *StepConnect) Cleanup(state multistep.StateBag) {