Merge pull request #7649 from jtopjian/openstack-boot-volume-fix
provider/openstack: Fixing boot volume interference
This commit is contained in:
commit
30273faf20
|
@ -1436,12 +1436,25 @@ func getVolumeAttachments(computeClient *gophercloud.ServiceClient, d *schema.Re
|
|||
return err
|
||||
}
|
||||
|
||||
vols := make([]map[string]interface{}, len(attachments))
|
||||
for i, attachment := range attachments {
|
||||
vols[i] = make(map[string]interface{})
|
||||
vols[i]["id"] = attachment.ID
|
||||
vols[i]["volume_id"] = attachment.VolumeID
|
||||
vols[i]["device"] = attachment.Device
|
||||
var vols []map[string]interface{}
|
||||
for _, attachment := range attachments {
|
||||
// ignore the volume if it is attached as a root device
|
||||
rootDevFound := false
|
||||
for _, rootDev := range []string{"/dev/vda", "/dev/xda", "/dev/sda", "/dev/xvda"} {
|
||||
if attachment.Device == rootDev {
|
||||
rootDevFound = true
|
||||
}
|
||||
}
|
||||
|
||||
if rootDevFound {
|
||||
continue
|
||||
}
|
||||
|
||||
vol := make(map[string]interface{})
|
||||
vol["id"] = attachment.ID
|
||||
vol["volume_id"] = attachment.VolumeID
|
||||
vol["device"] = attachment.Device
|
||||
vols = append(vols, vol)
|
||||
}
|
||||
log.Printf("[INFO] Volume attachments: %v", vols)
|
||||
d.Set("volume", vols)
|
||||
|
|
|
@ -472,6 +472,47 @@ func TestAccComputeV2Instance_bootFromVolumeImage(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccComputeV2Instance_bootFromVolumeImageWithAttachedVolume(t *testing.T) {
|
||||
var instance servers.Server
|
||||
var testAccComputeV2Instance_bootFromVolumeImageWithAttachedVolume = fmt.Sprintf(`
|
||||
resource "openstack_blockstorage_volume_v1" "volume_1" {
|
||||
name = "volume_1"
|
||||
size = 1
|
||||
}
|
||||
|
||||
resource "openstack_compute_instance_v2" "instance_1" {
|
||||
name = "instance_1"
|
||||
security_groups = ["default"]
|
||||
block_device {
|
||||
uuid = "%s"
|
||||
source_type = "image"
|
||||
volume_size = 2
|
||||
boot_index = 0
|
||||
destination_type = "volume"
|
||||
delete_on_termination = true
|
||||
}
|
||||
|
||||
volume {
|
||||
volume_id = "${openstack_blockstorage_volume_v1.volume_1.id}"
|
||||
}
|
||||
}`,
|
||||
os.Getenv("OS_IMAGE_ID"))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckComputeV2InstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeV2Instance_bootFromVolumeImageWithAttachedVolume,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.instance_1", &instance),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccComputeV2Instance_bootFromVolumeVolume(t *testing.T) {
|
||||
var instance servers.Server
|
||||
var testAccComputeV2Instance_bootFromVolumeVolume = fmt.Sprintf(`
|
||||
|
|
Loading…
Reference in New Issue