Commit 36673407 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/amazon/chroot: switch func type to interface

Was getting weird behavior... see
https://groups.google.com/d/msg/golang-nuts/a1kymwSVt2M/FwcCuBl1_48
parent 668631bd
...@@ -18,10 +18,6 @@ import ( ...@@ -18,10 +18,6 @@ import (
// The unique ID for this builder // The unique ID for this builder
const BuilderId = "mitchellh.amazon.chroot" const BuilderId = "mitchellh.amazon.chroot"
// CleanupFunc is a type that is strung throughout the state bag in
// order to perform cleanup at earlier points.
type CleanupFunc func(map[string]interface{}) error
// Config is the configuration that is chained through the steps and // Config is the configuration that is chained through the steps and
// settable from the template. // settable from the template.
type Config struct { type Config struct {
......
package chroot
// Cleanup is an interface that some steps implement for early cleanup.
type Cleanup interface {
CleanupFunc(map[string]interface{}) error
}
...@@ -71,7 +71,7 @@ func (s *StepAttachVolume) Run(state map[string]interface{}) multistep.StepActio ...@@ -71,7 +71,7 @@ func (s *StepAttachVolume) Run(state map[string]interface{}) multistep.StepActio
} }
state["device"] = config.AttachedDevicePath state["device"] = config.AttachedDevicePath
state["attach_cleanup"] = s.CleanupFunc state["attach_cleanup"] = s
return multistep.ActionContinue return multistep.ActionContinue
} }
......
package chroot
import "testing"
func TestAttachVolumeCleanupFunc_ImplementsCleanupFunc(t *testing.T) {
var raw interface{}
raw = new(StepAttachVolume)
if _, ok := raw.(Cleanup); !ok {
t.Fatalf("cleanup func should be a CleanupFunc")
}
}
...@@ -43,7 +43,7 @@ func (s *StepCopyFiles) Run(state map[string]interface{}) multistep.StepAction { ...@@ -43,7 +43,7 @@ func (s *StepCopyFiles) Run(state map[string]interface{}) multistep.StepAction {
} }
} }
state["copy_files_cleanup"] = s.CleanupFunc state["copy_files_cleanup"] = s
return multistep.ActionContinue return multistep.ActionContinue
} }
......
package chroot
import "testing"
func TestCopyFilesCleanupFunc_ImplementsCleanupFunc(t *testing.T) {
var raw interface{}
raw = new(StepCopyFiles)
if _, ok := raw.(Cleanup); !ok {
t.Fatalf("cleanup func should be a CleanupFunc")
}
}
...@@ -21,9 +21,9 @@ func (s *StepEarlyCleanup) Run(state map[string]interface{}) multistep.StepActio ...@@ -21,9 +21,9 @@ func (s *StepEarlyCleanup) Run(state map[string]interface{}) multistep.StepActio
} }
for _, key := range cleanupKeys { for _, key := range cleanupKeys {
f := state[key].(CleanupFunc) c := state[key].(Cleanup)
log.Printf("Running cleanup func: %s", key) log.Printf("Running cleanup func: %s", key)
if err := f(state); err != nil { if err := c.CleanupFunc(state); err != nil {
err := fmt.Errorf("Error cleaning up: %s", err) err := fmt.Errorf("Error cleaning up: %s", err)
state["error"] = err state["error"] = err
ui.Error(err.Error()) ui.Error(err.Error())
......
...@@ -62,7 +62,7 @@ func (s *StepMountDevice) Run(state map[string]interface{}) multistep.StepAction ...@@ -62,7 +62,7 @@ func (s *StepMountDevice) Run(state map[string]interface{}) multistep.StepAction
// Set the mount path so we remember to unmount it later // Set the mount path so we remember to unmount it later
s.mountPath = mountPath s.mountPath = mountPath
state["mount_path"] = s.mountPath state["mount_path"] = s.mountPath
state["mount_device_cleanup"] = s.CleanupFunc state["mount_device_cleanup"] = s
return multistep.ActionContinue return multistep.ActionContinue
} }
......
package chroot
import "testing"
func TestMountDeviceCleanupFunc_ImplementsCleanupFunc(t *testing.T) {
var raw interface{}
raw = new(StepMountDevice)
if _, ok := raw.(Cleanup); !ok {
t.Fatalf("cleanup func should be a CleanupFunc")
}
}
...@@ -61,7 +61,7 @@ func (s *StepMountExtra) Run(state map[string]interface{}) multistep.StepAction ...@@ -61,7 +61,7 @@ func (s *StepMountExtra) Run(state map[string]interface{}) multistep.StepAction
s.mounts = append(s.mounts, innerPath) s.mounts = append(s.mounts, innerPath)
} }
state["mount_extra_cleanup"] = s.CleanupFunc state["mount_extra_cleanup"] = s
return multistep.ActionContinue return multistep.ActionContinue
} }
......
package chroot
import "testing"
func TestMountExtraCleanupFunc_ImplementsCleanupFunc(t *testing.T) {
var raw interface{}
raw = new(StepMountExtra)
if _, ok := raw.(Cleanup); !ok {
t.Fatalf("cleanup func should be a CleanupFunc")
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment