mirror of
https://github.com/hashicorp/packer.git
synced 2026-04-26 00:31:18 -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.
38 lines
No EOL
1.1 KiB
Go
38 lines
No EOL
1.1 KiB
Go
package googlecompute
|
|
|
|
import (
|
|
"github.com/mitchellh/multistep"
|
|
"testing"
|
|
)
|
|
|
|
func TestStepWaitInstanceStartup(t *testing.T) {
|
|
state := testState(t)
|
|
step := new(StepWaitInstanceStartup)
|
|
config := state.Get("config").(*Config)
|
|
driver := state.Get("driver").(*DriverMock)
|
|
|
|
testZone := "test-zone"
|
|
testInstanceName := "test-instance-name"
|
|
|
|
config.Zone = testZone
|
|
state.Put("instance_name", testInstanceName)
|
|
// The done log triggers step completion.
|
|
driver.GetSerialPortOutputResult = StartupScriptDoneLog
|
|
|
|
// Run the step.
|
|
if action := step.Run(state); action != multistep.ActionContinue {
|
|
t.Fatalf("StepWaitInstanceStartup did not return a Continue action: %#v", action)
|
|
}
|
|
|
|
// Check that GetSerialPortOutput was called properly.
|
|
if driver.GetSerialPortOutputZone != testZone {
|
|
t.Fatalf(
|
|
"GetSerialPortOutput wrong zone. Expected: %s, Actual: %s", driver.GetSerialPortOutputZone,
|
|
testZone)
|
|
}
|
|
if driver.GetSerialPortOutputName != testInstanceName {
|
|
t.Fatalf(
|
|
"GetSerialPortOutput wrong instance name. Expected: %s, Actual: %s", driver.GetSerialPortOutputName,
|
|
testInstanceName)
|
|
}
|
|
} |