Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Mar 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
}
}`
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
}
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
}
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
}
}
`
9 changes: 7 additions & 2 deletions builtin/providers/openstack/resource_openstack_lb_pool_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
Loading