provider/openstack: Adding Timeouts to Image v2 and LBaaS v2 Resources (#12865)

This commit is contained in:
Joe Topjian 2017-03-19 11:14:20 -06:00 committed by Paul Stack
parent 3457772bab
commit adbc87f1e7
10 changed files with 290 additions and 9 deletions

View File

@ -29,6 +29,10 @@ func resourceImagesImageV2() *schema.Resource {
State: schema.ImportStatePassthrough,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
},
Schema: map[string]*schema.Schema{
"checksum": &schema.Schema{
Type: schema.TypeString,
@ -226,7 +230,7 @@ func resourceImagesImageV2Create(d *schema.ResourceData, meta interface{}) error
Pending: []string{string(images.ImageStatusQueued), string(images.ImageStatusSaving)},
Target: []string{string(images.ImageStatusActive)},
Refresh: resourceImagesImageV2RefreshFunc(imageClient, d.Id(), fileSize, fileChecksum),
Timeout: 30 * time.Minute,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
}

View File

@ -135,6 +135,24 @@ func TestAccImagesImageV2_visibility(t *testing.T) {
})
}
func TestAccImagesImageV2_timeout(t *testing.T) {
var image images.Image
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckImagesImageV2Destroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccImagesImageV2_timeout,
Check: resource.ComposeTestCheckFunc(
testAccCheckImagesImageV2Exists("openstack_images_image_v2.image_1", &image),
),
},
},
})
}
func testAccCheckImagesImageV2Destroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
imageClient, err := config.imageV2Client(OS_REGION_NAME)
@ -326,3 +344,15 @@ var testAccImagesImageV2_visibility_2 = `
disk_format = "qcow2"
visibility = "public"
}`
var testAccImagesImageV2_timeout = `
resource "openstack_images_image_v2" "image_1" {
name = "Rancher TerraformAccTest"
image_source_url = "https://releases.rancher.com/os/latest/rancheros-openstack.img"
container_format = "bare"
disk_format = "qcow2"
timeouts {
create = "10m"
}
}`

View File

@ -20,6 +20,11 @@ func resourceLoadBalancerV2() *schema.Resource {
Update: resourceLoadBalancerV2Update,
Delete: resourceLoadBalancerV2Delete,
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(20 * time.Minute),
Delete: schema.DefaultTimeout(10 * time.Minute),
},
Schema: map[string]*schema.Schema{
"region": &schema.Schema{
Type: schema.TypeString,
@ -138,7 +143,7 @@ func resourceLoadBalancerV2Create(d *schema.ResourceData, meta interface{}) erro
Pending: []string{"PENDING_CREATE"},
Target: []string{"ACTIVE"},
Refresh: waitForLoadBalancerActive(networkingClient, lb.ID),
Timeout: 20 * time.Minute,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 5 * time.Second,
MinTimeout: 3 * time.Second,
}
@ -245,7 +250,7 @@ func resourceLoadBalancerV2Delete(d *schema.ResourceData, meta interface{}) erro
Pending: []string{"ACTIVE", "PENDING_DELETE"},
Target: []string{"DELETED"},
Refresh: waitForLoadBalancerDelete(networkingClient, d.Id()),
Timeout: 2 * time.Minute,
Timeout: d.Timeout(schema.TimeoutDelete),
Delay: 5 * time.Second,
MinTimeout: 3 * time.Second,
}

View File

@ -97,6 +97,24 @@ func TestAccLBV2LoadBalancer_secGroup(t *testing.T) {
})
}
func TestAccLBV2LoadBalancer_timeout(t *testing.T) {
var lb loadbalancers.LoadBalancer
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLBV2LoadBalancerDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccLBV2LoadBalancerConfig_timeout,
Check: resource.ComposeTestCheckFunc(
testAccCheckLBV2LoadBalancerExists("openstack_lb_loadbalancer_v2.loadbalancer_1", &lb),
),
},
},
})
}
func testAccCheckLBV2LoadBalancerDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
@ -310,3 +328,28 @@ resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
depends_on = ["openstack_networking_secgroup_v2.secgroup_1"]
}
`
const testAccLBV2LoadBalancerConfig_timeout = `
resource "openstack_networking_network_v2" "network_1" {
name = "network_1"
admin_state_up = "true"
}
resource "openstack_networking_subnet_v2" "subnet_1" {
name = "subnet_1"
cidr = "192.168.199.0/24"
ip_version = 4
network_id = "${openstack_networking_network_v2.network_1.id}"
}
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
name = "loadbalancer_1"
loadbalancer_provider = "haproxy"
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
timeouts {
create = "5m"
delete = "5m"
}
}
`

View File

@ -19,6 +19,11 @@ func resourceMemberV2() *schema.Resource {
Update: resourceMemberV2Update,
Delete: resourceMemberV2Delete,
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,
@ -152,7 +157,7 @@ func resourceMemberV2Create(d *schema.ResourceData, meta interface{}) error {
Pending: []string{"PENDING_CREATE"},
Target: []string{"ACTIVE"},
Refresh: waitForMemberActive(networkingClient, poolID, member.ID),
Timeout: 2 * time.Minute,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 5 * time.Second,
MinTimeout: 3 * time.Second,
}
@ -233,7 +238,7 @@ func resourceMemberV2Delete(d *schema.ResourceData, meta interface{}) error {
Pending: []string{"ACTIVE", "PENDING_DELETE"},
Target: []string{"DELETED"},
Refresh: waitForMemberDelete(networkingClient, d.Get("pool_id").(string), d.Id()),
Timeout: 2 * time.Minute,
Timeout: d.Timeout(schema.TimeoutDelete),
Delay: 5 * time.Second,
MinTimeout: 3 * time.Second,
}

View File

@ -33,6 +33,24 @@ func TestAccLBV2Member_basic(t *testing.T) {
})
}
func TestAccLBV2Member_timeout(t *testing.T) {
var member pools.Member
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLBV2MemberDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: TestAccLBV2MemberConfig_timeout,
Check: resource.ComposeTestCheckFunc(
testAccCheckLBV2MemberExists("openstack_lb_member_v2.member_1", &member),
),
},
},
})
}
func testAccCheckLBV2MemberDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
@ -169,3 +187,48 @@ resource "openstack_lb_member_v2" "member_1" {
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
}
`
const TestAccLBV2MemberConfig_timeout = `
resource "openstack_networking_network_v2" "network_1" {
name = "network_1"
admin_state_up = "true"
}
resource "openstack_networking_subnet_v2" "subnet_1" {
name = "subnet_1"
network_id = "${openstack_networking_network_v2.network_1.id}"
cidr = "192.168.199.0/24"
ip_version = 4
}
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
name = "loadbalancer_1"
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
}
resource "openstack_lb_listener_v2" "listener_1" {
name = "listener_1"
protocol = "HTTP"
protocol_port = 8080
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
}
resource "openstack_lb_pool_v2" "pool_1" {
name = "pool_1"
protocol = "HTTP"
lb_method = "ROUND_ROBIN"
listener_id = "${openstack_lb_listener_v2.listener_1.id}"
}
resource "openstack_lb_member_v2" "member_1" {
address = "192.168.199.10"
protocol_port = 8080
pool_id = "${openstack_lb_pool_v2.pool_1.id}"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
timeouts {
create = "5m"
delete = "5m"
}
}
`

View File

@ -19,6 +19,11 @@ func resourceMonitorV2() *schema.Resource {
Update: resourceMonitorV2Update,
Delete: resourceMonitorV2Delete,
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,
@ -127,7 +132,7 @@ func resourceMonitorV2Create(d *schema.ResourceData, meta interface{}) error {
Pending: []string{"PENDING_CREATE"},
Target: []string{"ACTIVE"},
Refresh: waitForMonitorActive(networkingClient, monitor.ID),
Timeout: 2 * time.Minute,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 5 * time.Second,
MinTimeout: 3 * time.Second,
}
@ -226,7 +231,7 @@ func resourceMonitorV2Delete(d *schema.ResourceData, meta interface{}) error {
Pending: []string{"ACTIVE", "PENDING_DELETE"},
Target: []string{"DELETED"},
Refresh: waitForMonitorDelete(networkingClient, d.Id()),
Timeout: 2 * time.Minute,
Timeout: d.Timeout(schema.TimeoutDelete),
Delay: 5 * time.Second,
MinTimeout: 3 * time.Second,
}

View File

@ -36,6 +36,24 @@ func TestAccLBV2Monitor_basic(t *testing.T) {
})
}
func TestAccLBV2Monitor_timeout(t *testing.T) {
var monitor monitors.Monitor
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLBV2MonitorDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: TestAccLBV2MonitorConfig_timeout,
Check: resource.ComposeTestCheckFunc(
testAccCheckLBV2MonitorExists(t, "openstack_lb_monitor_v2.monitor_1", &monitor),
),
},
},
})
}
func testAccCheckLBV2MonitorDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
@ -173,3 +191,50 @@ resource "openstack_lb_monitor_v2" "monitor_1" {
pool_id = "${openstack_lb_pool_v2.pool_1.id}"
}
`
const TestAccLBV2MonitorConfig_timeout = `
resource "openstack_networking_network_v2" "network_1" {
name = "network_1"
admin_state_up = "true"
}
resource "openstack_networking_subnet_v2" "subnet_1" {
name = "subnet_1"
cidr = "192.168.199.0/24"
ip_version = 4
network_id = "${openstack_networking_network_v2.network_1.id}"
}
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
name = "loadbalancer_1"
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
}
resource "openstack_lb_listener_v2" "listener_1" {
name = "listener_1"
protocol = "HTTP"
protocol_port = 8080
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
}
resource "openstack_lb_pool_v2" "pool_1" {
name = "pool_1"
protocol = "HTTP"
lb_method = "ROUND_ROBIN"
listener_id = "${openstack_lb_listener_v2.listener_1.id}"
}
resource "openstack_lb_monitor_v2" "monitor_1" {
name = "monitor_1"
type = "PING"
delay = 20
timeout = 10
max_retries = 5
pool_id = "${openstack_lb_pool_v2.pool_1.id}"
timeouts {
create = "5m"
delete = "5m"
}
}
`

View File

@ -19,6 +19,11 @@ func resourcePoolV2() *schema.Resource {
Update: resourcePoolV2Update,
Delete: resourcePoolV2Delete,
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,
@ -174,7 +179,7 @@ func resourcePoolV2Create(d *schema.ResourceData, meta interface{}) error {
Pending: []string{"PENDING_CREATE"},
Target: []string{"ACTIVE"},
Refresh: waitForPoolActive(networkingClient, pool.ID),
Timeout: 2 * time.Minute,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 5 * time.Second,
MinTimeout: 3 * time.Second,
}
@ -258,7 +263,7 @@ func resourcePoolV2Delete(d *schema.ResourceData, meta interface{}) error {
Pending: []string{"ACTIVE", "PENDING_DELETE"},
Target: []string{"DELETED"},
Refresh: waitForPoolDelete(networkingClient, d.Id()),
Timeout: 2 * time.Minute,
Timeout: d.Timeout(schema.TimeoutDelete),
Delay: 5 * time.Second,
MinTimeout: 3 * time.Second,
}

View File

@ -33,6 +33,24 @@ func TestAccLBV2Pool_basic(t *testing.T) {
})
}
func TestAccLBV2Pool_timeout(t *testing.T) {
var pool pools.Pool
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLBV2PoolDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: TestAccLBV2PoolConfig_timeout,
Check: resource.ComposeTestCheckFunc(
testAccCheckLBV2PoolExists("openstack_lb_pool_v2.pool_1", &pool),
),
},
},
})
}
func testAccCheckLBV2PoolDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
@ -152,3 +170,41 @@ resource "openstack_lb_pool_v2" "pool_1" {
listener_id = "${openstack_lb_listener_v2.listener_1.id}"
}
`
const TestAccLBV2PoolConfig_timeout = `
resource "openstack_networking_network_v2" "network_1" {
name = "network_1"
admin_state_up = "true"
}
resource "openstack_networking_subnet_v2" "subnet_1" {
name = "subnet_1"
cidr = "192.168.199.0/24"
ip_version = 4
network_id = "${openstack_networking_network_v2.network_1.id}"
}
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
name = "loadbalancer_1"
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
}
resource "openstack_lb_listener_v2" "listener_1" {
name = "listener_1"
protocol = "HTTP"
protocol_port = 8080
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
}
resource "openstack_lb_pool_v2" "pool_1" {
name = "pool_1"
protocol = "HTTP"
lb_method = "ROUND_ROBIN"
listener_id = "${openstack_lb_listener_v2.listener_1.id}"
timeouts {
create = "5m"
delete = "5m"
}
}
`