provider/openstack: Adding Timeouts to LBaaS v1 Resources (#12867)

This commit is contained in:
Joe Topjian 2017-03-19 11:18:03 -06:00 committed by Paul Stack
parent 1b6fb24590
commit fbf1732a7b
8 changed files with 212 additions and 10 deletions

View File

@ -22,6 +22,11 @@ func resourceLBMemberV1() *schema.Resource {
State: schema.ImportStatePassthrough, State: schema.ImportStatePassthrough,
}, },
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(10 * time.Minute),
},
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"region": &schema.Schema{ "region": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
@ -91,7 +96,7 @@ func resourceLBMemberV1Create(d *schema.ResourceData, meta interface{}) error {
Pending: []string{"PENDING_CREATE"}, Pending: []string{"PENDING_CREATE"},
Target: []string{"ACTIVE", "INACTIVE", "CREATED", "DOWN"}, Target: []string{"ACTIVE", "INACTIVE", "CREATED", "DOWN"},
Refresh: waitForLBMemberActive(networkingClient, m.ID), Refresh: waitForLBMemberActive(networkingClient, m.ID),
Timeout: 2 * time.Minute, Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 5 * time.Second, Delay: 5 * time.Second,
MinTimeout: 3 * time.Second, MinTimeout: 3 * time.Second,
} }
@ -181,7 +186,7 @@ func resourceLBMemberV1Delete(d *schema.ResourceData, meta interface{}) error {
Pending: []string{"ACTIVE", "PENDING_DELETE"}, Pending: []string{"ACTIVE", "PENDING_DELETE"},
Target: []string{"DELETED"}, Target: []string{"DELETED"},
Refresh: waitForLBMemberDelete(networkingClient, d.Id()), Refresh: waitForLBMemberDelete(networkingClient, d.Id()),
Timeout: 2 * time.Minute, Timeout: d.Timeout(schema.TimeoutDelete),
Delay: 5 * time.Second, Delay: 5 * time.Second,
MinTimeout: 3 * time.Second, MinTimeout: 3 * time.Second,
} }

View File

@ -33,6 +33,24 @@ func TestAccLBV1Member_basic(t *testing.T) {
}) })
} }
func TestAccLBV1Member_timeout(t *testing.T) {
var member members.Member
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLBV1MemberDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccLBV1Member_timeout,
Check: resource.ComposeTestCheckFunc(
testAccCheckLBV1MemberExists("openstack_lb_member_v1.member_1", &member),
),
},
},
})
}
func testAccCheckLBV1MemberDestroy(s *terraform.State) error { func testAccCheckLBV1MemberDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config) config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME) networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
@ -139,3 +157,35 @@ resource "openstack_lb_member_v1" "member_1" {
pool_id = "${openstack_lb_pool_v1.pool_1.id}" pool_id = "${openstack_lb_pool_v1.pool_1.id}"
} }
` `
const testAccLBV1Member_timeout = `
resource "openstack_networking_network_v2" "network_1" {
name = "network_1"
admin_state_up = "true"
}
resource "openstack_networking_subnet_v2" "subnet_1" {
cidr = "192.168.199.0/24"
ip_version = 4
network_id = "${openstack_networking_network_v2.network_1.id}"
}
resource "openstack_lb_pool_v1" "pool_1" {
name = "pool_1"
protocol = "HTTP"
lb_method = "ROUND_ROBIN"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
}
resource "openstack_lb_member_v1" "member_1" {
address = "192.168.199.10"
port = 80
admin_state_up = true
pool_id = "${openstack_lb_pool_v1.pool_1.id}"
timeouts {
create = "5m"
delete = "5m"
}
}
`

View File

@ -23,6 +23,11 @@ func resourceLBMonitorV1() *schema.Resource {
State: schema.ImportStatePassthrough, State: schema.ImportStatePassthrough,
}, },
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(10 * time.Minute),
},
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"region": &schema.Schema{ "region": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
@ -125,7 +130,7 @@ func resourceLBMonitorV1Create(d *schema.ResourceData, meta interface{}) error {
Pending: []string{"PENDING_CREATE"}, Pending: []string{"PENDING_CREATE"},
Target: []string{"ACTIVE"}, Target: []string{"ACTIVE"},
Refresh: waitForLBMonitorActive(networkingClient, m.ID), Refresh: waitForLBMonitorActive(networkingClient, m.ID),
Timeout: 2 * time.Minute, Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 5 * time.Second, Delay: 5 * time.Second,
MinTimeout: 3 * time.Second, MinTimeout: 3 * time.Second,
} }
@ -216,7 +221,7 @@ func resourceLBMonitorV1Delete(d *schema.ResourceData, meta interface{}) error {
Pending: []string{"ACTIVE", "PENDING_DELETE"}, Pending: []string{"ACTIVE", "PENDING_DELETE"},
Target: []string{"DELETED"}, Target: []string{"DELETED"},
Refresh: waitForLBMonitorDelete(networkingClient, d.Id()), Refresh: waitForLBMonitorDelete(networkingClient, d.Id()),
Timeout: 2 * time.Minute, Timeout: d.Timeout(schema.TimeoutDelete),
Delay: 5 * time.Second, Delay: 5 * time.Second,
MinTimeout: 3 * time.Second, MinTimeout: 3 * time.Second,
} }

View File

@ -34,6 +34,24 @@ func TestAccLBV1Monitor_basic(t *testing.T) {
}) })
} }
func TestAccLBV1Monitor_timeout(t *testing.T) {
var monitor monitors.Monitor
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLBV1MonitorDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccLBV1Monitor_timeout,
Check: resource.ComposeTestCheckFunc(
testAccCheckLBV1MonitorExists("openstack_lb_monitor_v1.monitor_1", &monitor),
),
},
},
})
}
func testAccCheckLBV1MonitorDestroy(s *terraform.State) error { func testAccCheckLBV1MonitorDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config) config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME) networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
@ -89,7 +107,6 @@ func testAccCheckLBV1MonitorExists(n string, monitor *monitors.Monitor) resource
const testAccLBV1Monitor_basic = ` const testAccLBV1Monitor_basic = `
resource "openstack_lb_monitor_v1" "monitor_1" { resource "openstack_lb_monitor_v1" "monitor_1" {
region = "%s"
type = "PING" type = "PING"
delay = 30 delay = 30
timeout = 5 timeout = 5
@ -100,7 +117,6 @@ resource "openstack_lb_monitor_v1" "monitor_1" {
const testAccLBV1Monitor_update = ` const testAccLBV1Monitor_update = `
resource "openstack_lb_monitor_v1" "monitor_1" { resource "openstack_lb_monitor_v1" "monitor_1" {
region = "%s"
type = "PING" type = "PING"
delay = 20 delay = 20
timeout = 5 timeout = 5
@ -108,3 +124,18 @@ resource "openstack_lb_monitor_v1" "monitor_1" {
admin_state_up = "true" admin_state_up = "true"
} }
` `
const testAccLBV1Monitor_timeout = `
resource "openstack_lb_monitor_v1" "monitor_1" {
type = "PING"
delay = 30
timeout = 5
max_retries = 3
admin_state_up = "true"
timeouts {
create = "5m"
delete = "5m"
}
}
`

View File

@ -26,6 +26,11 @@ func resourceLBPoolV1() *schema.Resource {
State: schema.ImportStatePassthrough, State: schema.ImportStatePassthrough,
}, },
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(10 * time.Minute),
},
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"region": &schema.Schema{ "region": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
@ -150,7 +155,7 @@ func resourceLBPoolV1Create(d *schema.ResourceData, meta interface{}) error {
Pending: []string{"PENDING_CREATE"}, Pending: []string{"PENDING_CREATE"},
Target: []string{"ACTIVE"}, Target: []string{"ACTIVE"},
Refresh: waitForLBPoolActive(networkingClient, p.ID), Refresh: waitForLBPoolActive(networkingClient, p.ID),
Timeout: 2 * time.Minute, Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 5 * time.Second, Delay: 5 * time.Second,
MinTimeout: 3 * time.Second, MinTimeout: 3 * time.Second,
} }
@ -331,7 +336,7 @@ func resourceLBPoolV1Delete(d *schema.ResourceData, meta interface{}) error {
Pending: []string{"ACTIVE", "PENDING_DELETE"}, Pending: []string{"ACTIVE", "PENDING_DELETE"},
Target: []string{"DELETED"}, Target: []string{"DELETED"},
Refresh: waitForLBPoolDelete(networkingClient, d.Id()), Refresh: waitForLBPoolDelete(networkingClient, d.Id()),
Timeout: 2 * time.Minute, Timeout: d.Timeout(schema.TimeoutDelete),
Delay: 5 * time.Second, Delay: 5 * time.Second,
MinTimeout: 3 * time.Second, MinTimeout: 3 * time.Second,
} }

View File

@ -85,6 +85,25 @@ func TestAccLBV1Pool_fullstack(t *testing.T) {
}) })
} }
func TestAccLBV1Pool_timeout(t *testing.T) {
var pool pools.Pool
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLBV1PoolDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccLBV1Pool_timeout,
Check: resource.ComposeTestCheckFunc(
testAccCheckLBV1PoolExists("openstack_lb_pool_v1.pool_1", &pool),
resource.TestCheckResourceAttr("openstack_lb_pool_v1.pool_1", "lb_provider", "haproxy"),
),
},
},
})
}
func testAccCheckLBV1PoolDestroy(s *terraform.State) error { func testAccCheckLBV1PoolDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config) config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME) networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
@ -357,3 +376,29 @@ resource "openstack_lb_vip_v1" "vip_1" {
pool_id = "${openstack_lb_pool_v1.pool_1.id}" pool_id = "${openstack_lb_pool_v1.pool_1.id}"
} }
` `
const testAccLBV1Pool_timeout = `
resource "openstack_networking_network_v2" "network_1" {
name = "network_1"
admin_state_up = "true"
}
resource "openstack_networking_subnet_v2" "subnet_1" {
cidr = "192.168.199.0/24"
ip_version = 4
network_id = "${openstack_networking_network_v2.network_1.id}"
}
resource "openstack_lb_pool_v1" "pool_1" {
name = "pool_1"
protocol = "HTTP"
lb_method = "ROUND_ROBIN"
lb_provider = "haproxy"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
timeouts {
create = "5m"
delete = "5m"
}
}
`

View File

@ -22,6 +22,11 @@ func resourceLBVipV1() *schema.Resource {
State: schema.ImportStatePassthrough, State: schema.ImportStatePassthrough,
}, },
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(10 * time.Minute),
},
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"region": &schema.Schema{ "region": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
@ -139,7 +144,7 @@ func resourceLBVipV1Create(d *schema.ResourceData, meta interface{}) error {
Pending: []string{"PENDING_CREATE"}, Pending: []string{"PENDING_CREATE"},
Target: []string{"ACTIVE"}, Target: []string{"ACTIVE"},
Refresh: waitForLBVIPActive(networkingClient, p.ID), Refresh: waitForLBVIPActive(networkingClient, p.ID),
Timeout: 2 * time.Minute, Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 5 * time.Second, Delay: 5 * time.Second,
MinTimeout: 3 * time.Second, MinTimeout: 3 * time.Second,
} }
@ -291,7 +296,7 @@ func resourceLBVipV1Delete(d *schema.ResourceData, meta interface{}) error {
Pending: []string{"ACTIVE", "PENDING_DELETE"}, Pending: []string{"ACTIVE", "PENDING_DELETE"},
Target: []string{"DELETED"}, Target: []string{"DELETED"},
Refresh: waitForLBVIPDelete(networkingClient, d.Id()), Refresh: waitForLBVIPDelete(networkingClient, d.Id()),
Timeout: 2 * time.Minute, Timeout: d.Timeout(schema.TimeoutDelete),
Delay: 5 * time.Second, Delay: 5 * time.Second,
MinTimeout: 3 * time.Second, MinTimeout: 3 * time.Second,
} }

View File

@ -34,6 +34,24 @@ func TestAccLBV1VIP_basic(t *testing.T) {
}) })
} }
func TestAccLBV1VIP_timeout(t *testing.T) {
var vip vips.VirtualIP
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLBV1VIPDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccLBV1VIP_timeout,
Check: resource.ComposeTestCheckFunc(
testAccCheckLBV1VIPExists("openstack_lb_vip_v1.vip_1", &vip),
),
},
},
})
}
func testAccCheckLBV1VIPDestroy(s *terraform.State) error { func testAccCheckLBV1VIPDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config) config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME) networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
@ -152,3 +170,41 @@ resource "openstack_lb_vip_v1" "vip_1" {
} }
} }
` `
const testAccLBV1VIP_timeout = `
resource "openstack_networking_network_v2" "network_1" {
name = "network_1"
admin_state_up = "true"
}
resource "openstack_networking_subnet_v2" "subnet_1" {
cidr = "192.168.199.0/24"
ip_version = 4
network_id = "${openstack_networking_network_v2.network_1.id}"
}
resource "openstack_lb_pool_v1" "pool_1" {
name = "pool_1"
protocol = "HTTP"
lb_method = "ROUND_ROBIN"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
}
resource "openstack_lb_vip_v1" "vip_1" {
name = "vip_1"
protocol = "HTTP"
port = 80
admin_state_up = true
pool_id = "${openstack_lb_pool_v1.pool_1.id}"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
persistence {
type = "SOURCE_IP"
}
timeouts {
create = "5m"
delete = "5m"
}
}
`