Add cdrom test for iso builder
This commit is contained in:
parent
6235ecc129
commit
0861dbc283
|
@ -5,6 +5,7 @@ import (
|
||||||
commonT "github.com/jetbrains-infra/packer-builder-vsphere/common/testing"
|
commonT "github.com/jetbrains-infra/packer-builder-vsphere/common/testing"
|
||||||
"testing"
|
"testing"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
|
"github.com/vmware/govmomi/vim25/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestISOBuilderAcc_default(t *testing.T) {
|
func TestISOBuilderAcc_default(t *testing.T) {
|
||||||
|
@ -28,7 +29,7 @@ func defaultConfig() map[string]interface{} {
|
||||||
"ssh_username": "root",
|
"ssh_username": "root",
|
||||||
"ssh_password": "jetbrains",
|
"ssh_password": "jetbrains",
|
||||||
|
|
||||||
"vm_name": commonT.NewVMName(),
|
"vm_name": commonT.NewVMName(),
|
||||||
"communicator": "none", // do not start the VM without any bootable devices
|
"communicator": "none", // do not start the VM without any bootable devices
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,6 +153,7 @@ func TestISOBuilderAcc_cdrom(t *testing.T) {
|
||||||
builderT.Test(t, builderT.TestCase{
|
builderT.Test(t, builderT.TestCase{
|
||||||
Builder: &Builder{},
|
Builder: &Builder{},
|
||||||
Template: cdromConfig(),
|
Template: cdromConfig(),
|
||||||
|
Check: checkCDRom(t),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,6 +163,33 @@ func cdromConfig() string {
|
||||||
return commonT.RenderConfig(config)
|
return commonT.RenderConfig(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkCDRom(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)
|
||||||
|
}
|
||||||
|
|
||||||
|
cdrom, err := devices.FindCdrom("")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("cannot find cdrom: %v", err)
|
||||||
|
}
|
||||||
|
iso, ok := cdrom.Backing.(*types.VirtualCdromIsoBackingInfo)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("the iso is not connected")
|
||||||
|
}
|
||||||
|
expectedFileName := "[datastore1] alpine-standard-3.6.2-x86_64.iso"
|
||||||
|
if iso.FileName != expectedFileName {
|
||||||
|
t.Fatalf("invalid iso filename: expected '%v', got '%v'", expectedFileName, iso.FileName)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestISOBuilderAcc_networkCard(t *testing.T) {
|
func TestISOBuilderAcc_networkCard(t *testing.T) {
|
||||||
builderT.Test(t, builderT.TestCase{
|
builderT.Test(t, builderT.TestCase{
|
||||||
Builder: &Builder{},
|
Builder: &Builder{},
|
||||||
|
@ -184,12 +213,17 @@ func checkNetworkCard(t *testing.T) builderT.TestCheckFunc {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Cannot read VM properties: %v", err)
|
t.Fatalf("Cannot read VM properties: %v", err)
|
||||||
}
|
}
|
||||||
for _, device := range devices {
|
|
||||||
if devices.TypeName(device) == "VirtualVmxnet3" {
|
netCards := devices.SelectByType((*types.VirtualEthernetCard)(nil))
|
||||||
return 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)")
|
||||||
}
|
}
|
||||||
t.Errorf("Cannot find selected network card")
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue