2018-01-24 06:04:39 -05:00
|
|
|
package clone
|
2017-06-14 14:16:57 -04:00
|
|
|
|
|
|
|
import (
|
2020-02-14 11:42:29 -05:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2020-01-07 19:59:31 -05:00
|
|
|
"github.com/hashicorp/packer/builder/vsphere/common"
|
|
|
|
commonT "github.com/hashicorp/packer/builder/vsphere/common/testing"
|
2017-11-14 16:19:32 -05:00
|
|
|
builderT "github.com/hashicorp/packer/helper/builder/testing"
|
2018-10-31 17:42:24 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2018-12-17 07:49:04 -05:00
|
|
|
"github.com/vmware/govmomi/vim25/types"
|
2017-06-14 14:16:57 -04:00
|
|
|
)
|
|
|
|
|
2018-01-24 13:52:29 -05:00
|
|
|
func TestCloneBuilderAcc_default(t *testing.T) {
|
2020-01-08 13:22:55 -05:00
|
|
|
t.Skip("Acceptance tests not configured yet.")
|
2017-08-17 19:24:59 -04:00
|
|
|
config := defaultConfig()
|
2017-06-14 14:16:57 -04:00
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
2018-01-24 09:56:14 -05:00
|
|
|
Template: commonT.RenderConfig(config),
|
2017-11-13 16:02:46 -05:00
|
|
|
Check: checkDefault(t, config["vm_name"].(string), config["host"].(string), "datastore1"),
|
2017-06-14 14:16:57 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-08-17 19:24:59 -04: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"
|
|
|
|
}
|
|
|
|
|
2017-08-17 19:24:59 -04:00
|
|
|
config := map[string]interface{}{
|
2018-01-23 14:51:05 -05:00
|
|
|
"vcenter_server": "vcenter.vsphere65.test",
|
2018-10-30 18:10:57 -04:00
|
|
|
"username": username,
|
|
|
|
"password": password,
|
2017-07-01 11:59:36 -04:00
|
|
|
"insecure_connection": true,
|
2017-06-14 14:16:57 -04:00
|
|
|
|
2017-11-08 11:47:29 -05:00
|
|
|
"template": "alpine",
|
2018-01-23 14:51:05 -05:00
|
|
|
"host": "esxi-1.vsphere65.test",
|
2017-06-14 14:16:57 -04:00
|
|
|
|
2018-03-22 18:21:04 -04:00
|
|
|
"linked_clone": true, // speed up
|
|
|
|
"communicator": "none",
|
2017-08-17 19:24:59 -04:00
|
|
|
}
|
2018-01-24 09:56:14 -05:00
|
|
|
config["vm_name"] = commonT.NewVMName()
|
2017-08-17 19:24:59 -04:00
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
2017-11-13 16:02:46 -05:00
|
|
|
func checkDefault(t *testing.T, name string, host string, datastore string) builderT.TestCheckFunc {
|
|
|
|
return func(artifacts []packer.Artifact) error {
|
2018-01-30 11:48:32 -05:00
|
|
|
d := commonT.TestConn(t)
|
|
|
|
vm := commonT.GetVM(t, d, artifacts)
|
2017-11-13 16:02:46 -05:00
|
|
|
|
2018-03-22 18:21:04 -04:00
|
|
|
vmInfo, err := vm.Info("name", "parent", "runtime.host", "resourcePool", "datastore")
|
2017-11-13 16:02:46 -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 != "" {
|
2017-11-14 16:19:32 -05:00
|
|
|
t.Errorf("Invalid resource pool: expected '/', got '%v'", poolPath)
|
2017-11-13 16:02:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-24 13:52:29 -05:00
|
|
|
func TestCloneBuilderAcc_artifact(t *testing.T) {
|
2020-01-08 13:22:55 -05:00
|
|
|
t.Skip("Acceptance tests not configured yet.")
|
2017-08-23 16:32:45 -04:00
|
|
|
config := defaultConfig()
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
2018-01-24 09:56:14 -05:00
|
|
|
Template: commonT.RenderConfig(config),
|
2017-08-23 16:32:45 -04:00
|
|
|
Check: checkArtifact(t),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkArtifact(t *testing.T) builderT.TestCheckFunc {
|
|
|
|
return func(artifacts []packer.Artifact) error {
|
|
|
|
if len(artifacts) > 1 {
|
|
|
|
t.Fatal("more than 1 artifact")
|
|
|
|
}
|
|
|
|
|
|
|
|
artifactRaw := artifacts[0]
|
2018-01-24 06:04:39 -05:00
|
|
|
_, ok := artifactRaw.(*common.Artifact)
|
2017-08-23 16:32:45 -04:00
|
|
|
if !ok {
|
|
|
|
t.Fatalf("unknown artifact: %#v", artifactRaw)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-24 13:52:29 -05:00
|
|
|
func TestCloneBuilderAcc_folder(t *testing.T) {
|
2020-01-08 13:22:55 -05:00
|
|
|
t.Skip("Acceptance tests not configured yet.")
|
2017-08-23 17:23:29 -04:00
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: folderConfig(),
|
2017-11-08 11:47:29 -05:00
|
|
|
Check: checkFolder(t, "folder1/folder2"),
|
2017-08-23 17:23:29 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func folderConfig() string {
|
|
|
|
config := defaultConfig()
|
2017-11-08 11:47:29 -05:00
|
|
|
config["folder"] = "folder1/folder2"
|
2018-01-24 09:56:14 -05:00
|
|
|
return commonT.RenderConfig(config)
|
2017-08-23 17:23:29 -04:00
|
|
|
}
|
|
|
|
|
2017-11-14 16:19:32 -05:00
|
|
|
func checkFolder(t *testing.T, folder string) builderT.TestCheckFunc {
|
|
|
|
return func(artifacts []packer.Artifact) error {
|
2018-01-30 11:48:32 -05:00
|
|
|
d := commonT.TestConn(t)
|
|
|
|
vm := commonT.GetVM(t, d, artifacts)
|
2017-11-14 16:19:32 -05:00
|
|
|
|
|
|
|
vmInfo, err := vm.Info("parent")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read VM properties: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
f := d.NewFolder(vmInfo.Parent)
|
|
|
|
path, err := f.Path()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read folder name: %v", err)
|
|
|
|
}
|
|
|
|
if path != folder {
|
|
|
|
t.Errorf("Wrong folder. expected: %v, got: %v", folder, path)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-24 13:52:29 -05:00
|
|
|
func TestCloneBuilderAcc_resourcePool(t *testing.T) {
|
2020-01-08 13:22:55 -05:00
|
|
|
t.Skip("Acceptance tests not configured yet.")
|
2017-08-23 18:23:48 -04:00
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: resourcePoolConfig(),
|
2017-11-08 11:47:29 -05:00
|
|
|
Check: checkResourcePool(t, "pool1/pool2"),
|
2017-08-23 18:23:48 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourcePoolConfig() string {
|
|
|
|
config := defaultConfig()
|
2017-11-08 11:47:29 -05:00
|
|
|
config["resource_pool"] = "pool1/pool2"
|
2018-01-24 09:56:14 -05:00
|
|
|
return commonT.RenderConfig(config)
|
2017-08-23 18:23:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func checkResourcePool(t *testing.T, pool string) builderT.TestCheckFunc {
|
|
|
|
return func(artifacts []packer.Artifact) error {
|
2018-01-30 11:48:32 -05:00
|
|
|
d := commonT.TestConn(t)
|
|
|
|
vm := commonT.GetVM(t, d, artifacts)
|
2017-08-23 18:23:48 -04:00
|
|
|
|
2017-08-23 20:06:50 -04:00
|
|
|
vmInfo, err := vm.Info("resourcePool")
|
2017-08-23 18:23:48 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read VM properties: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-11-13 16:02:46 -05:00
|
|
|
p := d.NewResourcePool(vmInfo.ResourcePool)
|
|
|
|
path, err := p.Path()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read resource pool name: %v", err)
|
|
|
|
}
|
|
|
|
if path != pool {
|
|
|
|
t.Errorf("Wrong folder. expected: %v, got: %v", pool, path)
|
|
|
|
}
|
|
|
|
|
2017-08-23 18:23:48 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-24 13:52:29 -05:00
|
|
|
func TestCloneBuilderAcc_datastore(t *testing.T) {
|
2020-01-08 13:22:55 -05:00
|
|
|
t.Skip("Acceptance tests not configured yet.")
|
2017-08-24 16:18:14 -04:00
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: datastoreConfig(),
|
2018-01-23 14:51:05 -05:00
|
|
|
Check: checkDatastore(t, "datastore1"), // on esxi-1.vsphere65.test
|
2017-08-24 16:18:14 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func datastoreConfig() string {
|
|
|
|
config := defaultConfig()
|
2018-01-23 14:51:05 -05:00
|
|
|
config["template"] = "alpine-host4" // on esxi-4.vsphere65.test
|
2018-03-22 18:21:04 -04:00
|
|
|
config["linked_clone"] = false
|
2018-01-24 09:56:14 -05:00
|
|
|
return commonT.RenderConfig(config)
|
2017-08-24 16:18:14 -04:00
|
|
|
}
|
|
|
|
|
2017-11-13 16:02:46 -05:00
|
|
|
func checkDatastore(t *testing.T, name string) builderT.TestCheckFunc {
|
|
|
|
return func(artifacts []packer.Artifact) error {
|
2018-01-30 11:48:32 -05:00
|
|
|
d := commonT.TestConn(t)
|
|
|
|
vm := commonT.GetVM(t, d, artifacts)
|
2017-11-13 16:02:46 -05:00
|
|
|
|
|
|
|
vmInfo, err := vm.Info("datastore")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read VM properties: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
n := len(vmInfo.Datastore)
|
|
|
|
if n != 1 {
|
|
|
|
t.Fatalf("VM should have 1 datastore, got %v", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
ds := d.NewDatastore(&vmInfo.Datastore[0])
|
|
|
|
info, err := ds.Info("name")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read datastore properties: %v", err)
|
|
|
|
}
|
|
|
|
if info.Name != name {
|
|
|
|
t.Errorf("Wrong datastore. expected: %v, got: %v", name, info.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-24 13:52:29 -05:00
|
|
|
func TestCloneBuilderAcc_multipleDatastores(t *testing.T) {
|
2017-10-25 16:54:13 -04:00
|
|
|
t.Skip("test must fail")
|
2017-08-24 16:18:14 -04:00
|
|
|
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: multipleDatastoresConfig(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func multipleDatastoresConfig() string {
|
|
|
|
config := defaultConfig()
|
2018-01-23 14:51:05 -05:00
|
|
|
config["host"] = "esxi-4.vsphere65.test" // host with 2 datastores
|
2018-03-22 18:21:04 -04:00
|
|
|
config["linked_clone"] = false
|
|
|
|
return commonT.RenderConfig(config)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCloneBuilderAcc_fullClone(t *testing.T) {
|
2020-01-08 13:22:55 -05:00
|
|
|
t.Skip("Acceptance tests not configured yet.")
|
2018-03-22 18:21:04 -04:00
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: fullCloneConfig(),
|
|
|
|
Check: checkFullClone(t),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func fullCloneConfig() string {
|
|
|
|
config := defaultConfig()
|
|
|
|
config["linked_clone"] = false
|
2018-01-24 09:56:14 -05:00
|
|
|
return commonT.RenderConfig(config)
|
2017-08-24 16:18:14 -04:00
|
|
|
}
|
|
|
|
|
2018-03-22 18:21:04 -04:00
|
|
|
func checkFullClone(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("layoutEx.disk")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read VM properties: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(vmInfo.LayoutEx.Disk[0].Chain) != 1 {
|
|
|
|
t.Error("Not a full clone")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-24 13:52:29 -05:00
|
|
|
func TestCloneBuilderAcc_linkedClone(t *testing.T) {
|
2020-01-08 13:22:55 -05:00
|
|
|
t.Skip("Acceptance tests not configured yet.")
|
2017-08-17 19:24:59 -04:00
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: linkedCloneConfig(),
|
|
|
|
Check: checkLinkedClone(t),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func linkedCloneConfig() string {
|
|
|
|
config := defaultConfig()
|
|
|
|
config["linked_clone"] = true
|
2018-01-24 09:56:14 -05:00
|
|
|
return commonT.RenderConfig(config)
|
2017-08-17 19:24:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func checkLinkedClone(t *testing.T) builderT.TestCheckFunc {
|
|
|
|
return func(artifacts []packer.Artifact) error {
|
2018-01-30 11:48:32 -05:00
|
|
|
d := commonT.TestConn(t)
|
|
|
|
vm := commonT.GetVM(t, d, artifacts)
|
2017-08-17 19:24:59 -04:00
|
|
|
|
2017-08-23 20:06:50 -04:00
|
|
|
vmInfo, err := vm.Info("layoutEx.disk")
|
2017-08-17 19:24:59 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read VM properties: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-08-31 08:05:26 -04:00
|
|
|
if len(vmInfo.LayoutEx.Disk[0].Chain) != 2 {
|
2017-08-17 19:24:59 -04:00
|
|
|
t.Error("Not a linked clone")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-13 09:56:14 -04:00
|
|
|
func TestCloneBuilderAcc_network(t *testing.T) {
|
2020-01-08 13:22:55 -05:00
|
|
|
t.Skip("Acceptance tests not configured yet.")
|
2019-06-13 09:56:14 -04:00
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: networkConfig(),
|
|
|
|
Check: checkNetwork(t, "VM Network 2"),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func networkConfig() string {
|
|
|
|
config := defaultConfig()
|
|
|
|
config["template"] = "alpine-host4"
|
|
|
|
config["host"] = "esxi-4.vsphere65.test"
|
|
|
|
config["datastore"] = "datastore4"
|
|
|
|
config["network"] = "VM Network 2"
|
|
|
|
return commonT.RenderConfig(config)
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkNetwork(t *testing.T, name string) builderT.TestCheckFunc {
|
|
|
|
return func(artifacts []packer.Artifact) error {
|
|
|
|
d := commonT.TestConn(t)
|
|
|
|
vm := commonT.GetVM(t, d, artifacts)
|
|
|
|
|
|
|
|
vmInfo, err := vm.Info("network")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read VM properties: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
n := len(vmInfo.Network)
|
|
|
|
if n != 1 {
|
|
|
|
t.Fatalf("VM should have 1 network, got %v", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
ds := d.NewNetwork(&vmInfo.Network[0])
|
|
|
|
info, err := ds.Info("name")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read network properties: %v", err)
|
|
|
|
}
|
|
|
|
if info.Name != name {
|
|
|
|
t.Errorf("Wrong network. expected: %v, got: %v", name, info.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-24 13:52:29 -05:00
|
|
|
func TestCloneBuilderAcc_hardware(t *testing.T) {
|
2020-01-08 13:22:55 -05:00
|
|
|
t.Skip("Acceptance tests not configured yet.")
|
2017-08-24 16:50:25 -04:00
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: hardwareConfig(),
|
2017-11-13 16:02:46 -05:00
|
|
|
Check: checkHardware(t),
|
2017-08-24 16:50:25 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func hardwareConfig() string {
|
|
|
|
config := defaultConfig()
|
2017-11-08 11:47:29 -05:00
|
|
|
config["CPUs"] = 2
|
2018-12-18 12:51:56 -05:00
|
|
|
config["cpu_cores"] = 2
|
2017-11-08 11:47:29 -05:00
|
|
|
config["CPU_reservation"] = 1000
|
|
|
|
config["CPU_limit"] = 1500
|
|
|
|
config["RAM"] = 2048
|
|
|
|
config["RAM_reservation"] = 1024
|
2018-03-23 04:56:03 -04:00
|
|
|
config["CPU_hot_plug"] = true
|
|
|
|
config["RAM_hot_plug"] = true
|
2018-12-17 07:49:04 -05:00
|
|
|
config["video_ram"] = 8192
|
2017-08-24 16:50:25 -04:00
|
|
|
|
2018-01-24 09:56:14 -05:00
|
|
|
return commonT.RenderConfig(config)
|
2017-08-24 16:50:25 -04:00
|
|
|
}
|
|
|
|
|
2017-11-13 16:02:46 -05:00
|
|
|
func checkHardware(t *testing.T) builderT.TestCheckFunc {
|
|
|
|
return func(artifacts []packer.Artifact) error {
|
2018-01-30 11:48:32 -05:00
|
|
|
d := commonT.TestConn(t)
|
2017-11-13 16:02:46 -05:00
|
|
|
|
2018-01-30 11:48:32 -05:00
|
|
|
vm := commonT.GetVM(t, d, artifacts)
|
2017-11-13 16:02:46 -05:00
|
|
|
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
|
2017-11-13 16:02:46 -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
|
2017-11-13 16:02:46 -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
|
2017-11-13 16:02:46 -05:00
|
|
|
if ramReservation != 1024 {
|
|
|
|
t.Errorf("VM should have RAM reservation for 1024 MB, got %v", ramReservation)
|
|
|
|
}
|
|
|
|
|
2018-03-23 04:56:03 -04:00
|
|
|
cpuHotAdd := vmInfo.Config.CpuHotAddEnabled
|
|
|
|
if !*cpuHotAdd {
|
|
|
|
t.Errorf("VM should have CPU hot add enabled, got %v", cpuHotAdd)
|
|
|
|
}
|
|
|
|
|
|
|
|
memoryHotAdd := vmInfo.Config.MemoryHotAddEnabled
|
|
|
|
if !*memoryHotAdd {
|
|
|
|
t.Errorf("VM should have Memory hot add enabled, got %v", memoryHotAdd)
|
|
|
|
}
|
|
|
|
|
2018-12-17 07:49:04 -05:00
|
|
|
l, err := vm.Devices()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read VM devices: %v", err)
|
|
|
|
}
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2017-11-13 16:02:46 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-24 13:52:29 -05:00
|
|
|
func TestCloneBuilderAcc_RAMReservation(t *testing.T) {
|
2020-01-08 13:22:55 -05:00
|
|
|
t.Skip("Acceptance tests not configured yet.")
|
2017-08-24 16:50:25 -04:00
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: RAMReservationConfig(),
|
|
|
|
Check: checkRAMReservation(t),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func RAMReservationConfig() string {
|
|
|
|
config := defaultConfig()
|
|
|
|
config["RAM_reserve_all"] = true
|
|
|
|
|
2018-01-24 09:56:14 -05:00
|
|
|
return commonT.RenderConfig(config)
|
2017-08-24 16:50:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func checkRAMReservation(t *testing.T) builderT.TestCheckFunc {
|
|
|
|
return func(artifacts []packer.Artifact) error {
|
2018-01-30 11:48:32 -05:00
|
|
|
d := commonT.TestConn(t)
|
2017-08-24 16:50:25 -04:00
|
|
|
|
2018-01-30 11:48:32 -05:00
|
|
|
vm := commonT.GetVM(t, d, artifacts)
|
2017-08-24 16:50:25 -04:00
|
|
|
vmInfo, err := vm.Info("config")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read VM properties: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if *vmInfo.Config.MemoryReservationLockedToMax != true {
|
|
|
|
t.Errorf("VM should have all RAM reserved")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 18:21:04 -04:00
|
|
|
func TestCloneBuilderAcc_sshPassword(t *testing.T) {
|
2020-01-08 13:22:55 -05:00
|
|
|
t.Skip("Acceptance tests not configured yet.")
|
2018-03-22 18:21:04 -04:00
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: sshPasswordConfig(),
|
2018-10-31 17:42:24 -04:00
|
|
|
Check: checkDefaultBootOrder(t),
|
2018-03-22 18:21:04 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func sshPasswordConfig() string {
|
|
|
|
config := defaultConfig()
|
|
|
|
config["communicator"] = "ssh"
|
|
|
|
config["ssh_username"] = "root"
|
|
|
|
config["ssh_password"] = "jetbrains"
|
|
|
|
return commonT.RenderConfig(config)
|
|
|
|
}
|
|
|
|
|
2018-10-20 20:57:28 -04:00
|
|
|
func checkDefaultBootOrder(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")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-24 13:52:29 -05:00
|
|
|
func TestCloneBuilderAcc_sshKey(t *testing.T) {
|
2020-01-08 13:22:55 -05:00
|
|
|
t.Skip("Acceptance tests not configured yet.")
|
2017-08-31 08:05:26 -04:00
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: sshKeyConfig(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func sshKeyConfig() string {
|
|
|
|
config := defaultConfig()
|
2018-03-22 18:21:04 -04:00
|
|
|
config["communicator"] = "ssh"
|
|
|
|
config["ssh_username"] = "root"
|
2018-04-24 15:11:33 -04:00
|
|
|
config["ssh_private_key_file"] = "../test/test-key.pem"
|
2018-01-24 09:56:14 -05:00
|
|
|
return commonT.RenderConfig(config)
|
2017-08-31 08:05:26 -04:00
|
|
|
}
|
|
|
|
|
2018-01-24 13:52:29 -05:00
|
|
|
func TestCloneBuilderAcc_snapshot(t *testing.T) {
|
2020-01-08 13:22:55 -05:00
|
|
|
t.Skip("Acceptance tests not configured yet.")
|
2017-08-23 16:15:19 -04:00
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: snapshotConfig(),
|
2017-11-13 16:02:46 -05:00
|
|
|
Check: checkSnapshot(t),
|
2017-08-23 16:15:19 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func snapshotConfig() string {
|
|
|
|
config := defaultConfig()
|
2018-03-22 18:21:04 -04:00
|
|
|
config["linked_clone"] = false
|
2017-08-23 16:15:19 -04:00
|
|
|
config["create_snapshot"] = true
|
2018-01-24 09:56:14 -05:00
|
|
|
return commonT.RenderConfig(config)
|
2017-08-23 16:15:19 -04:00
|
|
|
}
|
|
|
|
|
2017-11-13 16:02:46 -05:00
|
|
|
func checkSnapshot(t *testing.T) builderT.TestCheckFunc {
|
|
|
|
return func(artifacts []packer.Artifact) error {
|
2018-01-30 11:48:32 -05:00
|
|
|
d := commonT.TestConn(t)
|
2017-11-13 16:02:46 -05:00
|
|
|
|
2018-01-30 11:48:32 -05:00
|
|
|
vm := commonT.GetVM(t, d, artifacts)
|
2017-11-13 16:02:46 -05:00
|
|
|
vmInfo, err := vm.Info("layoutEx.disk")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read VM properties: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
layers := len(vmInfo.LayoutEx.Disk[0].Chain)
|
|
|
|
if layers != 2 {
|
|
|
|
t.Errorf("VM should have a single snapshot. expected 2 disk layers, got %v", layers)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-24 13:52:29 -05:00
|
|
|
func TestCloneBuilderAcc_template(t *testing.T) {
|
2020-01-08 13:22:55 -05:00
|
|
|
t.Skip("Acceptance tests not configured yet.")
|
2017-08-17 19:24:59 -04:00
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: templateConfig(),
|
2017-11-13 16:02:46 -05:00
|
|
|
Check: checkTemplate(t),
|
2017-08-17 19:24:59 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func templateConfig() string {
|
|
|
|
config := defaultConfig()
|
|
|
|
config["convert_to_template"] = true
|
2018-01-24 09:56:14 -05:00
|
|
|
return commonT.RenderConfig(config)
|
2017-08-17 19:24:59 -04:00
|
|
|
}
|
|
|
|
|
2017-11-13 16:02:46 -05:00
|
|
|
func checkTemplate(t *testing.T) builderT.TestCheckFunc {
|
|
|
|
return func(artifacts []packer.Artifact) error {
|
2018-01-30 11:48:32 -05:00
|
|
|
d := commonT.TestConn(t)
|
2017-11-13 16:02:46 -05:00
|
|
|
|
2018-01-30 11:48:32 -05:00
|
|
|
vm := commonT.GetVM(t, d, artifacts)
|
2017-11-13 16:02:46 -05:00
|
|
|
vmInfo, err := vm.Info("config.template")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot read VM properties: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if vmInfo.Config.Template != true {
|
|
|
|
t.Error("Not a template")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
2018-10-20 20:57:28 -04:00
|
|
|
|
|
|
|
func TestCloneBuilderAcc_bootOrder(t *testing.T) {
|
2020-01-08 13:22:55 -05:00
|
|
|
t.Skip("Acceptance tests not configured yet.")
|
2018-10-20 20:57:28 -04:00
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: bootOrderConfig(),
|
|
|
|
Check: checkBootOrder(t),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func bootOrderConfig() string {
|
|
|
|
config := defaultConfig()
|
|
|
|
config["communicator"] = "ssh"
|
|
|
|
config["ssh_username"] = "root"
|
|
|
|
config["ssh_password"] = "jetbrains"
|
|
|
|
|
|
|
|
config["boot_order"] = "disk,cdrom,floppy"
|
|
|
|
|
|
|
|
return commonT.RenderConfig(config)
|
|
|
|
}
|
|
|
|
|
|
|
|
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-07 15:58:04 -05:00
|
|
|
|
|
|
|
func TestCloneBuilderAcc_notes(t *testing.T) {
|
2020-01-08 13:22:55 -05:00
|
|
|
t.Skip("Acceptance tests not configured yet.")
|
2018-11-07 15:58:04 -05:00
|
|
|
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("notest should be 'test'")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
2018-12-17 17:34:48 -05:00
|
|
|
|
|
|
|
func TestCloneBuilderAcc_windows(t *testing.T) {
|
2020-01-08 13:22:55 -05:00
|
|
|
t.Skip("Acceptance tests not configured yet.")
|
2018-12-17 17:34:48 -05:00
|
|
|
t.Skip("test is too slow")
|
|
|
|
config := windowsConfig()
|
|
|
|
builderT.Test(t, builderT.TestCase{
|
|
|
|
Builder: &Builder{},
|
|
|
|
Template: commonT.RenderConfig(config),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func windowsConfig() map[string]interface{} {
|
|
|
|
username := os.Getenv("VSPHERE_USERNAME")
|
|
|
|
if username == "" {
|
|
|
|
username = "root"
|
|
|
|
}
|
|
|
|
password := os.Getenv("VSPHERE_PASSWORD")
|
|
|
|
if password == "" {
|
|
|
|
password = "jetbrains"
|
|
|
|
}
|
|
|
|
|
|
|
|
config := map[string]interface{}{
|
|
|
|
"vcenter_server": "vcenter.vsphere65.test",
|
|
|
|
"username": username,
|
|
|
|
"password": password,
|
|
|
|
"insecure_connection": true,
|
|
|
|
|
|
|
|
"vm_name": commonT.NewVMName(),
|
|
|
|
"template": "windows",
|
|
|
|
"host": "esxi-1.vsphere65.test",
|
|
|
|
"linked_clone": true, // speed up
|
|
|
|
|
|
|
|
"communicator": "winrm",
|
|
|
|
"winrm_username": "jetbrains",
|
|
|
|
"winrm_password": "jetbrains",
|
|
|
|
}
|
|
|
|
|
|
|
|
return config
|
|
|
|
}
|