Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/ovirt_vm: Do not change VM status after updating #167

Merged
merged 1 commit into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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