packer-cn/provisioner/powershell/provisioner_acc_test.go

96 lines
2.7 KiB
Go
Raw Normal View History

package powershell_test
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/hashicorp/go-uuid"
"github.com/hashicorp/packer/command"
"github.com/hashicorp/packer/helper/tests/acc"
"github.com/hashicorp/packer/packer"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
test/provisioner/powershell: Add acceptance test for powershell provisioner cleanup Passing Tests ``` --- PASS: TestAccPowershellProvisioner_basic (282.02s) --- PASS: TestAccPowershellProvisioner_basic/testing_amazon-ebs_builder_against_powershell_provisioner (282.01s) PASS ok github.com/hashicorp/packer/provisioner/powershell 282.046s ``` Failing tests on master ``` 2020/04/08 09:59:34 Uploading file to 'c:/Windows/Temp/script.bat' 2020/04/08 09:59:36 [INFO] starting remote command: set "PACKER_BUILDER_TYPE=amazon-ebs" && set "PACKER_BUILD_NAME=amazon-ebs" && "c:/Windows/Temp/script.bat" 2020/04/08 09:59:36 ui: amazon-ebs: 2020/04/08 09:59:36 ui: amazon-ebs: C:\Users\Administrator>dir C:\Windows\Temp\packer-*.ps1 2020/04/08 09:59:36 ui: amazon-ebs: Volume in drive C has no label. 2020/04/08 09:59:36 [INFO] command 'set "PACKER_BUILDER_TYPE=amazon-ebs" && set "PACKER_BUILD_NAME=amazon-ebs" && "c:/Windows/Temp/script.bat"' exited with code: 0 2020/04/08 09:59:36 ui: amazon-ebs: Volume Serial Number is 46CA-4083 2020/04/08 09:59:36 ui: amazon-ebs: 2020/04/08 09:59:36 ui: amazon-ebs: Directory of C:\Windows\Temp 2020/04/08 09:59:36 ui: amazon-ebs: 2020/04/08 09:59:36 ui: amazon-ebs: 04/08/2020 01:59 PM 102 packer-acc-test-script-test.ps1 2020/04/08 09:59:36 ui: amazon-ebs: 04/08/2020 01:59 PM 76 packer-acc-test-vars.ps1 2020/04/08 09:59:36 ui: amazon-ebs: 2 File(s) 178 bytes 2020/04/08 09:59:36 ui: amazon-ebs: 0 Dir(s) 9,735,806,976 bytes free 2020/04/08 09:59:36 ui: ==> amazon-ebs: Provisioning step had errors: Running the cleanup provisioner, if present... 2020/04/08 09:59:36 ui: ==> amazon-ebs: Terminating the source AWS instance... 2020/04/08 10:00:09 ui: ==> amazon-ebs: Cleaning up any extra volumes... 2020/04/08 10:00:09 ui: ==> amazon-ebs: No volumes to clean up, skipping 2020/04/08 10:00:09 ui: ==> amazon-ebs: Deleting temporary security group... 2020/04/08 10:00:10 ui: ==> amazon-ebs: Deleting temporary keypair... 2020/04/08 10:00:11 ui error: Build 'amazon-ebs' errored: Script exited with non-zero exit status: 0.Allowed exit codes are: [1] 2020/04/08 10:00:11 machine readable: error-count []string{"1"} 2020/04/08 10:00:11 ui error: ==> Some builds didn't complete successfully and had errors: 2020/04/08 10:00:11 machine readable: amazon-ebs,error []string{"Script exited with non-zero exit status: 0.Allowed exit codes are: [1]"} 2020/04/08 10:00:11 ui error: --> amazon-ebs: Script exited with non-zero exit status: 0.Allowed exit codes are: [1] ``` test: Fix windows-shell command
2020-04-07 15:03:58 -04:00
"github.com/hashicorp/packer/provisioner/powershell"
windowsshellprovisioner "github.com/hashicorp/packer/provisioner/windows-shell"
)
const TestProvisionerName = "powershell"
test/provisioner/powershell: Add acceptance test for powershell provisioner cleanup Passing Tests ``` --- PASS: TestAccPowershellProvisioner_basic (282.02s) --- PASS: TestAccPowershellProvisioner_basic/testing_amazon-ebs_builder_against_powershell_provisioner (282.01s) PASS ok github.com/hashicorp/packer/provisioner/powershell 282.046s ``` Failing tests on master ``` 2020/04/08 09:59:34 Uploading file to 'c:/Windows/Temp/script.bat' 2020/04/08 09:59:36 [INFO] starting remote command: set "PACKER_BUILDER_TYPE=amazon-ebs" && set "PACKER_BUILD_NAME=amazon-ebs" && "c:/Windows/Temp/script.bat" 2020/04/08 09:59:36 ui: amazon-ebs: 2020/04/08 09:59:36 ui: amazon-ebs: C:\Users\Administrator>dir C:\Windows\Temp\packer-*.ps1 2020/04/08 09:59:36 ui: amazon-ebs: Volume in drive C has no label. 2020/04/08 09:59:36 [INFO] command 'set "PACKER_BUILDER_TYPE=amazon-ebs" && set "PACKER_BUILD_NAME=amazon-ebs" && "c:/Windows/Temp/script.bat"' exited with code: 0 2020/04/08 09:59:36 ui: amazon-ebs: Volume Serial Number is 46CA-4083 2020/04/08 09:59:36 ui: amazon-ebs: 2020/04/08 09:59:36 ui: amazon-ebs: Directory of C:\Windows\Temp 2020/04/08 09:59:36 ui: amazon-ebs: 2020/04/08 09:59:36 ui: amazon-ebs: 04/08/2020 01:59 PM 102 packer-acc-test-script-test.ps1 2020/04/08 09:59:36 ui: amazon-ebs: 04/08/2020 01:59 PM 76 packer-acc-test-vars.ps1 2020/04/08 09:59:36 ui: amazon-ebs: 2 File(s) 178 bytes 2020/04/08 09:59:36 ui: amazon-ebs: 0 Dir(s) 9,735,806,976 bytes free 2020/04/08 09:59:36 ui: ==> amazon-ebs: Provisioning step had errors: Running the cleanup provisioner, if present... 2020/04/08 09:59:36 ui: ==> amazon-ebs: Terminating the source AWS instance... 2020/04/08 10:00:09 ui: ==> amazon-ebs: Cleaning up any extra volumes... 2020/04/08 10:00:09 ui: ==> amazon-ebs: No volumes to clean up, skipping 2020/04/08 10:00:09 ui: ==> amazon-ebs: Deleting temporary security group... 2020/04/08 10:00:10 ui: ==> amazon-ebs: Deleting temporary keypair... 2020/04/08 10:00:11 ui error: Build 'amazon-ebs' errored: Script exited with non-zero exit status: 0.Allowed exit codes are: [1] 2020/04/08 10:00:11 machine readable: error-count []string{"1"} 2020/04/08 10:00:11 ui error: ==> Some builds didn't complete successfully and had errors: 2020/04/08 10:00:11 machine readable: amazon-ebs,error []string{"Script exited with non-zero exit status: 0.Allowed exit codes are: [1]"} 2020/04/08 10:00:11 ui error: --> amazon-ebs: Script exited with non-zero exit status: 0.Allowed exit codes are: [1] ``` test: Fix windows-shell command
2020-04-07 15:03:58 -04:00
func TestAccPowershellProvisioner_basic(t *testing.T) {
acc.TestProvisionersPreCheck(TestProvisionerName, t)
testProvisioner := PowershellProvisionerAccTest{"powershell-provisioner-cleanup.txt"}
acc.TestProvisionersAgainstBuilders(&testProvisioner, t)
}
func TestAccPowershellProvisioner_Inline(t *testing.T) {
acc.TestProvisionersPreCheck(TestProvisionerName, t)
testProvisioner := PowershellProvisionerAccTest{"powershell-inline-provisioner.txt"}
acc.TestProvisionersAgainstBuilders(&testProvisioner, t)
}
test/provisioner/powershell: Add acceptance test for powershell provisioner cleanup Passing Tests ``` --- PASS: TestAccPowershellProvisioner_basic (282.02s) --- PASS: TestAccPowershellProvisioner_basic/testing_amazon-ebs_builder_against_powershell_provisioner (282.01s) PASS ok github.com/hashicorp/packer/provisioner/powershell 282.046s ``` Failing tests on master ``` 2020/04/08 09:59:34 Uploading file to 'c:/Windows/Temp/script.bat' 2020/04/08 09:59:36 [INFO] starting remote command: set "PACKER_BUILDER_TYPE=amazon-ebs" && set "PACKER_BUILD_NAME=amazon-ebs" && "c:/Windows/Temp/script.bat" 2020/04/08 09:59:36 ui: amazon-ebs: 2020/04/08 09:59:36 ui: amazon-ebs: C:\Users\Administrator>dir C:\Windows\Temp\packer-*.ps1 2020/04/08 09:59:36 ui: amazon-ebs: Volume in drive C has no label. 2020/04/08 09:59:36 [INFO] command 'set "PACKER_BUILDER_TYPE=amazon-ebs" && set "PACKER_BUILD_NAME=amazon-ebs" && "c:/Windows/Temp/script.bat"' exited with code: 0 2020/04/08 09:59:36 ui: amazon-ebs: Volume Serial Number is 46CA-4083 2020/04/08 09:59:36 ui: amazon-ebs: 2020/04/08 09:59:36 ui: amazon-ebs: Directory of C:\Windows\Temp 2020/04/08 09:59:36 ui: amazon-ebs: 2020/04/08 09:59:36 ui: amazon-ebs: 04/08/2020 01:59 PM 102 packer-acc-test-script-test.ps1 2020/04/08 09:59:36 ui: amazon-ebs: 04/08/2020 01:59 PM 76 packer-acc-test-vars.ps1 2020/04/08 09:59:36 ui: amazon-ebs: 2 File(s) 178 bytes 2020/04/08 09:59:36 ui: amazon-ebs: 0 Dir(s) 9,735,806,976 bytes free 2020/04/08 09:59:36 ui: ==> amazon-ebs: Provisioning step had errors: Running the cleanup provisioner, if present... 2020/04/08 09:59:36 ui: ==> amazon-ebs: Terminating the source AWS instance... 2020/04/08 10:00:09 ui: ==> amazon-ebs: Cleaning up any extra volumes... 2020/04/08 10:00:09 ui: ==> amazon-ebs: No volumes to clean up, skipping 2020/04/08 10:00:09 ui: ==> amazon-ebs: Deleting temporary security group... 2020/04/08 10:00:10 ui: ==> amazon-ebs: Deleting temporary keypair... 2020/04/08 10:00:11 ui error: Build 'amazon-ebs' errored: Script exited with non-zero exit status: 0.Allowed exit codes are: [1] 2020/04/08 10:00:11 machine readable: error-count []string{"1"} 2020/04/08 10:00:11 ui error: ==> Some builds didn't complete successfully and had errors: 2020/04/08 10:00:11 machine readable: amazon-ebs,error []string{"Script exited with non-zero exit status: 0.Allowed exit codes are: [1]"} 2020/04/08 10:00:11 ui error: --> amazon-ebs: Script exited with non-zero exit status: 0.Allowed exit codes are: [1] ``` test: Fix windows-shell command
2020-04-07 15:03:58 -04:00
func TestAccPowershellProvisioner_Script(t *testing.T) {
acc.TestProvisionersPreCheck(TestProvisionerName, t)
testProvisioner := PowershellProvisionerAccTest{"powershell-script-provisioner.txt"}
acc.TestProvisionersAgainstBuilders(&testProvisioner, t)
}
type PowershellProvisionerAccTest struct {
ConfigName string
}
func (s *PowershellProvisionerAccTest) GetName() string {
return TestProvisionerName
}
func (s *PowershellProvisionerAccTest) GetConfig() (string, error) {
filePath := filepath.Join("./test-fixtures", s.ConfigName)
config, err := os.Open(filePath)
if err != nil {
return "", fmt.Errorf("os.Open:%v", err)
}
defer config.Close()
file, err := ioutil.ReadAll(config)
if err != nil {
return "", fmt.Errorf("ioutil.ReadAll:%v", err)
}
return string(file), nil
}
func (s *PowershellProvisionerAccTest) GetProvisionerStore() packer.MapOfProvisioner {
return packer.MapOfProvisioner{
2020-12-01 17:25:14 -05:00
TestProvisionerName: func() (packersdk.Provisioner, error) { return &powershell.Provisioner{}, nil },
"windows-shell": func() (packersdk.Provisioner, error) { return &windowsshellprovisioner.Provisioner{}, nil },
}
}
func (s *PowershellProvisionerAccTest) IsCompatible(builder string, vmOS string) bool {
return vmOS == "windows"
}
func (s *PowershellProvisionerAccTest) RunTest(c *command.BuildCommand, args []string) error {
UUID := os.Getenv("PACKER_RUN_UUID")
if UUID == "" {
UUID, _ = uuid.GenerateUUID()
os.Setenv("PACKER_RUN_UUID", UUID)
}
if code := c.Run(args); code != 0 {
ui := c.Meta.Ui.(*packersdk.BasicUi)
out := ui.Writer.(*bytes.Buffer)
err := ui.ErrorWriter.(*bytes.Buffer)
return fmt.Errorf(
"Bad exit code.\n\nStdout:\n\n%s\n\nStderr:\n\n%s",
out.String(),
err.String())
}
return nil
}