Skip to content

Commit

Permalink
Merge pull request #167 from imjoey/no_state_change_updating_vm
Browse files Browse the repository at this point in the history
resource/ovirt_vm: Do not change VM status after updating
  • Loading branch information
imjoey authored Jul 31, 2019
2 parents ff5d20c + 5b8ca43 commit 9d6a846
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
19 changes: 0 additions & 19 deletions ovirt/resource_ovirt_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,25 +447,6 @@ func resourceOvirtVMUpdate(d *schema.ResourceData, meta interface{}) error {
}
}

// Any way, ensure the VM is UP

// Currently only support cloud-init for Linux VMs
_, useCloudInit := d.GetOk("initialization")
vmService.Start().UseCloudInit(useCloudInit).Send()

upStateConf := &resource.StateChangeConf{
Target: []string{string(ovirtsdk4.VMSTATUS_DOWN)},
Refresh: VMStateRefreshFunc(conn, d.Id()),
Timeout: d.Timeout(schema.TimeoutUpdate),
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
}
_, err := upStateConf.WaitForState()
if err != nil {
log.Printf("[DEBUG] Failed to wait for VM (%s) to become down: %s", d.Id(), err)
return fmt.Errorf("Error starting vm: %s", err)
}

d.Partial(false)
return resourceOvirtVMRead(d, meta)
}
Expand Down
30 changes: 30 additions & 0 deletions ovirt/resource_ovirt_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ func TestAccOvirtVM_basic(t *testing.T) {
resource.TestCheckResourceAttr("ovirt_vm.vm", "name", "testAccVMBasic"),
resource.TestCheckResourceAttr("ovirt_vm.vm", "status", "up"),
resource.TestCheckResourceAttr("ovirt_vm.vm", "memory", "2048"),
resource.TestCheckResourceAttr("ovirt_vm.vm", "initialization.0.dns_servers", "8.8.8.8 8.8.4.4"),
),
},
{
Config: testAccVMBasicUpdate(clusterID, templateID),
Check: resource.ComposeTestCheckFunc(
testAccCheckOvirtVMExists("ovirt_vm.vm", &vm),
resource.TestCheckResourceAttr("ovirt_vm.vm", "name", "testAccVMBasic"),
resource.TestCheckResourceAttr("ovirt_vm.vm", "status", "up"),
resource.TestCheckResourceAttr("ovirt_vm.vm", "memory", "2048"),
resource.TestCheckResourceAttr("ovirt_vm.vm", "initialization.0.dns_servers", "114.114.114.114"),
),
},
},
Expand Down Expand Up @@ -287,6 +298,25 @@ resource "ovirt_vm" "vm" {
`, clusterID, templateID)
}

func testAccVMBasicUpdate(clusterID, templateID string) string {
return fmt.Sprintf(`
resource "ovirt_vm" "vm" {
name = "testAccVMBasic"
cluster_id = "%s"
template_id = "%s"
memory = 2048
initialization {
host_name = "vm-basic-1"
timezone = "Asia/Shanghai"
user_name = "root"
custom_script = "echo hello"
dns_search = "university.edu"
dns_servers = "114.114.114.114"
}
}
`, clusterID, templateID)
}

const testAccVMBlockDevice = `
resource "ovirt_vm" "vm" {
name = "testAccVMBlockDevice"
Expand Down

0 comments on commit 9d6a846

Please sign in to comment.