Skip to content

Commit

Permalink
Added test to check reboots in case of guest customisation is used (r…
Browse files Browse the repository at this point in the history
…emove CDrom)
  • Loading branch information
yannickstruyf3 committed Mar 17, 2020
1 parent 7f7a130 commit 5d0a48f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
6 changes: 6 additions & 0 deletions nutanix/resource_nutanix_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1175,10 +1175,16 @@ func resourceNutanixVirtualMachineUpdate(d *schema.ResourceData, meta interface{

if d.HasChange("disk_list") {
preCdromCount, err := CountDiskListCdrom(res.DiskList)
if err != nil {
return err
}
if res.DiskList, err = expandDiskList(d, false); err != nil {
return err
}
postCdromCount, err := CountDiskListCdrom(res.DiskList)
if err != nil {
return err
}
if preCdromCount != postCdromCount {
hotPlugChange = false
}
Expand Down
52 changes: 52 additions & 0 deletions nutanix/resource_nutanix_virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,37 @@ func TestAccNutanixVirtualMachine_PowerStateMechanism(t *testing.T) {
})
}

func TestAccNutanixVirtualMachine_CdromGuestCustomisationReboot(t *testing.T) {
r := acctest.RandInt()
resourceName := "nutanix_virtual_machine.vm7"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNutanixVirtualMachineDestroy,
Steps: []resource.TestStep{
{
Config: testAccNutanixVMConfigCdromGuestCustomisationReboot(r),
Check: resource.ComposeTestCheckFunc(
testAccCheckNutanixVirtualMachineExists(resourceName),
),
ExpectNonEmptyPlan: true,
},
{
Config: testAccNutanixVMConfigCdromGuestCustomisationReboot(r),
Check: resource.ComposeTestCheckFunc(
testAccCheckNutanixVirtualMachineExists(resourceName),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"disk_list"},
},
},
})
}

func testAccCheckNutanixVirtualMachineExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -579,3 +610,24 @@ resource "nutanix_virtual_machine" "vm6" {
}
`, r)
}

func testAccNutanixVMConfigCdromGuestCustomisationReboot(r int) string {
return fmt.Sprintf(`
data "nutanix_clusters" "clusters" {}
locals {
cluster1 = "${data.nutanix_clusters.clusters.entities.0.service_list.0 == "PRISM_CENTRAL"
? data.nutanix_clusters.clusters.entities.1.metadata.uuid : data.nutanix_clusters.clusters.entities.0.metadata.uuid}"
}
resource "nutanix_virtual_machine" "vm7" {
name = "test-dou-%d"
cluster_uuid = "${local.cluster1}"
num_vcpus_per_socket = 1
num_sockets = 1
memory_size_mib = 186
guest_customization_cloud_init_user_data = base64encode("#cloud-config\nfqdn: test.domain.local")
}
`, r)
}

0 comments on commit 5d0a48f

Please sign in to comment.