mirror of
https://github.com/hashicorp/packer.git
synced 2026-02-22 01:10:18 -05:00
Merge remote-tracking branch 'upstream/master' into prestine
This commit is contained in:
commit
a61c869ca7
47 changed files with 275 additions and 104 deletions
9
Makefile
9
Makefile
|
|
@ -4,7 +4,7 @@ VET?=$(shell ls -d */ | grep -v vendor | grep -v website)
|
|||
GITSHA:=$(shell git rev-parse HEAD)
|
||||
# Get the current local branch name from git (if we can, this may be blank)
|
||||
GITBRANCH:=$(shell git symbolic-ref --short HEAD 2>/dev/null)
|
||||
GOFMT_FILES?=find . -path ./vendor -prune -o -name "*.go"
|
||||
GOFMT_FILES?=$$(find . -not -path "./vendor/*" -name "*.go")
|
||||
GOOS=$(shell go env GOOS)
|
||||
GOARCH=$(shell go env GOARCH)
|
||||
GOPATH=$(shell go env GOPATH)
|
||||
|
|
@ -58,13 +58,10 @@ dev: deps ## Build and install a development build
|
|||
@cp $(GOPATH)/bin/packer pkg/$(GOOS)_$(GOARCH)
|
||||
|
||||
fmt: ## Format Go code
|
||||
@$(GOFMT_FILES) | xargs gofmt -w -s
|
||||
@gofmt -w -s $(GOFMT_FILES)
|
||||
|
||||
fmt-check: ## Check go code formatting
|
||||
@echo "==> Checking that code complies with gofmt requirements..."
|
||||
@echo "You can use the command: \`make fmt\` to reformat code."
|
||||
@$(GOFMT_FILES) | xargs $(CURDIR)/scripts/gofmtcheck.sh
|
||||
@echo "Check complete."
|
||||
$(CURDIR)/scripts/gofmtcheck.sh $(GOFMT_FILES)
|
||||
|
||||
fmt-docs:
|
||||
@find ./website/source/docs -name "*.md" -exec pandoc --wrap auto --columns 79 --atx-headers -s -f "markdown_github+yaml_metadata_block" -t "markdown_github+yaml_metadata_block" {} -o {} \;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package ecs
|
|||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/helper/communicator"
|
||||
|
|
@ -68,6 +69,7 @@ func TestRunConfigPrepare_UserData(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
defer tf.Close()
|
||||
|
||||
c.UserData = "foo"
|
||||
|
|
@ -92,6 +94,7 @@ func TestRunConfigPrepare_UserDataFile(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
defer tf.Close()
|
||||
|
||||
c.UserDataFile = tf.Name()
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ func TestRunConfigPrepare_UserData(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
defer tf.Close()
|
||||
|
||||
c.UserData = "foo"
|
||||
|
|
@ -143,6 +144,7 @@ func TestRunConfigPrepare_UserDataFile(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
defer tf.Close()
|
||||
|
||||
c.UserDataFile = tf.Name()
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package ebs
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
awscommon "github.com/hashicorp/packer/builder/amazon/common"
|
||||
|
|
@ -52,7 +53,16 @@ func (s *stepCreateAMI) Run(_ context.Context, state multistep.StateBag) multist
|
|||
|
||||
ui.Say("Waiting for AMI to become ready...")
|
||||
if _, err := awscommon.WaitForState(&stateChange); err != nil {
|
||||
err := fmt.Errorf("Error waiting for AMI: %s", err)
|
||||
log.Printf("Error waiting for AMI: %s", err)
|
||||
imagesResp, err := ec2conn.DescribeImages(&ec2.DescribeImagesInput{ImageIds: []*string{createResp.ImageId}})
|
||||
if err != nil {
|
||||
log.Printf("Unable to determine reason waiting for AMI failed: %s", err)
|
||||
err = fmt.Errorf("Unknown error waiting for AMI.")
|
||||
} else {
|
||||
stateReason := imagesResp.Images[0].StateReason
|
||||
err = fmt.Errorf("Error waiting for AMI. Reason: %s", stateReason)
|
||||
}
|
||||
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@ import (
|
|||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
||||
func testConfig() map[string]interface{} {
|
||||
func testConfig() (config map[string]interface{}, tf *os.File) {
|
||||
tf, err := ioutil.TempFile("", "packer")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
config = map[string]interface{}{
|
||||
"account_id": "foo",
|
||||
"ami_name": "foo",
|
||||
"instance_type": "m1.small",
|
||||
|
|
@ -26,6 +26,8 @@ func testConfig() map[string]interface{} {
|
|||
"x509_key_path": tf.Name(),
|
||||
"x509_upload_path": "/foo",
|
||||
}
|
||||
|
||||
return config, tf
|
||||
}
|
||||
|
||||
func TestBuilder_ImplementsBuilder(t *testing.T) {
|
||||
|
|
@ -38,7 +40,9 @@ func TestBuilder_ImplementsBuilder(t *testing.T) {
|
|||
|
||||
func TestBuilderPrepare_AccountId(t *testing.T) {
|
||||
b := &Builder{}
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
config["account_id"] = ""
|
||||
warnings, err := b.Prepare(config)
|
||||
|
|
@ -74,7 +78,9 @@ func TestBuilderPrepare_AccountId(t *testing.T) {
|
|||
|
||||
func TestBuilderPrepare_AMIName(t *testing.T) {
|
||||
var b Builder
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
// Test good
|
||||
config["ami_name"] = "foo"
|
||||
|
|
@ -111,7 +117,9 @@ func TestBuilderPrepare_AMIName(t *testing.T) {
|
|||
|
||||
func TestBuilderPrepare_BundleDestination(t *testing.T) {
|
||||
b := &Builder{}
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
config["bundle_destination"] = ""
|
||||
warnings, err := b.Prepare(config)
|
||||
|
|
@ -129,7 +137,9 @@ func TestBuilderPrepare_BundleDestination(t *testing.T) {
|
|||
|
||||
func TestBuilderPrepare_BundlePrefix(t *testing.T) {
|
||||
b := &Builder{}
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
warnings, err := b.Prepare(config)
|
||||
if len(warnings) > 0 {
|
||||
|
|
@ -146,7 +156,9 @@ func TestBuilderPrepare_BundlePrefix(t *testing.T) {
|
|||
|
||||
func TestBuilderPrepare_InvalidKey(t *testing.T) {
|
||||
var b Builder
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
// Add a random key
|
||||
config["i_should_not_be_valid"] = true
|
||||
|
|
@ -161,7 +173,9 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
|
|||
|
||||
func TestBuilderPrepare_S3Bucket(t *testing.T) {
|
||||
b := &Builder{}
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
config["s3_bucket"] = ""
|
||||
warnings, err := b.Prepare(config)
|
||||
|
|
@ -184,7 +198,9 @@ func TestBuilderPrepare_S3Bucket(t *testing.T) {
|
|||
|
||||
func TestBuilderPrepare_X509CertPath(t *testing.T) {
|
||||
b := &Builder{}
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
config["x509_cert_path"] = ""
|
||||
warnings, err := b.Prepare(config)
|
||||
|
|
@ -209,6 +225,7 @@ func TestBuilderPrepare_X509CertPath(t *testing.T) {
|
|||
t.Fatalf("error tempfile: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
defer tf.Close()
|
||||
|
||||
config["x509_cert_path"] = tf.Name()
|
||||
warnings, err = b.Prepare(config)
|
||||
|
|
@ -222,7 +239,9 @@ func TestBuilderPrepare_X509CertPath(t *testing.T) {
|
|||
|
||||
func TestBuilderPrepare_X509KeyPath(t *testing.T) {
|
||||
b := &Builder{}
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
config["x509_key_path"] = ""
|
||||
warnings, err := b.Prepare(config)
|
||||
|
|
@ -247,6 +266,7 @@ func TestBuilderPrepare_X509KeyPath(t *testing.T) {
|
|||
t.Fatalf("error tempfile: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
defer tf.Close()
|
||||
|
||||
config["x509_key_path"] = tf.Name()
|
||||
warnings, err = b.Prepare(config)
|
||||
|
|
@ -260,7 +280,9 @@ func TestBuilderPrepare_X509KeyPath(t *testing.T) {
|
|||
|
||||
func TestBuilderPrepare_X509UploadPath(t *testing.T) {
|
||||
b := &Builder{}
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
config["x509_upload_path"] = ""
|
||||
warnings, err := b.Prepare(config)
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@
|
|||
"image": {
|
||||
"uri": "https://localhost/custom.vhd"
|
||||
},
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"osType": "Linux",
|
||||
"vhd": {
|
||||
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@
|
|||
"osDisk": {
|
||||
"caching": "ReadWrite",
|
||||
"createOption": "FromImage",
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"vhd": {
|
||||
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@
|
|||
"osDisk": {
|
||||
"caching": "ReadWrite",
|
||||
"createOption": "FromImage",
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"vhd": {
|
||||
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@
|
|||
"osDisk": {
|
||||
"caching": "ReadWrite",
|
||||
"createOption": "FromImage",
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"vhd": {
|
||||
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@
|
|||
"image": {
|
||||
"uri": "https://localhost/custom.vhd"
|
||||
},
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"osType": "Linux",
|
||||
"vhd": {
|
||||
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@
|
|||
"image": {
|
||||
"uri": "https://localhost/custom.vhd"
|
||||
},
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"osType": "Linux",
|
||||
"vhd": {
|
||||
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@
|
|||
"image": {
|
||||
"uri": "https://localhost/custom.vhd"
|
||||
},
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"osType": "Linux",
|
||||
"vhd": {
|
||||
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@
|
|||
"image": {
|
||||
"uri": "https://localhost/custom.vhd"
|
||||
},
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"osType": "Linux",
|
||||
"vhd": {
|
||||
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@
|
|||
"managedDisk": {
|
||||
"storageAccountType": "Standard_LRS"
|
||||
},
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"osType": "Linux"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@
|
|||
"managedDisk": {
|
||||
"storageAccountType": "Standard_LRS"
|
||||
},
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"osType": "Linux"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@
|
|||
"managedDisk": {
|
||||
"storageAccountType": "Standard_LRS"
|
||||
},
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"osType": "Linux"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@
|
|||
"osDisk": {
|
||||
"caching": "ReadWrite",
|
||||
"createOption": "FromImage",
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"vhd": {
|
||||
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@
|
|||
"managedDisk": {
|
||||
"storageAccountType": "Standard_LRS"
|
||||
},
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"osType": "Linux"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@
|
|||
"storageProfile": {
|
||||
"osDisk": {
|
||||
"osType": "Linux",
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"vhd": {
|
||||
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -111,7 +111,6 @@ func (s *TemplateBuilder) SetManagedDiskUrl(managedImageId string, storageAccoun
|
|||
profile.ImageReference = &compute.ImageReference{
|
||||
ID: &managedImageId,
|
||||
}
|
||||
profile.OsDisk.Name = to.StringPtr("osdisk")
|
||||
profile.OsDisk.OsType = s.osType
|
||||
profile.OsDisk.CreateOption = compute.FromImage
|
||||
profile.OsDisk.Vhd = nil
|
||||
|
|
@ -136,7 +135,6 @@ func (s *TemplateBuilder) SetManagedMarketplaceImage(location, publisher, offer,
|
|||
Version: &version,
|
||||
//ID: &imageID,
|
||||
}
|
||||
profile.OsDisk.Name = to.StringPtr("osdisk")
|
||||
profile.OsDisk.OsType = s.osType
|
||||
profile.OsDisk.CreateOption = compute.FromImage
|
||||
profile.OsDisk.Vhd = nil
|
||||
|
|
@ -583,7 +581,7 @@ const BasicTemplate = `{
|
|||
},
|
||||
"storageProfile": {
|
||||
"osDisk": {
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"vhd": {
|
||||
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@
|
|||
"osDisk": {
|
||||
"caching": "ReadWrite",
|
||||
"createOption": "FromImage",
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"vhd": {
|
||||
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@
|
|||
"image": {
|
||||
"uri": "http://azure/custom.vhd"
|
||||
},
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"osType": "Linux",
|
||||
"vhd": {
|
||||
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@
|
|||
"image": {
|
||||
"uri": "http://azure/custom.vhd"
|
||||
},
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"osType": "Linux",
|
||||
"vhd": {
|
||||
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@
|
|||
"osDisk": {
|
||||
"caching": "ReadWrite",
|
||||
"createOption": "FromImage",
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"vhd": {
|
||||
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@
|
|||
"managedDisk": {
|
||||
"storageAccountType": "Premium_LRS"
|
||||
},
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"osType": "Windows"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@
|
|||
"osDisk": {
|
||||
"caching": "ReadWrite",
|
||||
"createOption": "FromImage",
|
||||
"name": "osdisk",
|
||||
"name": "[parameters('osDiskName')]",
|
||||
"vhd": {
|
||||
"uri": "[concat(parameters('storageAccountBlobEndpoint'),variables('vmStorageAccountContainerName'),'/', parameters('osDiskName'),'.vhd')]"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package googlecompute
|
|||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
|
@ -199,7 +200,8 @@ func TestConfigPrepare(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
raw := testConfig(t)
|
||||
raw, tempfile := testConfig(t)
|
||||
defer os.Remove(tempfile)
|
||||
|
||||
if tc.Value == nil {
|
||||
delete(raw, tc.Key)
|
||||
|
|
@ -251,7 +253,8 @@ func TestConfigPrepareAccelerator(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
raw := testConfig(t)
|
||||
raw, tempfile := testConfig(t)
|
||||
defer os.Remove(tempfile)
|
||||
|
||||
errStr := ""
|
||||
for k := range tc.Keys {
|
||||
|
|
@ -300,7 +303,8 @@ func TestConfigPrepareServiceAccount(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
raw := testConfig(t)
|
||||
raw, tempfile := testConfig(t)
|
||||
defer os.Remove(tempfile)
|
||||
|
||||
errStr := ""
|
||||
for k := range tc.Keys {
|
||||
|
|
@ -342,7 +346,8 @@ func TestConfigDefaults(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
raw := testConfig(t)
|
||||
raw, tempfile := testConfig(t)
|
||||
defer os.Remove(tempfile)
|
||||
|
||||
c, warns, errs := NewConfig(raw)
|
||||
testConfigOk(t, warns, errs)
|
||||
|
|
@ -355,7 +360,10 @@ func TestConfigDefaults(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestImageName(t *testing.T) {
|
||||
c, _, _ := NewConfig(testConfig(t))
|
||||
raw, tempfile := testConfig(t)
|
||||
defer os.Remove(tempfile)
|
||||
|
||||
c, _, _ := NewConfig(raw)
|
||||
if !strings.HasPrefix(c.ImageName, "packer-") {
|
||||
t.Fatalf("ImageName should have 'packer-' prefix, found %s", c.ImageName)
|
||||
}
|
||||
|
|
@ -365,7 +373,10 @@ func TestImageName(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRegion(t *testing.T) {
|
||||
c, _, _ := NewConfig(testConfig(t))
|
||||
raw, tempfile := testConfig(t)
|
||||
defer os.Remove(tempfile)
|
||||
|
||||
c, _, _ := NewConfig(raw)
|
||||
if c.Region != "us-east1" {
|
||||
t.Fatalf("Region should be 'us-east1' given Zone of 'us-east1-a', but is %s", c.Region)
|
||||
}
|
||||
|
|
@ -373,9 +384,11 @@ func TestRegion(t *testing.T) {
|
|||
|
||||
// Helper stuff below
|
||||
|
||||
func testConfig(t *testing.T) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"account_file": testAccountFile(t),
|
||||
func testConfig(t *testing.T) (config map[string]interface{}, tempAccountFile string) {
|
||||
tempAccountFile = testAccountFile(t)
|
||||
|
||||
config = map[string]interface{}{
|
||||
"account_file": tempAccountFile,
|
||||
"project_id": "hashicorp",
|
||||
"source_image": "foo",
|
||||
"ssh_username": "root",
|
||||
|
|
@ -389,10 +402,15 @@ func testConfig(t *testing.T) map[string]interface{} {
|
|||
},
|
||||
"zone": "us-east1-a",
|
||||
}
|
||||
|
||||
return config, tempAccountFile
|
||||
}
|
||||
|
||||
func testConfigStruct(t *testing.T) *Config {
|
||||
c, warns, errs := NewConfig(testConfig(t))
|
||||
raw, tempfile := testConfig(t)
|
||||
defer os.Remove(tempfile)
|
||||
|
||||
c, warns, errs := NewConfig(raw)
|
||||
if len(warns) > 0 {
|
||||
t.Fatalf("bad: %#v", len(warns))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"google.golang.org/api/compute/v1"
|
||||
compute "google.golang.org/api/compute/v1"
|
||||
|
||||
"github.com/hashicorp/packer/common"
|
||||
"github.com/hashicorp/packer/helper/useragent"
|
||||
|
|
@ -168,7 +168,7 @@ func (d *driverGCE) DeleteDisk(zone, name string) (<-chan error, error) {
|
|||
}
|
||||
|
||||
func (d *driverGCE) GetImage(name string, fromFamily bool) (*Image, error) {
|
||||
projects := []string{d.projectId, "centos-cloud", "coreos-cloud", "cos-cloud", "debian-cloud", "google-containers", "opensuse-cloud", "rhel-cloud", "suse-cloud", "ubuntu-os-cloud", "windows-cloud", "gce-nvme"}
|
||||
projects := []string{d.projectId, "centos-cloud", "coreos-cloud", "cos-cloud", "debian-cloud", "google-containers", "opensuse-cloud", "rhel-cloud", "suse-cloud", "ubuntu-os-cloud", "windows-cloud", "gce-nvme", "windows-sql-cloud"}
|
||||
var errs error
|
||||
for _, project := range projects {
|
||||
image, err := d.GetImageFromProject(project, name, fromFamily)
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ func TestStepCreateSSHKey_debug(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
tf.Close()
|
||||
|
||||
state := testState(t)
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ func TestStepCreateOrResetWindowsPassword_debug(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
tf.Close()
|
||||
|
||||
state := testState(t)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ func TestIPAddress(t *testing.T) {
|
|||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
defer tf.Close()
|
||||
|
||||
d := Parallels9Driver{
|
||||
dhcpLeaseFile: tf.Name(),
|
||||
|
|
@ -62,9 +63,9 @@ func TestIPAddress(t *testing.T) {
|
|||
func TestXMLParseConfig(t *testing.T) {
|
||||
td, err := ioutil.TempDir("", "configpvs")
|
||||
if err != nil {
|
||||
t.Fatalf("Error creating temp file: %s", err)
|
||||
t.Fatalf("Error creating temp dir: %s", err)
|
||||
}
|
||||
defer os.Remove(td)
|
||||
defer os.RemoveAll(td)
|
||||
|
||||
config := []byte(`
|
||||
<ExampleParallelsConfig>
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ func TestStepOutputDir_impl(t *testing.T) {
|
|||
func TestStepOutputDir(t *testing.T) {
|
||||
state := testState(t)
|
||||
step := testStepOutputDir(t)
|
||||
// Delete the test output directory when done
|
||||
defer os.RemoveAll(step.Path)
|
||||
|
||||
// Test the run
|
||||
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
||||
|
|
|
|||
|
|
@ -217,6 +217,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
|||
}
|
||||
|
||||
errs = packer.MultiErrorAppend(errs, b.config.FloppyConfig.Prepare(&b.config.ctx)...)
|
||||
errs = packer.MultiErrorAppend(errs, b.config.VNCConfig.Prepare(&b.config.ctx)...)
|
||||
|
||||
if b.config.NetDevice == "" {
|
||||
b.config.NetDevice = "virtio-net"
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ func (s *stepTypeBootCommand) Run(ctx context.Context, state multistep.StateBag)
|
|||
}
|
||||
|
||||
// Wait the for the vm to boot.
|
||||
if int64(config.BootConfig.BootWait) > 0 {
|
||||
if int64(config.BootWait) > 0 {
|
||||
ui.Say(fmt.Sprintf("Waiting %s for boot...", config.BootWait.String()))
|
||||
select {
|
||||
case <-time.After(config.BootWait):
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ func commHost(state multistep.StateBag) (string, error) {
|
|||
|
||||
func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) {
|
||||
config := state.Get("config").(Config)
|
||||
var privateKey string
|
||||
|
||||
var auth []ssh.AuthMethod
|
||||
|
||||
|
|
@ -45,11 +44,9 @@ func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) {
|
|||
)
|
||||
}
|
||||
|
||||
if config.Comm.SSHPrivateKey != "" {
|
||||
if priv, ok := state.GetOk("privateKey"); ok {
|
||||
privateKey = priv.(string)
|
||||
}
|
||||
signer, err := ssh.ParsePrivateKey([]byte(privateKey))
|
||||
// Use key based auth if there is a private key in the state bag
|
||||
if privateKey, ok := state.GetOk("private_key"); ok {
|
||||
signer, err := ssh.ParsePrivateKey([]byte(privateKey.(string)))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error setting up SSH config: %s", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ func (s *stepCreateSSHKey) Run(_ context.Context, state multistep.StateBag) mult
|
|||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
state.Put("privateKey", string(privateKeyBytes))
|
||||
state.Put("private_key", string(privateKeyBytes))
|
||||
state.Put("ssh_pubkey", "")
|
||||
|
||||
return multistep.ActionContinue
|
||||
|
|
@ -61,7 +61,7 @@ func (s *stepCreateSSHKey) Run(_ context.Context, state multistep.StateBag) mult
|
|||
}
|
||||
|
||||
// Set the private key in the statebag for later
|
||||
state.Put("privateKey", string(pem.EncodeToMemory(&priv_blk)))
|
||||
state.Put("private_key", string(pem.EncodeToMemory(&priv_blk)))
|
||||
|
||||
pub, _ := ssh.NewPublicKey(&priv.PublicKey)
|
||||
pub_sshformat := string(ssh.MarshalAuthorizedKey(pub))
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ func TestStepOutputDir_impl(t *testing.T) {
|
|||
func TestStepOutputDir(t *testing.T) {
|
||||
state := testState(t)
|
||||
step := testStepOutputDir(t)
|
||||
defer os.RemoveAll(step.Path)
|
||||
|
||||
// Test the run
|
||||
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
||||
|
|
@ -55,6 +56,7 @@ func TestStepOutputDir_exists(t *testing.T) {
|
|||
if err := os.MkdirAll(step.Path, 0755); err != nil {
|
||||
t.Fatalf("bad: %s", err)
|
||||
}
|
||||
defer os.RemoveAll(step.Path)
|
||||
|
||||
// Test the run
|
||||
if action := step.Run(context.Background(), state); action != multistep.ActionHalt {
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ func TestStepOutputDir(t *testing.T) {
|
|||
step := new(StepOutputDir)
|
||||
|
||||
dir := testOutputDir(t)
|
||||
// Delete the test output directory when done
|
||||
defer os.RemoveAll(dir.dir)
|
||||
state.Put("dir", dir)
|
||||
|
||||
// Test the run
|
||||
|
|
@ -61,6 +63,7 @@ func TestStepOutputDir_existsNoForce(t *testing.T) {
|
|||
if err := os.MkdirAll(dir.dir, 0755); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
defer os.RemoveAll(dir.dir)
|
||||
|
||||
// Test the run
|
||||
if action := step.Run(context.Background(), state); action != multistep.ActionHalt {
|
||||
|
|
@ -89,6 +92,7 @@ func TestStepOutputDir_existsForce(t *testing.T) {
|
|||
if err := os.MkdirAll(dir.dir, 0755); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
defer os.RemoveAll(dir.dir)
|
||||
|
||||
// Test the run
|
||||
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
||||
|
|
|
|||
|
|
@ -85,6 +85,12 @@ func TestStepShutdown_command(t *testing.T) {
|
|||
if comm.StartCmd.Command != "foo" {
|
||||
t.Fatalf("bad: %#v", comm.StartCmd.Command)
|
||||
}
|
||||
|
||||
// Clean up the created test output directory
|
||||
dir := state.Get("dir").(*LocalOutputDir)
|
||||
if err := dir.RemoveAll(); err != nil {
|
||||
t.Fatalf("Error cleaning up directory: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStepShutdown_noCommand(t *testing.T) {
|
||||
|
|
@ -113,6 +119,12 @@ func TestStepShutdown_noCommand(t *testing.T) {
|
|||
if comm.StartCalled {
|
||||
t.Fatal("start should not be called")
|
||||
}
|
||||
|
||||
// Clean up the created test output directory
|
||||
dir := state.Get("dir").(*LocalOutputDir)
|
||||
if err := dir.RemoveAll(); err != nil {
|
||||
t.Fatalf("Error cleaning up directory: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStepShutdown_locks(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ func TestDownloadClient_basic(t *testing.T) {
|
|||
TargetPath: tf.Name(),
|
||||
CopyFile: true,
|
||||
})
|
||||
defer os.Remove(tf.Name())
|
||||
|
||||
path, err := client.Get()
|
||||
if err != nil {
|
||||
|
|
@ -96,6 +97,7 @@ func TestDownloadClient_checksumBad(t *testing.T) {
|
|||
Checksum: checksum,
|
||||
CopyFile: true,
|
||||
})
|
||||
defer os.Remove(tf.Name())
|
||||
if _, err := client.Get(); err == nil {
|
||||
t.Fatal("should error")
|
||||
}
|
||||
|
|
@ -121,6 +123,7 @@ func TestDownloadClient_checksumGood(t *testing.T) {
|
|||
Checksum: checksum,
|
||||
CopyFile: true,
|
||||
})
|
||||
defer os.Remove(tf.Name())
|
||||
path, err := client.Get()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
|
|
@ -191,6 +194,7 @@ func TestDownloadClient_resume(t *testing.T) {
|
|||
TargetPath: tf.Name(),
|
||||
CopyFile: true,
|
||||
})
|
||||
defer os.Remove(tf.Name())
|
||||
path, err := client.Get()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
|
|
@ -211,7 +215,8 @@ func TestDownloadClient_usesDefaultUserAgent(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("tempfile error: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
tf.Close()
|
||||
os.Remove(tf.Name())
|
||||
|
||||
defaultUserAgent := ""
|
||||
asserted := false
|
||||
|
|
@ -249,6 +254,7 @@ func TestDownloadClient_usesDefaultUserAgent(t *testing.T) {
|
|||
TargetPath: tf.Name(),
|
||||
CopyFile: true,
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
|
||||
client := NewDownloadClient(config)
|
||||
_, err = client.Get()
|
||||
|
|
@ -266,7 +272,8 @@ func TestDownloadClient_setsUserAgent(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("tempfile error: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
tf.Close()
|
||||
os.Remove(tf.Name())
|
||||
|
||||
asserted := false
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -281,6 +288,7 @@ func TestDownloadClient_setsUserAgent(t *testing.T) {
|
|||
UserAgent: "fancy user agent",
|
||||
CopyFile: true,
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
|
||||
client := NewDownloadClient(config)
|
||||
_, err = client.Get()
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
|
@ -90,6 +91,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
|
|||
i = testISOConfig()
|
||||
i.ISOChecksum = ""
|
||||
cs_file, _ := ioutil.TempFile("", "packer-test-")
|
||||
defer os.Remove(cs_file.Name())
|
||||
defer cs_file.Close()
|
||||
ioutil.WriteFile(cs_file.Name(), []byte(cs_bsd_style), 0666)
|
||||
filePrefix := "file://"
|
||||
if runtime.GOOS == "windows" {
|
||||
|
|
@ -112,6 +115,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
|
|||
i = testISOConfig()
|
||||
i.ISOChecksum = ""
|
||||
cs_file, _ = ioutil.TempFile("", "packer-test-")
|
||||
defer os.Remove(cs_file.Name())
|
||||
defer cs_file.Close()
|
||||
ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style), 0666)
|
||||
i.ISOChecksumURL = fmt.Sprintf("%s%s", filePrefix, cs_file.Name())
|
||||
warns, err = i.Prepare(nil)
|
||||
|
|
@ -130,6 +135,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
|
|||
i = testISOConfig()
|
||||
i.ISOChecksum = ""
|
||||
cs_file, _ = ioutil.TempFile("", "packer-test-")
|
||||
defer os.Remove(cs_file.Name())
|
||||
defer cs_file.Close()
|
||||
ioutil.WriteFile(cs_file.Name(), []byte(cs_bsd_style_no_newline), 0666)
|
||||
i.ISOChecksumURL = fmt.Sprintf("file://%s", cs_file.Name())
|
||||
warns, err = i.Prepare(nil)
|
||||
|
|
@ -150,6 +157,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
|
|||
|
||||
cs_dir, _ := ioutil.TempDir("", "packer-testdir-")
|
||||
cs_file, _ = ioutil.TempFile(cs_dir, "packer-test-")
|
||||
defer os.RemoveAll(cs_dir) // Removes the file as well
|
||||
defer cs_file.Close()
|
||||
ioutil.WriteFile(cs_file.Name(), []byte(cs_bsd_style_subdir), 0666)
|
||||
i.ISOChecksumURL = fmt.Sprintf("%s%s", filePrefix, cs_file.Name())
|
||||
i.RawSingleISOUrl = fmt.Sprintf("%s%s", cs_dir, "/subdir/the-OS.iso")
|
||||
|
|
@ -169,6 +178,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
|
|||
i = testISOConfig()
|
||||
i.ISOChecksum = ""
|
||||
cs_file, _ = ioutil.TempFile("", "packer-test-")
|
||||
defer os.Remove(cs_file.Name())
|
||||
defer cs_file.Close()
|
||||
ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style_no_newline), 0666)
|
||||
i.ISOChecksumURL = fmt.Sprintf("file://%s", cs_file.Name())
|
||||
warns, err = i.Prepare(nil)
|
||||
|
|
@ -189,6 +200,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
|
|||
i.RawSingleISOUrl = "http://www.packer.io/the-OS.iso?stuff=boo"
|
||||
|
||||
cs_file, _ = ioutil.TempFile("", "packer-test-")
|
||||
defer os.Remove(cs_file.Name())
|
||||
defer cs_file.Close()
|
||||
ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style), 0666)
|
||||
i.ISOChecksumURL = fmt.Sprintf("%s%s", filePrefix, cs_file.Name())
|
||||
warns, err = i.Prepare(nil)
|
||||
|
|
@ -208,6 +221,8 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
|
|||
i.ISOChecksum = ""
|
||||
|
||||
cs_file, _ = ioutil.TempFile(cs_dir, "packer-test-")
|
||||
defer os.Remove(cs_file.Name())
|
||||
defer cs_file.Close()
|
||||
ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style_subdir), 0666)
|
||||
i.ISOChecksumURL = fmt.Sprintf("%s%s", filePrefix, cs_file.Name())
|
||||
i.RawSingleISOUrl = fmt.Sprintf("%s%s", cs_dir, "/subdir/the-OS.iso")
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
//"log"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
|
@ -30,6 +29,7 @@ func TestProvisionerPrepare_extractScript(t *testing.T) {
|
|||
p := new(Provisioner)
|
||||
_ = p.Prepare(config)
|
||||
file, err := extractScript(p)
|
||||
defer os.Remove(file)
|
||||
if err != nil {
|
||||
t.Fatalf("Should not be error: %s", err)
|
||||
}
|
||||
|
|
@ -177,6 +177,7 @@ func TestProvisionerPrepare_Script(t *testing.T) {
|
|||
t.Fatalf("error tempfile: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
defer tf.Close()
|
||||
|
||||
config["script"] = tf.Name()
|
||||
p = new(Provisioner)
|
||||
|
|
@ -203,6 +204,7 @@ func TestProvisionerPrepare_ScriptAndInline(t *testing.T) {
|
|||
t.Fatalf("error tempfile: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
defer tf.Close()
|
||||
|
||||
config["inline"] = []interface{}{"foo"}
|
||||
config["script"] = tf.Name()
|
||||
|
|
@ -222,6 +224,7 @@ func TestProvisionerPrepare_ScriptAndScripts(t *testing.T) {
|
|||
t.Fatalf("error tempfile: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
defer tf.Close()
|
||||
|
||||
config["inline"] = []interface{}{"foo"}
|
||||
config["scripts"] = []string{tf.Name()}
|
||||
|
|
@ -248,6 +251,7 @@ func TestProvisionerPrepare_Scripts(t *testing.T) {
|
|||
t.Fatalf("error tempfile: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
defer tf.Close()
|
||||
|
||||
config["scripts"] = []string{tf.Name()}
|
||||
p = new(Provisioner)
|
||||
|
|
@ -444,6 +448,8 @@ func TestProvisionerProvision_Inline(t *testing.T) {
|
|||
func TestProvisionerProvision_Scripts(t *testing.T) {
|
||||
tempFile, _ := ioutil.TempFile("", "packer")
|
||||
defer os.Remove(tempFile.Name())
|
||||
defer tempFile.Close()
|
||||
|
||||
config := testConfig()
|
||||
delete(config, "inline")
|
||||
config["scripts"] = []string{tempFile.Name()}
|
||||
|
|
@ -473,6 +479,8 @@ func TestProvisionerProvision_ScriptsWithEnvVars(t *testing.T) {
|
|||
config := testConfig()
|
||||
ui := testUi()
|
||||
defer os.Remove(tempFile.Name())
|
||||
defer tempFile.Close()
|
||||
|
||||
delete(config, "inline")
|
||||
|
||||
config["scripts"] = []string{tempFile.Name()}
|
||||
|
|
|
|||
|
|
@ -13,15 +13,17 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func testConfig() map[string]interface{} {
|
||||
func testConfig() (config map[string]interface{}, tf *os.File) {
|
||||
tf, err := ioutil.TempFile("", "packer")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
config = map[string]interface{}{
|
||||
"manifest_file": tf.Name(),
|
||||
}
|
||||
|
||||
return config, tf
|
||||
}
|
||||
|
||||
func TestProvisioner_Impl(t *testing.T) {
|
||||
|
|
@ -33,7 +35,10 @@ func TestProvisioner_Impl(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGuestOSConfig_empty_unix(t *testing.T) {
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
p := new(Provisioner)
|
||||
err := p.Prepare(config)
|
||||
if err != nil {
|
||||
|
|
@ -58,7 +63,10 @@ func TestGuestOSConfig_empty_unix(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGuestOSConfig_full_unix(t *testing.T) {
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
p := new(Provisioner)
|
||||
err := p.Prepare(config)
|
||||
if err != nil {
|
||||
|
|
@ -95,7 +103,10 @@ func TestGuestOSConfig_full_unix(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGuestOSConfig_empty_windows(t *testing.T) {
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
config["guest_os_type"] = "windows"
|
||||
p := new(Provisioner)
|
||||
err := p.Prepare(config)
|
||||
|
|
@ -120,7 +131,10 @@ func TestGuestOSConfig_empty_windows(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGuestOSConfig_full_windows(t *testing.T) {
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
config["guest_os_type"] = "windows"
|
||||
p := new(Provisioner)
|
||||
err := p.Prepare(config)
|
||||
|
|
@ -158,7 +172,9 @@ func TestGuestOSConfig_full_windows(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProvisionerPrepare_puppetBinDir(t *testing.T) {
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
delete(config, "puppet_bin_dir")
|
||||
p := new(Provisioner)
|
||||
|
|
@ -183,7 +199,9 @@ func TestProvisionerPrepare_puppetBinDir(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProvisionerPrepare_hieraConfigPath(t *testing.T) {
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
delete(config, "hiera_config_path")
|
||||
p := new(Provisioner)
|
||||
|
|
@ -208,7 +226,9 @@ func TestProvisionerPrepare_hieraConfigPath(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProvisionerPrepare_manifestFile(t *testing.T) {
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
delete(config, "manifest_file")
|
||||
p := new(Provisioner)
|
||||
|
|
@ -233,7 +253,9 @@ func TestProvisionerPrepare_manifestFile(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProvisionerPrepare_manifestDir(t *testing.T) {
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
delete(config, "manifestdir")
|
||||
p := new(Provisioner)
|
||||
|
|
@ -258,7 +280,9 @@ func TestProvisionerPrepare_manifestDir(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProvisionerPrepare_modulePaths(t *testing.T) {
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
delete(config, "module_paths")
|
||||
p := new(Provisioner)
|
||||
|
|
@ -291,7 +315,9 @@ func TestProvisionerPrepare_modulePaths(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProvisionerPrepare_facterFacts(t *testing.T) {
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
delete(config, "facter")
|
||||
p := new(Provisioner)
|
||||
|
|
@ -346,7 +372,9 @@ func TestProvisionerPrepare_facterFacts(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProvisionerPrepare_extraArguments(t *testing.T) {
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
// Test with missing parameter
|
||||
delete(config, "extra_arguments")
|
||||
|
|
@ -377,7 +405,9 @@ func TestProvisionerPrepare_extraArguments(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProvisionerPrepare_stagingDir(t *testing.T) {
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
delete(config, "staging_directory")
|
||||
p := new(Provisioner)
|
||||
|
|
@ -405,7 +435,9 @@ func TestProvisionerPrepare_stagingDir(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProvisionerPrepare_workingDir(t *testing.T) {
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
delete(config, "working_directory")
|
||||
p := new(Provisioner)
|
||||
|
|
@ -438,7 +470,10 @@ func TestProvisionerPrepare_workingDir(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProvisionerProvision_extraArguments(t *testing.T) {
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
ui := &packer.MachineReadableUi{
|
||||
Writer: ioutil.Discard,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,15 +8,17 @@ import (
|
|||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
||||
func testConfig() map[string]interface{} {
|
||||
func testConfig() (config map[string]interface{}, tf *os.File) {
|
||||
tf, err := ioutil.TempFile("", "packer")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
config = map[string]interface{}{
|
||||
"puppet_server": tf.Name(),
|
||||
}
|
||||
|
||||
return config, tf
|
||||
}
|
||||
|
||||
func TestProvisioner_Impl(t *testing.T) {
|
||||
|
|
@ -28,7 +30,9 @@ func TestProvisioner_Impl(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProvisionerPrepare_puppetBinDir(t *testing.T) {
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
delete(config, "puppet_bin_dir")
|
||||
p := new(Provisioner)
|
||||
|
|
@ -53,7 +57,9 @@ func TestProvisionerPrepare_puppetBinDir(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProvisionerPrepare_clientPrivateKeyPath(t *testing.T) {
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
delete(config, "client_private_key_path")
|
||||
p := new(Provisioner)
|
||||
|
|
@ -86,7 +92,9 @@ func TestProvisionerPrepare_clientPrivateKeyPath(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProvisionerPrepare_clientCertPath(t *testing.T) {
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
delete(config, "client_cert_path")
|
||||
p := new(Provisioner)
|
||||
|
|
@ -119,7 +127,9 @@ func TestProvisionerPrepare_clientCertPath(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProvisionerPrepare_executeCommand(t *testing.T) {
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
delete(config, "execute_command")
|
||||
p := new(Provisioner)
|
||||
|
|
@ -130,7 +140,9 @@ func TestProvisionerPrepare_executeCommand(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProvisionerPrepare_facterFacts(t *testing.T) {
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
delete(config, "facter")
|
||||
p := new(Provisioner)
|
||||
|
|
@ -185,7 +197,9 @@ func TestProvisionerPrepare_facterFacts(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProvisionerPrepare_stagingDir(t *testing.T) {
|
||||
config := testConfig()
|
||||
config, tempfile := testConfig()
|
||||
defer os.Remove(tempfile.Name())
|
||||
defer tempfile.Close()
|
||||
|
||||
delete(config, "staging_dir")
|
||||
p := new(Provisioner)
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ func TestProvisionerPrepare_extractScript(t *testing.T) {
|
|||
p := new(Provisioner)
|
||||
_ = p.Prepare(config)
|
||||
file, err := extractScript(p)
|
||||
defer os.Remove(file)
|
||||
if err != nil {
|
||||
t.Fatalf("Should not be error: %s", err)
|
||||
}
|
||||
|
|
@ -104,6 +105,7 @@ func TestProvisionerPrepare_Script(t *testing.T) {
|
|||
t.Fatalf("error tempfile: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
defer tf.Close()
|
||||
|
||||
config["script"] = tf.Name()
|
||||
p = new(Provisioner)
|
||||
|
|
@ -130,6 +132,7 @@ func TestProvisionerPrepare_ScriptAndInline(t *testing.T) {
|
|||
t.Fatalf("error tempfile: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
defer tf.Close()
|
||||
|
||||
config["inline"] = []interface{}{"foo"}
|
||||
config["script"] = tf.Name()
|
||||
|
|
@ -149,6 +152,7 @@ func TestProvisionerPrepare_ScriptAndScripts(t *testing.T) {
|
|||
t.Fatalf("error tempfile: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
defer tf.Close()
|
||||
|
||||
config["inline"] = []interface{}{"foo"}
|
||||
config["scripts"] = []string{tf.Name()}
|
||||
|
|
@ -175,6 +179,7 @@ func TestProvisionerPrepare_Scripts(t *testing.T) {
|
|||
t.Fatalf("error tempfile: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
defer tf.Close()
|
||||
|
||||
config["scripts"] = []string{tf.Name()}
|
||||
p = new(Provisioner)
|
||||
|
|
@ -322,11 +327,16 @@ func TestProvisionerProvision_Inline(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProvisionerProvision_Scripts(t *testing.T) {
|
||||
tempFile, _ := ioutil.TempFile("", "packer")
|
||||
defer os.Remove(tempFile.Name())
|
||||
tf, err := ioutil.TempFile("", "packer")
|
||||
if err != nil {
|
||||
t.Fatalf("error tempfile: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
defer tf.Close()
|
||||
|
||||
config := testConfig()
|
||||
delete(config, "inline")
|
||||
config["scripts"] = []string{tempFile.Name()}
|
||||
config["scripts"] = []string{tf.Name()}
|
||||
config["packer_build_name"] = "foobuild"
|
||||
config["packer_builder_type"] = "footype"
|
||||
ui := testUi()
|
||||
|
|
@ -334,7 +344,7 @@ func TestProvisionerProvision_Scripts(t *testing.T) {
|
|||
p := new(Provisioner)
|
||||
comm := new(packer.MockCommunicator)
|
||||
p.Prepare(config)
|
||||
err := p.Provision(ui, comm)
|
||||
err = p.Provision(ui, comm)
|
||||
if err != nil {
|
||||
t.Fatal("should not have error")
|
||||
}
|
||||
|
|
@ -349,13 +359,18 @@ func TestProvisionerProvision_Scripts(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProvisionerProvision_ScriptsWithEnvVars(t *testing.T) {
|
||||
tempFile, _ := ioutil.TempFile("", "packer")
|
||||
tf, err := ioutil.TempFile("", "packer")
|
||||
if err != nil {
|
||||
t.Fatalf("error tempfile: %s", err)
|
||||
}
|
||||
defer os.Remove(tf.Name())
|
||||
defer tf.Close()
|
||||
|
||||
config := testConfig()
|
||||
ui := testUi()
|
||||
defer os.Remove(tempFile.Name())
|
||||
delete(config, "inline")
|
||||
|
||||
config["scripts"] = []string{tempFile.Name()}
|
||||
config["scripts"] = []string{tf.Name()}
|
||||
config["packer_build_name"] = "foobuild"
|
||||
config["packer_builder_type"] = "footype"
|
||||
|
||||
|
|
@ -368,7 +383,7 @@ func TestProvisionerProvision_ScriptsWithEnvVars(t *testing.T) {
|
|||
p := new(Provisioner)
|
||||
comm := new(packer.MockCommunicator)
|
||||
p.Prepare(config)
|
||||
err := p.Provision(ui, comm)
|
||||
err = p.Provision(ui, comm)
|
||||
if err != nil {
|
||||
t.Fatal("should not have error")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,14 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
for f in $@; do
|
||||
[ -n "`dos2unix 2>/dev/null < $f | gofmt -s -d`" ] && echo $f
|
||||
done
|
||||
# Check gofmt
|
||||
echo "==> Checking that code complies with gofmt requirements..."
|
||||
gofmt_files=$(gofmt -s -l ${@})
|
||||
if [[ -n ${gofmt_files} ]]; then
|
||||
echo 'gofmt needs running on the following files:'
|
||||
echo "${gofmt_files}"
|
||||
echo "You can use the command: \`make fmt\` to reformat code."
|
||||
exit 1
|
||||
fi
|
||||
echo "Check passed."
|
||||
|
||||
# always return success or else 'make' will abort
|
||||
exit 0
|
||||
|
|
|
|||
1
vendor/vendor.json
vendored
1
vendor/vendor.json
vendored
|
|
@ -1013,7 +1013,6 @@
|
|||
{
|
||||
"checksumSHA1": "UIqCj7qI0hhIMpAhS9YYqs2jD48=",
|
||||
"path": "github.com/mitchellh/cli",
|
||||
|
||||
"revision": "65fcae5817c8600da98ada9d7edf26dd1a84837b",
|
||||
"revisionTime": "2017-09-08T18:10:43Z"
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue