provider/openstack: Handle Volume Creation Errors (#10821)

This commit makes the openstack_blockstorage_volume resources better able
to handle volume creation errors upon resource creation. The cause of this
change is because there could be some storage backend error that happens
during storage provisioning that won't manifest in an "err" but will set
the volume's status to "error". We now check for a status of "error" and
propagate the error up the stack.
This commit is contained in:
Joe Topjian 2016-12-18 15:38:55 -07:00 committed by Paul Stack
parent 2283f0c166
commit 7843a5c6e6
2 changed files with 18 additions and 6 deletions

View File

@ -130,9 +130,6 @@ func resourceBlockStorageVolumeV1Create(d *schema.ResourceData, meta interface{}
}
log.Printf("[INFO] Volume ID: %s", v.ID)
// Store the ID now
d.SetId(v.ID)
// Wait for the volume to become available.
log.Printf(
"[DEBUG] Waiting for volume (%s) to become available",
@ -154,6 +151,9 @@ func resourceBlockStorageVolumeV1Create(d *schema.ResourceData, meta interface{}
v.ID, err)
}
// Store the ID now
d.SetId(v.ID)
return resourceBlockStorageVolumeV1Read(d, meta)
}
@ -314,6 +314,12 @@ func VolumeV1StateRefreshFunc(client *gophercloud.ServiceClient, volumeID string
return nil, "", err
}
if v.Status == "error" {
return v, v.Status, fmt.Errorf("There was an error creating the volume. " +
"Please check with your cloud admin or check the Block Storage " +
"API logs to see why this error occurred.")
}
return v, v.Status, nil
}
}

View File

@ -142,9 +142,6 @@ func resourceBlockStorageVolumeV2Create(d *schema.ResourceData, meta interface{}
}
log.Printf("[INFO] Volume ID: %s", v.ID)
// Store the ID now
d.SetId(v.ID)
// Wait for the volume to become available.
log.Printf(
"[DEBUG] Waiting for volume (%s) to become available",
@ -166,6 +163,9 @@ func resourceBlockStorageVolumeV2Create(d *schema.ResourceData, meta interface{}
v.ID, err)
}
// Store the ID now
d.SetId(v.ID)
return resourceBlockStorageVolumeV2Read(d, meta)
}
@ -325,6 +325,12 @@ func VolumeV2StateRefreshFunc(client *gophercloud.ServiceClient, volumeID string
return nil, "", err
}
if v.Status == "error" {
return v, v.Status, fmt.Errorf("There was an error creating the volume. " +
"Please check with your cloud admin or check the Block Storage " +
"API logs to see why this error occurred.")
}
return v, v.Status, nil
}
}