mirror of
https://github.com/hashicorp/packer.git
synced 2026-04-23 15:18:40 -04:00
- Startup scripts can be provided through the instance creation metadata field 'startup-script'. - Script log can be copied to a GCS location by setting the metadata field 'startup-script-log-dest'. Added Retry method to googlecompute package. Added GetSerialPortOutput to googlecompute Drivers. Added StepWaitInstanceStartup (and associated test) which waits for an instance startup-script to finish. Changed the instance service account to use the same service account as the one provided in the Packer config template. It was the project default service account. Tested googlecompute package with 'go test' and also performed builds with a startup script and without a startup script.
89 lines
2.4 KiB
Go
89 lines
2.4 KiB
Go
package googlecompute
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/mitchellh/multistep"
|
|
)
|
|
|
|
func TestStepCreateImage_impl(t *testing.T) {
|
|
var _ multistep.Step = new(StepCreateImage)
|
|
}
|
|
|
|
func TestStepCreateImage(t *testing.T) {
|
|
state := testState(t)
|
|
step := new(StepCreateImage)
|
|
defer step.Cleanup(state)
|
|
|
|
config := state.Get("config").(*Config)
|
|
driver := state.Get("driver").(*DriverMock)
|
|
driver.CreateImageProjectId = "createimage-project"
|
|
driver.CreateImageSizeGb = 100
|
|
|
|
// run the step
|
|
if action := step.Run(state); action != multistep.ActionContinue {
|
|
t.Fatalf("bad action: %#v", action)
|
|
}
|
|
|
|
uncastImage, ok := state.GetOk("image")
|
|
if !ok {
|
|
t.Fatal("should have image")
|
|
}
|
|
image, ok := uncastImage.(Image)
|
|
if !ok {
|
|
t.Fatal("image is not an Image")
|
|
}
|
|
|
|
// Verify created Image results.
|
|
if image.Name != config.ImageName {
|
|
t.Fatalf("Created image name, %s, does not match config name, %s.", image.Name, config.ImageName)
|
|
}
|
|
if driver.CreateImageProjectId != image.ProjectId {
|
|
t.Fatalf("Created image project ID, %s, does not match driver project ID, %s.", image.ProjectId, driver.CreateImageProjectId)
|
|
}
|
|
if driver.CreateImageSizeGb != image.SizeGb {
|
|
t.Fatalf("Created image size, %d, does not match the expected test value, %d.", image.SizeGb, driver.CreateImageSizeGb)
|
|
}
|
|
|
|
// Verify proper args passed to driver.CreateImage.
|
|
if driver.CreateImageName != config.ImageName {
|
|
t.Fatalf("bad: %#v", driver.CreateImageName)
|
|
}
|
|
if driver.CreateImageDesc != config.ImageDescription {
|
|
t.Fatalf("bad: %#v", driver.CreateImageDesc)
|
|
}
|
|
if driver.CreateImageFamily != config.ImageFamily {
|
|
t.Fatalf("bad: %#v", driver.CreateImageFamily)
|
|
}
|
|
if driver.CreateImageZone != config.Zone {
|
|
t.Fatalf("bad: %#v", driver.CreateImageZone)
|
|
}
|
|
if driver.CreateImageDisk != config.DiskName {
|
|
t.Fatalf("bad: %#v", driver.CreateImageDisk)
|
|
}
|
|
}
|
|
|
|
func TestStepCreateImage_errorOnChannel(t *testing.T) {
|
|
state := testState(t)
|
|
step := new(StepCreateImage)
|
|
defer step.Cleanup(state)
|
|
|
|
errCh := make(chan error, 1)
|
|
errCh <- errors.New("error")
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
|
driver.CreateImageErrCh = errCh
|
|
|
|
// run the step
|
|
if action := step.Run(state); action != multistep.ActionHalt {
|
|
t.Fatalf("bad action: %#v", action)
|
|
}
|
|
|
|
if _, ok := state.GetOk("error"); !ok {
|
|
t.Fatal("should have error")
|
|
}
|
|
if _, ok := state.GetOk("image_name"); ok {
|
|
t.Fatal("should NOT have image")
|
|
}
|
|
}
|