2018-01-24 09:56:14 -05:00
|
|
|
package iso
|
|
|
|
|
|
|
|
import (
|
2018-10-20 20:57:28 -04:00
|
|
|
"fmt"
|
2018-01-24 09:56:14 -05:00
|
|
|
builderT "github.com/hashicorp/packer/helper/builder/testing"
|
2018-01-30 11:48:32 -05:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2018-10-20 20:57:28 -04:00
|
|
|
commonT "github.com/jetbrains-infra/packer-builder-vsphere/common/testing"
|
2018-01-31 10:15:26 -05:00
|
|
|
"github.com/vmware/govmomi/vim25/types"
|
2018-02-01 06:47:09 -05:00
|
|
|
"io/ioutil"
|
2018-10-30 18:10:57 -04:00
|
|
|
"os"
|
2018-10-20 20:57:28 -04:00
|
|
|
"testing"
|
2018-01-24 09:56:14 -05:00
|
|
|
)
|
|
|
|
|
2018-01-24 13:52:29 -05:00
|
|
|
func TestISOBuilderAcc_default(t *testing.T) {
|
2018-01-24 09:56:14 -05:00
|
|
|
config := defaultConfig()
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: commonT.RenderConfig(config),
|
2018-01-31 06:31:11 -05:00
|
|
|
Check: checkDefault(t, config["vm_name"].(string), config["host"].(string), "datastore1"),
|
2018-01-24 09:56:14 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func defaultConfig() map[string]interface{} {
|
2018-10-30 18:10:57 -04:00
|
|
|
username := os.Getenv("VSPHERE_USERNAME")
|
|
|
|
if username == "" {
|
|
|
|
username = "root"
|
|
|
|
}
|
|
|
|
password := os.Getenv("VSPHERE_PASSWORD")
|
|
|
|
if password == "" {
|
|
|
|
password = "jetbrains"
|
|
|
|
}
|
|
|
|
|
2018-01-24 09:56:14 -05:00
|
|
|
config := map[string]interface{}{
|
|
|
|
"vcenter_server": "vcenter.vsphere65.test",
|
2018-10-30 18:10:57 -04:00
|
|
|
"username": username,
|
|
|
|
"password": password,
|
2018-01-24 09:56:14 -05:00
|
|
|
"insecure_connection": true,
|
|
|
|
|
|
|
|
"host": "esxi-1.vsphere65.test",
|
|
|
|
|
|
|
|
"ssh_username": "root",
|
|
|
|
"ssh_password": "jetbrains",
|
|
|
|
|
2018-02-01 07:50:12 -05:00
|
|
|
"vm_name": commonT.NewVMName(),
|
2018-04-27 05:11:02 -04:00
|
|
|
"disk_size": 2048,
|
2018-02-01 07:50:12 -05:00
|
|
|
|
2018-01-31 06:31:11 -05:00
|
|
|
"communicator": "none", // do not start the VM without any bootable devices
|
2018-01-24 09:56:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return config
|
|
|
|
}
|
2018-01-30 11:48:32 -05:00
|
|
|
|
|
|
|
func checkDefault(t *testing.T, name string, host string, datastore string) builderT.TestCheckFunc {
|
|
|
|
return func(artifacts []packer.Artifact) error {
|
|
|
|
d := commonT.TestConn(t)
|
|
|
|
vm := commonT.GetVM(t, d, artifacts)
|
|
|
|
|
2018-10-16 19:15:27 -04:00
|
|
|
vmInfo, err := vm.Info("name", "parent", "runtime.host", "resourcePool", "datastore", "layoutEx.disk", "config.firmware")
|
2018-01-30 11:48:32 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read VM properties: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if vmInfo.Name != name {
|
|
|
|
t.Errorf("Invalid VM name: expected '%v', got '%v'", name, vmInfo.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
f := d.NewFolder(vmInfo.Parent)
|
|
|
|
folderPath, err := f.Path()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read folder name: %v", err)
|
|
|
|
}
|
|
|
|
if folderPath != "" {
|
|
|
|
t.Errorf("Invalid folder: expected '/', got '%v'", folderPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
h := d.NewHost(vmInfo.Runtime.Host)
|
|
|
|
hostInfo, err := h.Info("name")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Cannot read host properties: ", err)
|
|
|
|
}
|
|
|
|
if hostInfo.Name != host {
|
|
|
|
t.Errorf("Invalid host name: expected '%v', got '%v'", host, hostInfo.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
p := d.NewResourcePool(vmInfo.ResourcePool)
|
|
|
|
poolPath, err := p.Path()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read resource pool name: %v", err)
|
|
|
|
}
|
|
|
|
if poolPath != "" {
|
|
|
|
t.Errorf("Invalid resource pool: expected '/', got '%v'", poolPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
dsr := vmInfo.Datastore[0].Reference()
|
|
|
|
ds := d.NewDatastore(&dsr)
|
|
|
|
dsInfo, err := ds.Info("name")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Cannot read datastore properties: ", err)
|
|
|
|
}
|
|
|
|
if dsInfo.Name != datastore {
|
|
|
|
t.Errorf("Invalid datastore name: expected '%v', got '%v'", datastore, dsInfo.Name)
|
|
|
|
}
|
|
|
|
|
2018-10-16 19:15:27 -04:00
|
|
|
fw := vmInfo.Config.Firmware
|
|
|
|
if fw != "bios" {
|
|
|
|
t.Errorf("Invalid firmware: expected 'bios', got '%v'", fw)
|
|
|
|
}
|
2018-11-07 15:58:04 -05:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestISOBuilderAcc_notes(t *testing.T) {
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: notesConfig(),
|
|
|
|
Check: checkNotes(t),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func notesConfig() string {
|
|
|
|
config := defaultConfig()
|
|
|
|
config["notes"] = "test"
|
|
|
|
|
|
|
|
return commonT.RenderConfig(config)
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkNotes(t *testing.T) builderT.TestCheckFunc {
|
|
|
|
return func(artifacts []packer.Artifact) error {
|
|
|
|
d := commonT.TestConn(t)
|
|
|
|
vm := commonT.GetVM(t, d, artifacts)
|
|
|
|
|
|
|
|
vmInfo, err := vm.Info("config.annotation")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read VM properties: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
notes := vmInfo.Config.Annotation
|
|
|
|
if notes != "test" {
|
|
|
|
t.Errorf("notes should be 'test'")
|
|
|
|
}
|
2018-10-16 19:15:27 -04:00
|
|
|
|
2018-01-30 11:48:32 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestISOBuilderAcc_hardware(t *testing.T) {
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: hardwareConfig(),
|
|
|
|
Check: checkHardware(t),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func hardwareConfig() string {
|
|
|
|
config := defaultConfig()
|
|
|
|
config["CPUs"] = 2
|
2018-12-18 12:51:56 -05:00
|
|
|
config["cpu_cores"] = 2
|
2018-01-30 11:48:32 -05:00
|
|
|
config["CPU_reservation"] = 1000
|
|
|
|
config["CPU_limit"] = 1500
|
|
|
|
config["RAM"] = 2048
|
|
|
|
config["RAM_reservation"] = 1024
|
2018-04-25 02:45:02 -04:00
|
|
|
config["NestedHV"] = true
|
2018-10-16 19:15:27 -04:00
|
|
|
config["firmware"] = "efi"
|
2018-12-17 07:49:04 -05:00
|
|
|
config["video_ram"] = 8192
|
2018-01-30 11:48:32 -05:00
|
|
|
|
|
|
|
return commonT.RenderConfig(config)
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkHardware(t *testing.T) builderT.TestCheckFunc {
|
|
|
|
return func(artifacts []packer.Artifact) error {
|
|
|
|
d := commonT.TestConn(t)
|
|
|
|
|
|
|
|
vm := commonT.GetVM(t, d, artifacts)
|
|
|
|
vmInfo, err := vm.Info("config")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read VM properties: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cpuSockets := vmInfo.Config.Hardware.NumCPU
|
|
|
|
if cpuSockets != 2 {
|
|
|
|
t.Errorf("VM should have 2 CPU sockets, got %v", cpuSockets)
|
|
|
|
}
|
|
|
|
|
2018-12-18 12:51:56 -05:00
|
|
|
cpuCores := vmInfo.Config.Hardware.NumCoresPerSocket
|
|
|
|
if cpuCores != 2 {
|
|
|
|
t.Errorf("VM should have 2 CPU cores per socket, got %v", cpuCores)
|
|
|
|
}
|
|
|
|
|
2018-05-12 07:19:17 -04:00
|
|
|
cpuReservation := *vmInfo.Config.CpuAllocation.Reservation
|
2018-01-30 11:48:32 -05:00
|
|
|
if cpuReservation != 1000 {
|
|
|
|
t.Errorf("VM should have CPU reservation for 1000 Mhz, got %v", cpuReservation)
|
|
|
|
}
|
|
|
|
|
2018-05-12 07:19:17 -04:00
|
|
|
cpuLimit := *vmInfo.Config.CpuAllocation.Limit
|
2018-01-30 11:48:32 -05:00
|
|
|
if cpuLimit != 1500 {
|
|
|
|
t.Errorf("VM should have CPU reservation for 1500 Mhz, got %v", cpuLimit)
|
|
|
|
}
|
|
|
|
|
|
|
|
ram := vmInfo.Config.Hardware.MemoryMB
|
|
|
|
if ram != 2048 {
|
|
|
|
t.Errorf("VM should have 2048 MB of RAM, got %v", ram)
|
|
|
|
}
|
|
|
|
|
2018-05-12 07:19:17 -04:00
|
|
|
ramReservation := *vmInfo.Config.MemoryAllocation.Reservation
|
2018-01-30 11:48:32 -05:00
|
|
|
if ramReservation != 1024 {
|
|
|
|
t.Errorf("VM should have RAM reservation for 1024 MB, got %v", ramReservation)
|
|
|
|
}
|
|
|
|
|
2018-04-25 02:45:02 -04:00
|
|
|
nestedHV := vmInfo.Config.NestedHVEnabled
|
|
|
|
if !*nestedHV {
|
|
|
|
t.Errorf("VM should have NestedHV enabled, got %v", nestedHV)
|
|
|
|
}
|
|
|
|
|
2018-10-16 19:15:27 -04:00
|
|
|
fw := vmInfo.Config.Firmware
|
|
|
|
if fw != "efi" {
|
|
|
|
t.Errorf("Invalid firmware: expected 'efi', got '%v'", fw)
|
|
|
|
}
|
|
|
|
|
2018-10-29 20:18:57 -04:00
|
|
|
l, err := vm.Devices()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read VM devices: %v", err)
|
|
|
|
}
|
|
|
|
c := l.PickController((*types.VirtualIDEController)(nil))
|
|
|
|
if c == nil {
|
|
|
|
t.Errorf("VM should have IDE controller")
|
|
|
|
}
|
|
|
|
s := l.PickController((*types.VirtualAHCIController)(nil))
|
|
|
|
if s != nil {
|
|
|
|
t.Errorf("VM should have no SATA controllers")
|
|
|
|
}
|
|
|
|
|
2018-12-17 07:49:04 -05:00
|
|
|
v := l.SelectByType((*types.VirtualMachineVideoCard)(nil))
|
|
|
|
if len(v) != 1 {
|
|
|
|
t.Errorf("VM should have one video card")
|
|
|
|
}
|
|
|
|
if v[0].(*types.VirtualMachineVideoCard).VideoRamSizeInKB != 8192 {
|
|
|
|
t.Errorf("Video RAM should be equal 8192")
|
|
|
|
}
|
|
|
|
|
2018-01-30 11:48:32 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-16 11:59:51 -04:00
|
|
|
func TestISOBuilderAcc_limit(t *testing.T) {
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: limitConfig(),
|
|
|
|
Check: checkLimit(t),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func limitConfig() string {
|
|
|
|
config := defaultConfig()
|
|
|
|
config["CPUs"] = 1 // hardware is customized, but CPU limit is not specified explicitly
|
|
|
|
|
|
|
|
return commonT.RenderConfig(config)
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkLimit(t *testing.T) builderT.TestCheckFunc {
|
|
|
|
return func(artifacts []packer.Artifact) error {
|
|
|
|
d := commonT.TestConn(t)
|
|
|
|
|
|
|
|
vm := commonT.GetVM(t, d, artifacts)
|
|
|
|
vmInfo, err := vm.Info("config.cpuAllocation")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read VM properties: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
limit := *vmInfo.Config.CpuAllocation.Limit
|
|
|
|
if limit != -1 { // must be unlimited
|
|
|
|
t.Errorf("Invalid CPU limit: expected '%v', got '%v'", -1, limit)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-29 20:18:57 -04:00
|
|
|
func TestISOBuilderAcc_sata(t *testing.T) {
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: sataConfig(),
|
|
|
|
Check: checkSata(t),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func sataConfig() string {
|
|
|
|
config := defaultConfig()
|
|
|
|
config["cdrom_type"] = "sata"
|
|
|
|
|
|
|
|
return commonT.RenderConfig(config)
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkSata(t *testing.T) builderT.TestCheckFunc {
|
|
|
|
return func(artifacts []packer.Artifact) error {
|
|
|
|
d := commonT.TestConn(t)
|
|
|
|
|
|
|
|
vm := commonT.GetVM(t, d, artifacts)
|
|
|
|
|
|
|
|
l, err := vm.Devices()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read VM devices: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
c := l.PickController((*types.VirtualAHCIController)(nil))
|
|
|
|
if c == nil {
|
|
|
|
t.Errorf("VM has no SATA controllers")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-30 11:48:32 -05:00
|
|
|
func TestISOBuilderAcc_cdrom(t *testing.T) {
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: cdromConfig(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func cdromConfig() string {
|
|
|
|
config := defaultConfig()
|
2018-01-31 12:29:03 -05:00
|
|
|
config["iso_paths"] = []string{
|
|
|
|
"[datastore1] test0.iso",
|
|
|
|
"[datastore1] test1.iso",
|
|
|
|
}
|
2018-01-30 11:48:32 -05:00
|
|
|
return commonT.RenderConfig(config)
|
|
|
|
}
|
2018-01-31 06:31:11 -05:00
|
|
|
|
|
|
|
func TestISOBuilderAcc_networkCard(t *testing.T) {
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: networkCardConfig(),
|
|
|
|
Check: checkNetworkCard(t),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func networkCardConfig() string {
|
|
|
|
config := defaultConfig()
|
|
|
|
config["network_card"] = "vmxnet3"
|
|
|
|
return commonT.RenderConfig(config)
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkNetworkCard(t *testing.T) builderT.TestCheckFunc {
|
|
|
|
return func(artifacts []packer.Artifact) error {
|
|
|
|
d := commonT.TestConn(t)
|
|
|
|
|
|
|
|
vm := commonT.GetVM(t, d, artifacts)
|
|
|
|
devices, err := vm.Devices()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read VM properties: %v", err)
|
|
|
|
}
|
2018-01-31 10:15:26 -05:00
|
|
|
|
|
|
|
netCards := devices.SelectByType((*types.VirtualEthernetCard)(nil))
|
|
|
|
if len(netCards) == 0 {
|
|
|
|
t.Fatalf("Cannot find the network card")
|
|
|
|
}
|
|
|
|
if len(netCards) > 1 {
|
|
|
|
t.Fatalf("Found several network catds")
|
|
|
|
}
|
|
|
|
if _, ok := netCards[0].(*types.VirtualVmxnet3); !ok {
|
|
|
|
t.Errorf("The network card type is not the expected one (vmxnet3)")
|
2018-01-31 06:31:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
2018-02-01 06:47:09 -05:00
|
|
|
|
|
|
|
func TestISOBuilderAcc_createFloppy(t *testing.T) {
|
|
|
|
tmpFile, err := ioutil.TempFile("", "packer-vsphere-iso-test")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error creating temp file ")
|
|
|
|
}
|
2018-02-01 07:48:30 -05:00
|
|
|
fmt.Fprint(tmpFile, "Hello, World!")
|
2018-02-01 06:47:09 -05:00
|
|
|
tmpFile.Close()
|
|
|
|
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: createFloppyConfig(tmpFile.Name()),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func createFloppyConfig(filePath string) string {
|
|
|
|
config := defaultConfig()
|
|
|
|
config["floppy_files"] = []string{filePath}
|
|
|
|
return commonT.RenderConfig(config)
|
|
|
|
}
|
2018-10-20 20:57:28 -04:00
|
|
|
|
|
|
|
func TestISOBuilderAcc_full(t *testing.T) {
|
|
|
|
config := fullConfig()
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: commonT.RenderConfig(config),
|
|
|
|
Check: checkFull(t),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func fullConfig() map[string]interface{} {
|
2018-12-03 12:10:48 -05:00
|
|
|
username := os.Getenv("VSPHERE_USERNAME")
|
|
|
|
if username == "" {
|
|
|
|
username = "root"
|
|
|
|
}
|
|
|
|
password := os.Getenv("VSPHERE_PASSWORD")
|
|
|
|
if password == "" {
|
|
|
|
password = "jetbrains"
|
|
|
|
}
|
|
|
|
|
2018-10-20 20:57:28 -04:00
|
|
|
config := map[string]interface{}{
|
|
|
|
"vcenter_server": "vcenter.vsphere65.test",
|
2018-12-03 12:10:48 -05:00
|
|
|
"username": username,
|
|
|
|
"password": password,
|
2018-10-20 20:57:28 -04:00
|
|
|
"insecure_connection": true,
|
|
|
|
|
|
|
|
"vm_name": commonT.NewVMName(),
|
|
|
|
"host": "esxi-1.vsphere65.test",
|
|
|
|
|
2019-01-04 09:21:59 -05:00
|
|
|
"RAM": 512,
|
2018-10-20 20:57:28 -04:00
|
|
|
"disk_controller_type": "pvscsi",
|
2019-01-04 09:21:59 -05:00
|
|
|
"disk_size": 1024,
|
2018-10-20 20:57:28 -04:00
|
|
|
"disk_thin_provisioned": true,
|
|
|
|
"network_card": "vmxnet3",
|
2019-01-04 09:21:59 -05:00
|
|
|
"guest_os_type": "other3xLinux64Guest",
|
2018-10-20 20:57:28 -04:00
|
|
|
|
|
|
|
"iso_paths": []string{
|
2019-01-04 09:21:59 -05:00
|
|
|
"[datastore1] ISO/alpine-standard-3.8.2-x86_64.iso",
|
2018-10-20 20:57:28 -04:00
|
|
|
},
|
|
|
|
"floppy_files": []string{
|
2019-01-04 09:21:59 -05:00
|
|
|
"../examples/alpine/answerfile",
|
|
|
|
"../examples/alpine/setup.sh",
|
2018-10-20 20:57:28 -04:00
|
|
|
},
|
|
|
|
|
2019-01-04 09:21:59 -05:00
|
|
|
"boot_wait": "15s",
|
2018-10-20 20:57:28 -04:00
|
|
|
"boot_command": []string{
|
2019-01-04 09:21:59 -05:00
|
|
|
"root<enter><wait>",
|
|
|
|
"mount -t vfat /dev/fd0 /media/floppy<enter><wait>",
|
|
|
|
"setup-alpine -f /media/floppy/answerfile<enter>",
|
|
|
|
"<wait5>",
|
|
|
|
"jetbrains<enter>",
|
|
|
|
"jetbrains<enter>",
|
|
|
|
"<wait5>",
|
|
|
|
"y<enter>",
|
|
|
|
"<wait10><wait10><wait10><wait10>",
|
|
|
|
"reboot<enter>",
|
|
|
|
"<wait10><wait10>",
|
|
|
|
"root<enter>",
|
|
|
|
"jetbrains<enter><wait>",
|
|
|
|
"mount -t vfat /dev/fd0 /media/floppy<enter><wait>",
|
|
|
|
"/media/floppy/SETUP.SH<enter>",
|
2018-10-20 20:57:28 -04:00
|
|
|
},
|
|
|
|
|
2019-01-04 09:21:59 -05:00
|
|
|
"ssh_username": "root",
|
2018-10-20 20:57:28 -04:00
|
|
|
"ssh_password": "jetbrains",
|
|
|
|
}
|
|
|
|
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkFull(t *testing.T) builderT.TestCheckFunc {
|
|
|
|
return func(artifacts []packer.Artifact) error {
|
|
|
|
d := commonT.TestConn(t)
|
|
|
|
vm := commonT.GetVM(t, d, artifacts)
|
|
|
|
|
|
|
|
vmInfo, err := vm.Info("config.bootOptions")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read VM properties: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
order := vmInfo.Config.BootOptions.BootOrder
|
|
|
|
if order != nil {
|
|
|
|
t.Errorf("Boot order must be empty")
|
|
|
|
}
|
|
|
|
|
2018-10-21 03:47:35 -04:00
|
|
|
devices, err := vm.Devices()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read devices: %v", err)
|
|
|
|
}
|
|
|
|
cdroms := devices.SelectByType((*types.VirtualCdrom)(nil))
|
|
|
|
for _, cd := range cdroms {
|
|
|
|
_, ok := cd.(*types.VirtualCdrom).Backing.(*types.VirtualCdromRemotePassthroughBackingInfo)
|
|
|
|
if !ok {
|
|
|
|
t.Errorf("wrong cdrom backing")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-20 20:57:28 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestISOBuilderAcc_bootOrder(t *testing.T) {
|
|
|
|
config := fullConfig()
|
|
|
|
config["boot_order"] = "disk,cdrom,floppy"
|
|
|
|
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: commonT.RenderConfig(config),
|
|
|
|
Check: checkBootOrder(t),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkBootOrder(t *testing.T) builderT.TestCheckFunc {
|
|
|
|
return func(artifacts []packer.Artifact) error {
|
|
|
|
d := commonT.TestConn(t)
|
|
|
|
vm := commonT.GetVM(t, d, artifacts)
|
|
|
|
|
|
|
|
vmInfo, err := vm.Info("config.bootOptions")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read VM properties: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
order := vmInfo.Config.BootOptions.BootOrder
|
|
|
|
if order == nil {
|
|
|
|
t.Errorf("Boot order must not be empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
2018-11-01 17:32:34 -04:00
|
|
|
|
|
|
|
func TestISOBuilderAcc_cluster(t *testing.T) {
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: clusterConfig(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func clusterConfig() string {
|
|
|
|
config := defaultConfig()
|
|
|
|
config["cluster"] = "cluster1"
|
|
|
|
config["host"] = "esxi-2.vsphere65.test"
|
|
|
|
|
|
|
|
return commonT.RenderConfig(config)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestISOBuilderAcc_clusterDRS(t *testing.T) {
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: clusterDRSConfig(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func clusterDRSConfig() string {
|
|
|
|
config := defaultConfig()
|
|
|
|
config["cluster"] = "cluster2"
|
|
|
|
config["host"] = ""
|
|
|
|
config["datastore"] = "datastore3" // bug #183
|
|
|
|
config["network"] = "VM Network" // bug #183
|
|
|
|
|
|
|
|
return commonT.RenderConfig(config)
|
|
|
|
}
|