Skip to content

Commit ec48458

Browse files
committed
feat: add acc test for sparse disk
Signed-off-by: Stoyan Zhelyazkov <[email protected]>
1 parent 011167d commit ec48458

File tree

1 file changed

+73
-4
lines changed

1 file changed

+73
-4
lines changed

vsphere/resource_vsphere_virtual_machine_test.go

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,35 @@ func TestAccResourceVSphereVirtualMachine_hardwareVersionBare(t *testing.T) {
100100
})
101101
}
102102

103+
func TestAccResourceVSphereVirtualMachine_fromSparseVmdk(t *testing.T) {
104+
t.Skipf("requires an existing 2gbsparse vmdk")
105+
// to run this test you need to create a vmdk on the target datastore
106+
// 1. ssh to an ESXi host with connection to the datastore
107+
// 2. create an empty folder on the datastore and `cd` inside (e.g. /vmfs/volumes/67fe111f-489f3741-b381-02007873e8d0/sparsedisks)
108+
// 3. create a regular sparse vmdk - vmkfstools -c 2g -d sesparse sparse.vmdk
109+
// 4. create a 2gbsparse vmdk from the regular one - vmkfstools -i sparse.vmdk sparse2.vmdk -d 2gbsparse
110+
// the test is pre-configured to look for a disk at [acc-test-nfs] sparsedisks/sparse2.vmdk. change if necessary
111+
resource.Test(t, resource.TestCase{
112+
PreCheck: func() {
113+
RunSweepers()
114+
testAccPreCheck(t)
115+
},
116+
Providers: testAccProviders,
117+
CheckDestroy: testAccResourceVSphereVirtualMachineCheckExists(false),
118+
Steps: []resource.TestStep{
119+
{
120+
Config: testAccResourceVSphereVirtualMachineConfigFromSparseVmdk(),
121+
Check: resource.ComposeTestCheckFunc(
122+
testAccResourceVSphereVirtualMachineCheckExists(true),
123+
resource.TestMatchResourceAttr("vsphere_virtual_machine.vm", "moid", regexp.MustCompile("^vm-")),
124+
),
125+
},
126+
},
127+
})
128+
}
129+
103130
func TestAccResourceVSphereVirtualMachine_vtpmCreate(t *testing.T) {
104-
t.Skipf("Requires key management server to run")
131+
t.Skipf("requires key management server to run")
105132
resource.Test(t, resource.TestCase{
106133
PreCheck: func() {
107134
RunSweepers()
@@ -122,7 +149,7 @@ func TestAccResourceVSphereVirtualMachine_vtpmCreate(t *testing.T) {
122149
}
123150

124151
func TestAccResourceVSphereVirtualMachine_vtpmAdd(t *testing.T) {
125-
t.Skipf("Requires key management server to run")
152+
t.Skipf("requires key management server to run")
126153
resource.Test(t, resource.TestCase{
127154
PreCheck: func() {
128155
RunSweepers()
@@ -150,7 +177,7 @@ func TestAccResourceVSphereVirtualMachine_vtpmAdd(t *testing.T) {
150177
}
151178

152179
func TestAccResourceVSphereVirtualMachine_vtpmRemove(t *testing.T) {
153-
t.Skipf("Requires key management server to run")
180+
t.Skipf("requires key management server to run")
154181
resource.Test(t, resource.TestCase{
155182
PreCheck: func() {
156183
RunSweepers()
@@ -178,7 +205,7 @@ func TestAccResourceVSphereVirtualMachine_vtpmRemove(t *testing.T) {
178205
}
179206

180207
func TestAccResourceVSphereVirtualMachine_vtpmClone(t *testing.T) {
181-
t.Skipf("Requires key management server to run")
208+
t.Skipf("requires key management server to run")
182209
resource.Test(t, resource.TestCase{
183210
PreCheck: func() {
184211
RunSweepers()
@@ -4145,6 +4172,48 @@ resource "vsphere_virtual_machine" "vm" {
41454172
)
41464173
}
41474174

4175+
func testAccResourceVSphereVirtualMachineConfigFromSparseVmdk() string {
4176+
return fmt.Sprintf(`
4177+
4178+
4179+
%s // Mix and match config
4180+
4181+
resource "vsphere_virtual_machine" "vm" {
4182+
name = "testacc-test"
4183+
resource_pool_id = vsphere_resource_pool.pool1.id
4184+
datastore_id = data.vsphere_datastore.rootds1.id
4185+
4186+
num_cpus = 2
4187+
memory = 2048
4188+
guest_id = "other3xLinuxGuest"
4189+
firmware = "efi"
4190+
4191+
wait_for_guest_net_timeout = 0
4192+
4193+
cdrom {
4194+
client_device = true
4195+
}
4196+
4197+
network_interface {
4198+
network_id = data.vsphere_network.network1.id
4199+
}
4200+
4201+
disk {
4202+
label = "disk0"
4203+
attach = true
4204+
datastore_id = data.vsphere_datastore.rootds1.id
4205+
path = "[acc-test-nfs] sparsedisks/sparse2.vmdk"
4206+
controller_type = "ide"
4207+
unit_number = 1
4208+
io_reservation = 1
4209+
}
4210+
}
4211+
`,
4212+
4213+
testAccResourceVSphereVirtualMachineConfigBase(),
4214+
)
4215+
}
4216+
41484217
func testAccResourceVSphereVirtualMachineConfigSharedSCSIBus() string {
41494218
return fmt.Sprintf(`
41504219

0 commit comments

Comments
 (0)