2013-12-13 00:38:34 -05:00
|
|
|
package googlecompute
|
|
|
|
|
Some googlecompute fixes and cleanup. Addresses https://github.com/mitchellh/packer/issues/3829. Changes:
- startup scripts don't run for Windows since it is isn't implemented yet.
- startup scripts use instance metadata instead of serial port output to flag when they are done.
- added licenses to Image data type (to check if an Image is a Windows Image).
- added GetImage and GetImageFromProject to googlecompute Drivers.
- changed some of the builder/googlecompute tests to use github.com/stretchr/testify/assert.
Tests:
- (in the Packer directory) `go test .`, `go test ./builder/googlecompute`, and `go test ./post-processor/googlecompute-export`
- manual run of `packer build packer_template.json` with the following files
--packer_template.json--
{
"builders": [
{
"type": "googlecompute",
"account_file": "creds.json",
"project_id": "google.com:packer-test",
"source_image": "debian-8-jessie-v20160629",
"zone": "us-central1-a",
"startup_script_file": "startup_script.sh",
"metadata": {
"startup-script": "#!/bin/sh\necho \"This should be overwritten.\"",
"startup-script-log-dest": "gs://packer-test.google.com.a.appspot.com/startup-script.log"
},
"image_name": "test-packer-modifications",
"ssh_username": "foo"
}
],
"post-processors": [
{
"type": "googlecompute-export",
"paths": [
"gs://packer-test.google.com.a.appspot.com/foo.tar.gz",
"gs://packer-test.google.com.a.appspot.com/bar.tar.gz"
],
"keep_input_artifact": true
}
]
}
--startup_script.sh--
\#!/bin/sh
echo "Hi, my name is Scott. I'm waiting 60 seconds!" >> /scott
sleep 60
echo "I'm done waiting!" >> /scott
2016-09-07 22:00:30 -04:00
|
|
|
import "fmt"
|
|
|
|
|
2013-12-13 00:38:34 -05:00
|
|
|
// DriverMock is a Driver implementation that is a mocked out so that
|
|
|
|
// it can be used for tests.
|
|
|
|
type DriverMock struct {
|
Some googlecompute fixes and cleanup. Addresses https://github.com/mitchellh/packer/issues/3829. Changes:
- startup scripts don't run for Windows since it is isn't implemented yet.
- startup scripts use instance metadata instead of serial port output to flag when they are done.
- added licenses to Image data type (to check if an Image is a Windows Image).
- added GetImage and GetImageFromProject to googlecompute Drivers.
- changed some of the builder/googlecompute tests to use github.com/stretchr/testify/assert.
Tests:
- (in the Packer directory) `go test .`, `go test ./builder/googlecompute`, and `go test ./post-processor/googlecompute-export`
- manual run of `packer build packer_template.json` with the following files
--packer_template.json--
{
"builders": [
{
"type": "googlecompute",
"account_file": "creds.json",
"project_id": "google.com:packer-test",
"source_image": "debian-8-jessie-v20160629",
"zone": "us-central1-a",
"startup_script_file": "startup_script.sh",
"metadata": {
"startup-script": "#!/bin/sh\necho \"This should be overwritten.\"",
"startup-script-log-dest": "gs://packer-test.google.com.a.appspot.com/startup-script.log"
},
"image_name": "test-packer-modifications",
"ssh_username": "foo"
}
],
"post-processors": [
{
"type": "googlecompute-export",
"paths": [
"gs://packer-test.google.com.a.appspot.com/foo.tar.gz",
"gs://packer-test.google.com.a.appspot.com/bar.tar.gz"
],
"keep_input_artifact": true
}
]
}
--startup_script.sh--
\#!/bin/sh
echo "Hi, my name is Scott. I'm waiting 60 seconds!" >> /scott
sleep 60
echo "I'm done waiting!" >> /scott
2016-09-07 22:00:30 -04:00
|
|
|
CreateImageName string
|
|
|
|
CreateImageDesc string
|
|
|
|
CreateImageFamily string
|
|
|
|
CreateImageZone string
|
|
|
|
CreateImageDisk string
|
|
|
|
CreateImageResultLicenses []string
|
|
|
|
CreateImageResultProjectId string
|
|
|
|
CreateImageResultSelfLink string
|
|
|
|
CreateImageResultSizeGb int64
|
|
|
|
CreateImageErrCh <-chan error
|
|
|
|
CreateImageResultCh <-chan *Image
|
2013-12-13 22:03:10 -05:00
|
|
|
|
2013-12-13 22:07:10 -05:00
|
|
|
DeleteImageName string
|
|
|
|
DeleteImageErrCh <-chan error
|
|
|
|
|
2013-12-13 01:34:47 -05:00
|
|
|
DeleteInstanceZone string
|
|
|
|
DeleteInstanceName string
|
|
|
|
DeleteInstanceErrCh <-chan error
|
|
|
|
DeleteInstanceErr error
|
|
|
|
|
2014-11-24 11:36:14 -05:00
|
|
|
DeleteDiskZone string
|
|
|
|
DeleteDiskName string
|
|
|
|
DeleteDiskErrCh <-chan error
|
|
|
|
DeleteDiskErr error
|
|
|
|
|
Some googlecompute fixes and cleanup. Addresses https://github.com/mitchellh/packer/issues/3829. Changes:
- startup scripts don't run for Windows since it is isn't implemented yet.
- startup scripts use instance metadata instead of serial port output to flag when they are done.
- added licenses to Image data type (to check if an Image is a Windows Image).
- added GetImage and GetImageFromProject to googlecompute Drivers.
- changed some of the builder/googlecompute tests to use github.com/stretchr/testify/assert.
Tests:
- (in the Packer directory) `go test .`, `go test ./builder/googlecompute`, and `go test ./post-processor/googlecompute-export`
- manual run of `packer build packer_template.json` with the following files
--packer_template.json--
{
"builders": [
{
"type": "googlecompute",
"account_file": "creds.json",
"project_id": "google.com:packer-test",
"source_image": "debian-8-jessie-v20160629",
"zone": "us-central1-a",
"startup_script_file": "startup_script.sh",
"metadata": {
"startup-script": "#!/bin/sh\necho \"This should be overwritten.\"",
"startup-script-log-dest": "gs://packer-test.google.com.a.appspot.com/startup-script.log"
},
"image_name": "test-packer-modifications",
"ssh_username": "foo"
}
],
"post-processors": [
{
"type": "googlecompute-export",
"paths": [
"gs://packer-test.google.com.a.appspot.com/foo.tar.gz",
"gs://packer-test.google.com.a.appspot.com/bar.tar.gz"
],
"keep_input_artifact": true
}
]
}
--startup_script.sh--
\#!/bin/sh
echo "Hi, my name is Scott. I'm waiting 60 seconds!" >> /scott
sleep 60
echo "I'm done waiting!" >> /scott
2016-09-07 22:00:30 -04:00
|
|
|
GetImageName string
|
|
|
|
GetImageResult *Image
|
|
|
|
GetImageErr error
|
|
|
|
|
|
|
|
GetImageFromProjectProject string
|
|
|
|
GetImageFromProjectName string
|
|
|
|
GetImageFromProjectResult *Image
|
|
|
|
GetImageFromProjectErr error
|
|
|
|
|
|
|
|
GetInstanceMetadataZone string
|
|
|
|
GetInstanceMetadataName string
|
|
|
|
GetInstanceMetadataKey string
|
|
|
|
GetInstanceMetadataResult string
|
|
|
|
GetInstanceMetadataErr error
|
|
|
|
|
2013-12-13 16:01:28 -05:00
|
|
|
GetNatIPZone string
|
|
|
|
GetNatIPName string
|
|
|
|
GetNatIPResult string
|
|
|
|
GetNatIPErr error
|
|
|
|
|
2015-05-29 17:50:11 -04:00
|
|
|
GetInternalIPZone string
|
|
|
|
GetInternalIPName string
|
|
|
|
GetInternalIPResult string
|
|
|
|
GetInternalIPErr error
|
2016-05-24 20:13:36 -04:00
|
|
|
|
|
|
|
GetSerialPortOutputZone string
|
|
|
|
GetSerialPortOutputName string
|
|
|
|
GetSerialPortOutputResult string
|
|
|
|
GetSerialPortOutputErr error
|
2015-05-29 17:50:11 -04:00
|
|
|
|
Some googlecompute fixes and cleanup. Addresses https://github.com/mitchellh/packer/issues/3829. Changes:
- startup scripts don't run for Windows since it is isn't implemented yet.
- startup scripts use instance metadata instead of serial port output to flag when they are done.
- added licenses to Image data type (to check if an Image is a Windows Image).
- added GetImage and GetImageFromProject to googlecompute Drivers.
- changed some of the builder/googlecompute tests to use github.com/stretchr/testify/assert.
Tests:
- (in the Packer directory) `go test .`, `go test ./builder/googlecompute`, and `go test ./post-processor/googlecompute-export`
- manual run of `packer build packer_template.json` with the following files
--packer_template.json--
{
"builders": [
{
"type": "googlecompute",
"account_file": "creds.json",
"project_id": "google.com:packer-test",
"source_image": "debian-8-jessie-v20160629",
"zone": "us-central1-a",
"startup_script_file": "startup_script.sh",
"metadata": {
"startup-script": "#!/bin/sh\necho \"This should be overwritten.\"",
"startup-script-log-dest": "gs://packer-test.google.com.a.appspot.com/startup-script.log"
},
"image_name": "test-packer-modifications",
"ssh_username": "foo"
}
],
"post-processors": [
{
"type": "googlecompute-export",
"paths": [
"gs://packer-test.google.com.a.appspot.com/foo.tar.gz",
"gs://packer-test.google.com.a.appspot.com/bar.tar.gz"
],
"keep_input_artifact": true
}
]
}
--startup_script.sh--
\#!/bin/sh
echo "Hi, my name is Scott. I'm waiting 60 seconds!" >> /scott
sleep 60
echo "I'm done waiting!" >> /scott
2016-09-07 22:00:30 -04:00
|
|
|
ImageExistsName string
|
|
|
|
ImageExistsResult bool
|
|
|
|
|
2013-12-13 00:38:34 -05:00
|
|
|
RunInstanceConfig *InstanceConfig
|
|
|
|
RunInstanceErrCh <-chan error
|
|
|
|
RunInstanceErr error
|
2013-12-13 16:01:28 -05:00
|
|
|
|
|
|
|
WaitForInstanceState string
|
|
|
|
WaitForInstanceZone string
|
|
|
|
WaitForInstanceName string
|
|
|
|
WaitForInstanceErrCh <-chan error
|
2013-12-13 00:38:34 -05:00
|
|
|
}
|
|
|
|
|
Some googlecompute fixes and cleanup. Addresses https://github.com/mitchellh/packer/issues/3829. Changes:
- startup scripts don't run for Windows since it is isn't implemented yet.
- startup scripts use instance metadata instead of serial port output to flag when they are done.
- added licenses to Image data type (to check if an Image is a Windows Image).
- added GetImage and GetImageFromProject to googlecompute Drivers.
- changed some of the builder/googlecompute tests to use github.com/stretchr/testify/assert.
Tests:
- (in the Packer directory) `go test .`, `go test ./builder/googlecompute`, and `go test ./post-processor/googlecompute-export`
- manual run of `packer build packer_template.json` with the following files
--packer_template.json--
{
"builders": [
{
"type": "googlecompute",
"account_file": "creds.json",
"project_id": "google.com:packer-test",
"source_image": "debian-8-jessie-v20160629",
"zone": "us-central1-a",
"startup_script_file": "startup_script.sh",
"metadata": {
"startup-script": "#!/bin/sh\necho \"This should be overwritten.\"",
"startup-script-log-dest": "gs://packer-test.google.com.a.appspot.com/startup-script.log"
},
"image_name": "test-packer-modifications",
"ssh_username": "foo"
}
],
"post-processors": [
{
"type": "googlecompute-export",
"paths": [
"gs://packer-test.google.com.a.appspot.com/foo.tar.gz",
"gs://packer-test.google.com.a.appspot.com/bar.tar.gz"
],
"keep_input_artifact": true
}
]
}
--startup_script.sh--
\#!/bin/sh
echo "Hi, my name is Scott. I'm waiting 60 seconds!" >> /scott
sleep 60
echo "I'm done waiting!" >> /scott
2016-09-07 22:00:30 -04:00
|
|
|
func (d *DriverMock) CreateImage(name, description, family, zone, disk string) (<-chan *Image, <-chan error) {
|
2013-12-13 22:03:10 -05:00
|
|
|
d.CreateImageName = name
|
|
|
|
d.CreateImageDesc = description
|
2016-05-06 07:43:39 -04:00
|
|
|
d.CreateImageFamily = family
|
2014-11-24 11:36:14 -05:00
|
|
|
d.CreateImageZone = zone
|
|
|
|
d.CreateImageDisk = disk
|
Some googlecompute fixes and cleanup. Addresses https://github.com/mitchellh/packer/issues/3829. Changes:
- startup scripts don't run for Windows since it is isn't implemented yet.
- startup scripts use instance metadata instead of serial port output to flag when they are done.
- added licenses to Image data type (to check if an Image is a Windows Image).
- added GetImage and GetImageFromProject to googlecompute Drivers.
- changed some of the builder/googlecompute tests to use github.com/stretchr/testify/assert.
Tests:
- (in the Packer directory) `go test .`, `go test ./builder/googlecompute`, and `go test ./post-processor/googlecompute-export`
- manual run of `packer build packer_template.json` with the following files
--packer_template.json--
{
"builders": [
{
"type": "googlecompute",
"account_file": "creds.json",
"project_id": "google.com:packer-test",
"source_image": "debian-8-jessie-v20160629",
"zone": "us-central1-a",
"startup_script_file": "startup_script.sh",
"metadata": {
"startup-script": "#!/bin/sh\necho \"This should be overwritten.\"",
"startup-script-log-dest": "gs://packer-test.google.com.a.appspot.com/startup-script.log"
},
"image_name": "test-packer-modifications",
"ssh_username": "foo"
}
],
"post-processors": [
{
"type": "googlecompute-export",
"paths": [
"gs://packer-test.google.com.a.appspot.com/foo.tar.gz",
"gs://packer-test.google.com.a.appspot.com/bar.tar.gz"
],
"keep_input_artifact": true
}
]
}
--startup_script.sh--
\#!/bin/sh
echo "Hi, my name is Scott. I'm waiting 60 seconds!" >> /scott
sleep 60
echo "I'm done waiting!" >> /scott
2016-09-07 22:00:30 -04:00
|
|
|
if d.CreateImageResultProjectId == "" {
|
|
|
|
d.CreateImageResultProjectId = "test"
|
|
|
|
}
|
|
|
|
if d.CreateImageResultSelfLink == "" {
|
|
|
|
d.CreateImageResultSelfLink = fmt.Sprintf(
|
|
|
|
"http://content.googleapis.com/compute/v1/%s/global/licenses/test",
|
|
|
|
d.CreateImageResultProjectId)
|
2016-05-24 20:13:36 -04:00
|
|
|
}
|
Some googlecompute fixes and cleanup. Addresses https://github.com/mitchellh/packer/issues/3829. Changes:
- startup scripts don't run for Windows since it is isn't implemented yet.
- startup scripts use instance metadata instead of serial port output to flag when they are done.
- added licenses to Image data type (to check if an Image is a Windows Image).
- added GetImage and GetImageFromProject to googlecompute Drivers.
- changed some of the builder/googlecompute tests to use github.com/stretchr/testify/assert.
Tests:
- (in the Packer directory) `go test .`, `go test ./builder/googlecompute`, and `go test ./post-processor/googlecompute-export`
- manual run of `packer build packer_template.json` with the following files
--packer_template.json--
{
"builders": [
{
"type": "googlecompute",
"account_file": "creds.json",
"project_id": "google.com:packer-test",
"source_image": "debian-8-jessie-v20160629",
"zone": "us-central1-a",
"startup_script_file": "startup_script.sh",
"metadata": {
"startup-script": "#!/bin/sh\necho \"This should be overwritten.\"",
"startup-script-log-dest": "gs://packer-test.google.com.a.appspot.com/startup-script.log"
},
"image_name": "test-packer-modifications",
"ssh_username": "foo"
}
],
"post-processors": [
{
"type": "googlecompute-export",
"paths": [
"gs://packer-test.google.com.a.appspot.com/foo.tar.gz",
"gs://packer-test.google.com.a.appspot.com/bar.tar.gz"
],
"keep_input_artifact": true
}
]
}
--startup_script.sh--
\#!/bin/sh
echo "Hi, my name is Scott. I'm waiting 60 seconds!" >> /scott
sleep 60
echo "I'm done waiting!" >> /scott
2016-09-07 22:00:30 -04:00
|
|
|
if d.CreateImageResultSizeGb == 0 {
|
|
|
|
d.CreateImageResultSizeGb = 10
|
2016-05-24 20:13:36 -04:00
|
|
|
}
|
2013-12-13 22:03:10 -05:00
|
|
|
|
2016-05-24 20:13:36 -04:00
|
|
|
resultCh := d.CreateImageResultCh
|
2013-12-13 22:03:10 -05:00
|
|
|
if resultCh == nil {
|
Some googlecompute fixes and cleanup. Addresses https://github.com/mitchellh/packer/issues/3829. Changes:
- startup scripts don't run for Windows since it is isn't implemented yet.
- startup scripts use instance metadata instead of serial port output to flag when they are done.
- added licenses to Image data type (to check if an Image is a Windows Image).
- added GetImage and GetImageFromProject to googlecompute Drivers.
- changed some of the builder/googlecompute tests to use github.com/stretchr/testify/assert.
Tests:
- (in the Packer directory) `go test .`, `go test ./builder/googlecompute`, and `go test ./post-processor/googlecompute-export`
- manual run of `packer build packer_template.json` with the following files
--packer_template.json--
{
"builders": [
{
"type": "googlecompute",
"account_file": "creds.json",
"project_id": "google.com:packer-test",
"source_image": "debian-8-jessie-v20160629",
"zone": "us-central1-a",
"startup_script_file": "startup_script.sh",
"metadata": {
"startup-script": "#!/bin/sh\necho \"This should be overwritten.\"",
"startup-script-log-dest": "gs://packer-test.google.com.a.appspot.com/startup-script.log"
},
"image_name": "test-packer-modifications",
"ssh_username": "foo"
}
],
"post-processors": [
{
"type": "googlecompute-export",
"paths": [
"gs://packer-test.google.com.a.appspot.com/foo.tar.gz",
"gs://packer-test.google.com.a.appspot.com/bar.tar.gz"
],
"keep_input_artifact": true
}
]
}
--startup_script.sh--
\#!/bin/sh
echo "Hi, my name is Scott. I'm waiting 60 seconds!" >> /scott
sleep 60
echo "I'm done waiting!" >> /scott
2016-09-07 22:00:30 -04:00
|
|
|
ch := make(chan *Image, 1)
|
|
|
|
ch <- &Image{
|
|
|
|
Licenses: d.CreateImageResultLicenses,
|
2016-05-24 20:13:36 -04:00
|
|
|
Name: name,
|
Some googlecompute fixes and cleanup. Addresses https://github.com/mitchellh/packer/issues/3829. Changes:
- startup scripts don't run for Windows since it is isn't implemented yet.
- startup scripts use instance metadata instead of serial port output to flag when they are done.
- added licenses to Image data type (to check if an Image is a Windows Image).
- added GetImage and GetImageFromProject to googlecompute Drivers.
- changed some of the builder/googlecompute tests to use github.com/stretchr/testify/assert.
Tests:
- (in the Packer directory) `go test .`, `go test ./builder/googlecompute`, and `go test ./post-processor/googlecompute-export`
- manual run of `packer build packer_template.json` with the following files
--packer_template.json--
{
"builders": [
{
"type": "googlecompute",
"account_file": "creds.json",
"project_id": "google.com:packer-test",
"source_image": "debian-8-jessie-v20160629",
"zone": "us-central1-a",
"startup_script_file": "startup_script.sh",
"metadata": {
"startup-script": "#!/bin/sh\necho \"This should be overwritten.\"",
"startup-script-log-dest": "gs://packer-test.google.com.a.appspot.com/startup-script.log"
},
"image_name": "test-packer-modifications",
"ssh_username": "foo"
}
],
"post-processors": [
{
"type": "googlecompute-export",
"paths": [
"gs://packer-test.google.com.a.appspot.com/foo.tar.gz",
"gs://packer-test.google.com.a.appspot.com/bar.tar.gz"
],
"keep_input_artifact": true
}
]
}
--startup_script.sh--
\#!/bin/sh
echo "Hi, my name is Scott. I'm waiting 60 seconds!" >> /scott
sleep 60
echo "I'm done waiting!" >> /scott
2016-09-07 22:00:30 -04:00
|
|
|
ProjectId: d.CreateImageResultProjectId,
|
|
|
|
SelfLink: d.CreateImageResultSelfLink,
|
|
|
|
SizeGb: d.CreateImageResultSizeGb,
|
2016-05-24 20:13:36 -04:00
|
|
|
}
|
2013-12-13 22:03:10 -05:00
|
|
|
close(ch)
|
|
|
|
resultCh = ch
|
|
|
|
}
|
|
|
|
|
2016-05-24 20:13:36 -04:00
|
|
|
errCh := d.CreateImageErrCh
|
|
|
|
if errCh == nil {
|
|
|
|
ch := make(chan error)
|
|
|
|
close(ch)
|
|
|
|
errCh = ch
|
|
|
|
}
|
|
|
|
|
|
|
|
return resultCh, errCh
|
2013-12-13 22:07:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *DriverMock) DeleteImage(name string) <-chan error {
|
|
|
|
d.DeleteImageName = name
|
|
|
|
|
|
|
|
resultCh := d.DeleteImageErrCh
|
|
|
|
if resultCh == nil {
|
|
|
|
ch := make(chan error)
|
|
|
|
close(ch)
|
|
|
|
resultCh = ch
|
|
|
|
}
|
|
|
|
|
2013-12-13 22:03:10 -05:00
|
|
|
return resultCh
|
|
|
|
}
|
|
|
|
|
2013-12-13 01:34:47 -05:00
|
|
|
func (d *DriverMock) DeleteInstance(zone, name string) (<-chan error, error) {
|
|
|
|
d.DeleteInstanceZone = zone
|
|
|
|
d.DeleteInstanceName = name
|
|
|
|
|
|
|
|
resultCh := d.DeleteInstanceErrCh
|
|
|
|
if resultCh == nil {
|
|
|
|
ch := make(chan error)
|
|
|
|
close(ch)
|
|
|
|
resultCh = ch
|
|
|
|
}
|
|
|
|
|
|
|
|
return resultCh, d.DeleteInstanceErr
|
|
|
|
}
|
|
|
|
|
2014-11-24 11:36:14 -05:00
|
|
|
func (d *DriverMock) DeleteDisk(zone, name string) (<-chan error, error) {
|
|
|
|
d.DeleteDiskZone = zone
|
|
|
|
d.DeleteDiskName = name
|
|
|
|
|
|
|
|
resultCh := d.DeleteDiskErrCh
|
|
|
|
if resultCh == nil {
|
|
|
|
ch := make(chan error)
|
|
|
|
close(ch)
|
|
|
|
resultCh = ch
|
|
|
|
}
|
|
|
|
|
|
|
|
return resultCh, d.DeleteDiskErr
|
|
|
|
}
|
|
|
|
|
Some googlecompute fixes and cleanup. Addresses https://github.com/mitchellh/packer/issues/3829. Changes:
- startup scripts don't run for Windows since it is isn't implemented yet.
- startup scripts use instance metadata instead of serial port output to flag when they are done.
- added licenses to Image data type (to check if an Image is a Windows Image).
- added GetImage and GetImageFromProject to googlecompute Drivers.
- changed some of the builder/googlecompute tests to use github.com/stretchr/testify/assert.
Tests:
- (in the Packer directory) `go test .`, `go test ./builder/googlecompute`, and `go test ./post-processor/googlecompute-export`
- manual run of `packer build packer_template.json` with the following files
--packer_template.json--
{
"builders": [
{
"type": "googlecompute",
"account_file": "creds.json",
"project_id": "google.com:packer-test",
"source_image": "debian-8-jessie-v20160629",
"zone": "us-central1-a",
"startup_script_file": "startup_script.sh",
"metadata": {
"startup-script": "#!/bin/sh\necho \"This should be overwritten.\"",
"startup-script-log-dest": "gs://packer-test.google.com.a.appspot.com/startup-script.log"
},
"image_name": "test-packer-modifications",
"ssh_username": "foo"
}
],
"post-processors": [
{
"type": "googlecompute-export",
"paths": [
"gs://packer-test.google.com.a.appspot.com/foo.tar.gz",
"gs://packer-test.google.com.a.appspot.com/bar.tar.gz"
],
"keep_input_artifact": true
}
]
}
--startup_script.sh--
\#!/bin/sh
echo "Hi, my name is Scott. I'm waiting 60 seconds!" >> /scott
sleep 60
echo "I'm done waiting!" >> /scott
2016-09-07 22:00:30 -04:00
|
|
|
func (d *DriverMock) GetImage(name string) (*Image, error) {
|
|
|
|
d.GetImageName = name
|
|
|
|
return d.GetImageResult, d.GetImageErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *DriverMock) GetImageFromProject(project, name string) (*Image, error) {
|
|
|
|
d.GetImageFromProjectProject = project
|
|
|
|
d.GetImageFromProjectName = name
|
|
|
|
return d.GetImageFromProjectResult, d.GetImageFromProjectErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *DriverMock) GetInstanceMetadata(zone, name, key string) (string, error) {
|
|
|
|
d.GetInstanceMetadataZone = zone
|
|
|
|
d.GetInstanceMetadataName = name
|
|
|
|
d.GetInstanceMetadataKey = key
|
|
|
|
return d.GetInstanceMetadataResult, d.GetInstanceMetadataErr
|
|
|
|
}
|
|
|
|
|
2013-12-13 16:01:28 -05:00
|
|
|
func (d *DriverMock) GetNatIP(zone, name string) (string, error) {
|
|
|
|
d.GetNatIPZone = zone
|
|
|
|
d.GetNatIPName = name
|
|
|
|
return d.GetNatIPResult, d.GetNatIPErr
|
|
|
|
}
|
|
|
|
|
2015-05-29 17:50:11 -04:00
|
|
|
func (d *DriverMock) GetInternalIP(zone, name string) (string, error) {
|
|
|
|
d.GetInternalIPZone = zone
|
|
|
|
d.GetInternalIPName = name
|
|
|
|
return d.GetInternalIPResult, d.GetInternalIPErr
|
|
|
|
}
|
|
|
|
|
2016-05-24 20:13:36 -04:00
|
|
|
func (d *DriverMock) GetSerialPortOutput(zone, name string) (string, error) {
|
|
|
|
d.GetSerialPortOutputZone = zone
|
|
|
|
d.GetSerialPortOutputName = name
|
|
|
|
return d.GetSerialPortOutputResult, d.GetSerialPortOutputErr
|
|
|
|
}
|
|
|
|
|
Some googlecompute fixes and cleanup. Addresses https://github.com/mitchellh/packer/issues/3829. Changes:
- startup scripts don't run for Windows since it is isn't implemented yet.
- startup scripts use instance metadata instead of serial port output to flag when they are done.
- added licenses to Image data type (to check if an Image is a Windows Image).
- added GetImage and GetImageFromProject to googlecompute Drivers.
- changed some of the builder/googlecompute tests to use github.com/stretchr/testify/assert.
Tests:
- (in the Packer directory) `go test .`, `go test ./builder/googlecompute`, and `go test ./post-processor/googlecompute-export`
- manual run of `packer build packer_template.json` with the following files
--packer_template.json--
{
"builders": [
{
"type": "googlecompute",
"account_file": "creds.json",
"project_id": "google.com:packer-test",
"source_image": "debian-8-jessie-v20160629",
"zone": "us-central1-a",
"startup_script_file": "startup_script.sh",
"metadata": {
"startup-script": "#!/bin/sh\necho \"This should be overwritten.\"",
"startup-script-log-dest": "gs://packer-test.google.com.a.appspot.com/startup-script.log"
},
"image_name": "test-packer-modifications",
"ssh_username": "foo"
}
],
"post-processors": [
{
"type": "googlecompute-export",
"paths": [
"gs://packer-test.google.com.a.appspot.com/foo.tar.gz",
"gs://packer-test.google.com.a.appspot.com/bar.tar.gz"
],
"keep_input_artifact": true
}
]
}
--startup_script.sh--
\#!/bin/sh
echo "Hi, my name is Scott. I'm waiting 60 seconds!" >> /scott
sleep 60
echo "I'm done waiting!" >> /scott
2016-09-07 22:00:30 -04:00
|
|
|
func (d *DriverMock) ImageExists(name string) bool {
|
|
|
|
d.ImageExistsName = name
|
|
|
|
return d.ImageExistsResult
|
|
|
|
}
|
|
|
|
|
2013-12-13 00:38:34 -05:00
|
|
|
func (d *DriverMock) RunInstance(c *InstanceConfig) (<-chan error, error) {
|
|
|
|
d.RunInstanceConfig = c
|
|
|
|
|
|
|
|
resultCh := d.RunInstanceErrCh
|
|
|
|
if resultCh == nil {
|
|
|
|
ch := make(chan error)
|
|
|
|
close(ch)
|
|
|
|
resultCh = ch
|
|
|
|
}
|
|
|
|
|
|
|
|
return resultCh, d.RunInstanceErr
|
|
|
|
}
|
2013-12-13 16:01:28 -05:00
|
|
|
|
|
|
|
func (d *DriverMock) WaitForInstance(state, zone, name string) <-chan error {
|
|
|
|
d.WaitForInstanceState = state
|
|
|
|
d.WaitForInstanceZone = zone
|
|
|
|
d.WaitForInstanceName = name
|
|
|
|
|
|
|
|
resultCh := d.WaitForInstanceErrCh
|
|
|
|
if resultCh == nil {
|
|
|
|
ch := make(chan error)
|
|
|
|
close(ch)
|
|
|
|
resultCh = ch
|
|
|
|
}
|
|
|
|
|
|
|
|
return resultCh
|
|
|
|
}
|