provider/openstack: Adding Timeouts to Blockstorage Resources (#12862)

This commit is contained in:
Joe Topjian 2017-03-19 11:07:26 -06:00 committed by Paul Stack
parent 98ee99f405
commit e37b26a3fa
6 changed files with 123 additions and 6 deletions

View File

@ -19,6 +19,11 @@ func resourceBlockStorageVolumeAttachV2() *schema.Resource {
Read: resourceBlockStorageVolumeAttachV2Read,
Delete: resourceBlockStorageVolumeAttachV2Delete,
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(10 * time.Minute),
},
Schema: map[string]*schema.Schema{
"region": &schema.Schema{
Type: schema.TypeString,
@ -231,7 +236,7 @@ func resourceBlockStorageVolumeAttachV2Create(d *schema.ResourceData, meta inter
Pending: []string{"available", "attaching"},
Target: []string{"in-use"},
Refresh: VolumeV2StateRefreshFunc(client, volumeId),
Timeout: 10 * time.Minute,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
}
@ -369,7 +374,7 @@ func resourceBlockStorageVolumeAttachV2Delete(d *schema.ResourceData, meta inter
Pending: []string{"in-use", "attaching", "detaching"},
Target: []string{"available"},
Refresh: VolumeV2StateRefreshFunc(client, volumeId),
Timeout: 10 * time.Minute,
Timeout: d.Timeout(schema.TimeoutDelete),
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
}

View File

@ -29,6 +29,24 @@ func TestAccBlockStorageVolumeAttachV2_basic(t *testing.T) {
})
}
func TestAccBlockStorageVolumeAttachV2_timeout(t *testing.T) {
var va volumes.Attachment
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBlockStorageVolumeAttachV2Destroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccBlockStorageVolumeAttachV2_timeout,
Check: resource.ComposeTestCheckFunc(
testAccCheckBlockStorageVolumeAttachV2Exists("openstack_blockstorage_volume_attach_v2.va_1", &va),
),
},
},
})
}
func testAccCheckBlockStorageVolumeAttachV2Destroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
client, err := config.blockStorageV2Client(OS_REGION_NAME)
@ -124,3 +142,25 @@ resource "openstack_blockstorage_volume_attach_v2" "va_1" {
platform = "x86_64"
}
`
const testAccBlockStorageVolumeAttachV2_timeout = `
resource "openstack_blockstorage_volume_v2" "volume_1" {
name = "volume_1"
size = 1
}
resource "openstack_blockstorage_volume_attach_v2" "va_1" {
volume_id = "${openstack_blockstorage_volume_v2.volume_1.id}"
device = "auto"
host_name = "devstack"
ip_address = "192.168.255.10"
initiator = "iqn.1993-08.org.debian:01:e9861fb1859"
os_type = "linux2"
platform = "x86_64"
timeouts {
create = "5m"
}
}
`

View File

@ -24,6 +24,11 @@ func resourceBlockStorageVolumeV1() *schema.Resource {
State: schema.ImportStatePassthrough,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(10 * time.Minute),
},
Schema: map[string]*schema.Schema{
"region": &schema.Schema{
Type: schema.TypeString,
@ -139,7 +144,7 @@ func resourceBlockStorageVolumeV1Create(d *schema.ResourceData, meta interface{}
Pending: []string{"downloading", "creating"},
Target: []string{"available"},
Refresh: VolumeV1StateRefreshFunc(blockStorageClient, v.ID),
Timeout: 10 * time.Minute,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
}
@ -278,7 +283,7 @@ func resourceBlockStorageVolumeV1Delete(d *schema.ResourceData, meta interface{}
Pending: []string{"deleting", "downloading", "available"},
Target: []string{"deleted"},
Refresh: VolumeV1StateRefreshFunc(blockStorageClient, d.Id()),
Timeout: 10 * time.Minute,
Timeout: d.Timeout(schema.TimeoutDelete),
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
}

View File

@ -61,6 +61,24 @@ func TestAccBlockStorageV1Volume_image(t *testing.T) {
})
}
func TestAccBlockStorageV1Volume_timeout(t *testing.T) {
var volume volumes.Volume
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBlockStorageV1VolumeDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccBlockStorageV1Volume_timeout,
Check: resource.ComposeTestCheckFunc(
testAccCheckBlockStorageV1VolumeExists("openstack_blockstorage_volume_v1.volume_1", &volume),
),
},
},
})
}
func testAccCheckBlockStorageV1VolumeDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
blockStorageClient, err := config.blockStorageV1Client(OS_REGION_NAME)
@ -188,3 +206,16 @@ resource "openstack_blockstorage_volume_v1" "volume_1" {
image_id = "%s"
}
`, OS_IMAGE_ID)
const testAccBlockStorageV1Volume_timeout = `
resource "openstack_blockstorage_volume_v1" "volume_1" {
name = "volume_1"
description = "first test volume"
size = 1
timeouts {
create = "5m"
delete = "5m"
}
}
`

View File

@ -24,6 +24,11 @@ func resourceBlockStorageVolumeV2() *schema.Resource {
State: schema.ImportStatePassthrough,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(10 * time.Minute),
},
Schema: map[string]*schema.Schema{
"region": &schema.Schema{
Type: schema.TypeString,
@ -151,7 +156,7 @@ func resourceBlockStorageVolumeV2Create(d *schema.ResourceData, meta interface{}
Pending: []string{"downloading", "creating"},
Target: []string{"available"},
Refresh: VolumeV2StateRefreshFunc(blockStorageClient, v.ID),
Timeout: 10 * time.Minute,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
}
@ -289,7 +294,7 @@ func resourceBlockStorageVolumeV2Delete(d *schema.ResourceData, meta interface{}
Pending: []string{"deleting", "downloading", "available"},
Target: []string{"deleted"},
Refresh: VolumeV2StateRefreshFunc(blockStorageClient, d.Id()),
Timeout: 10 * time.Minute,
Timeout: d.Timeout(schema.TimeoutDelete),
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
}

View File

@ -61,6 +61,24 @@ func TestAccBlockStorageV2Volume_image(t *testing.T) {
})
}
func TestAccBlockStorageV2Volume_timeout(t *testing.T) {
var volume volumes.Volume
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBlockStorageV2VolumeDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccBlockStorageV2Volume_timeout,
Check: resource.ComposeTestCheckFunc(
testAccCheckBlockStorageV2VolumeExists("openstack_blockstorage_volume_v2.volume_1", &volume),
),
},
},
})
}
func testAccCheckBlockStorageV2VolumeDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
blockStorageClient, err := config.blockStorageV2Client(OS_REGION_NAME)
@ -186,3 +204,16 @@ resource "openstack_blockstorage_volume_v2" "volume_1" {
image_id = "%s"
}
`, OS_IMAGE_ID)
const testAccBlockStorageV2Volume_timeout = `
resource "openstack_blockstorage_volume_v2" "volume_1" {
name = "volume_1"
description = "first test volume"
size = 1
timeouts {
create = "5m"
delete = "5m"
}
}
`