Skip to content

Commit

Permalink
provider/openstack: Adding Timeouts to Network Resources (#12866)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtopjian authored and mbfrahry committed Mar 28, 2017
1 parent f1e6238 commit b2c7c87
Show file tree
Hide file tree
Showing 16 changed files with 375 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ func resourceNetworkingFloatingIPV2() *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,
Expand Down Expand Up @@ -101,7 +106,7 @@ func resourceNetworkFloatingIPV2Create(d *schema.ResourceData, meta interface{})
stateConf := &resource.StateChangeConf{
Target: []string{"ACTIVE"},
Refresh: waitForFloatingIPActive(networkingClient, floatingIP.ID),
Timeout: 2 * time.Minute,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 5 * time.Second,
MinTimeout: 3 * time.Second,
}
Expand Down Expand Up @@ -175,7 +180,7 @@ func resourceNetworkFloatingIPV2Delete(d *schema.ResourceData, meta interface{})
Pending: []string{"ACTIVE"},
Target: []string{"DELETED"},
Refresh: waitForFloatingIPDelete(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 @@ -69,6 +69,24 @@ func TestAccNetworkingV2FloatingIP_fixedip_bind(t *testing.T) {
})
}

func TestAccNetworkingV2FloatingIP_timeout(t *testing.T) {
var fip floatingips.FloatingIP

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNetworkingV2FloatingIPDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccNetworkingV2FloatingIP_timeout,
Check: resource.ComposeTestCheckFunc(
testAccCheckNetworkingV2FloatingIPExists("openstack_networking_floatingip_v2.fip_1", &fip),
),
},
},
})
}

func testAccCheckNetworkingV2FloatingIPDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
networkClient, err := config.networkingV2Client(OS_REGION_NAME)
Expand Down Expand Up @@ -218,3 +236,12 @@ resource "openstack_networking_floatingip_v2" "fip_1" {
fixed_ip = "${openstack_networking_port_v2.port_1.fixed_ip.1.ip_address}"
}
`, OS_EXTGW_ID, OS_POOL_NAME)

const testAccNetworkingV2FloatingIP_timeout = `
resource "openstack_networking_floatingip_v2" "fip_1" {
timeouts {
create = "5m"
delete = "5m"
}
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func resourceNetworkingNetworkV2() *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,
Expand Down Expand Up @@ -108,7 +113,7 @@ func resourceNetworkingNetworkV2Create(d *schema.ResourceData, meta interface{})
Pending: []string{"BUILD"},
Target: []string{"ACTIVE"},
Refresh: waitForNetworkActive(networkingClient, n.ID),
Timeout: 2 * time.Minute,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 5 * time.Second,
MinTimeout: 3 * time.Second,
}
Expand Down Expand Up @@ -196,7 +201,7 @@ func resourceNetworkingNetworkV2Delete(d *schema.ResourceData, meta interface{})
Pending: []string{"ACTIVE"},
Target: []string{"DELETED"},
Refresh: waitForNetworkDelete(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 @@ -90,6 +90,24 @@ func TestAccNetworkingV2Network_fullstack(t *testing.T) {
})
}

func TestAccNetworkingV2Network_timeout(t *testing.T) {
var network networks.Network

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNetworkingV2NetworkDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccNetworkingV2Network_timeout,
Check: resource.ComposeTestCheckFunc(
testAccCheckNetworkingV2NetworkExists("openstack_networking_network_v2.network_1", &network),
),
},
},
})
}

func testAccCheckNetworkingV2NetworkDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
Expand Down Expand Up @@ -225,3 +243,15 @@ resource "openstack_compute_instance_v2" "instance_1" {
}
}
`

const testAccNetworkingV2Network_timeout = `
resource "openstack_networking_network_v2" "network_1" {
name = "network_1"
admin_state_up = "true"
timeouts {
create = "5m"
delete = "5m"
}
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ func resourceNetworkingPortV2() *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,
Expand Down Expand Up @@ -162,7 +167,7 @@ func resourceNetworkingPortV2Create(d *schema.ResourceData, meta interface{}) er
stateConf := &resource.StateChangeConf{
Target: []string{"ACTIVE"},
Refresh: waitForNetworkPortActive(networkingClient, p.ID),
Timeout: 2 * time.Minute,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 5 * time.Second,
MinTimeout: 3 * time.Second,
}
Expand Down Expand Up @@ -280,7 +285,7 @@ func resourceNetworkingPortV2Delete(d *schema.ResourceData, meta interface{}) er
Pending: []string{"ACTIVE"},
Target: []string{"DELETED"},
Refresh: waitForNetworkPortDelete(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 @@ -102,6 +102,28 @@ func TestAccNetworkingV2Port_multipleFixedIPs(t *testing.T) {
})
}

func TestAccNetworkingV2Port_timeout(t *testing.T) {
var network networks.Network
var port ports.Port
var subnet subnets.Subnet

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNetworkingV2PortDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccNetworkingV2Port_timeout,
Check: resource.ComposeTestCheckFunc(
testAccCheckNetworkingV2SubnetExists("openstack_networking_subnet_v2.subnet_1", &subnet),
testAccCheckNetworkingV2NetworkExists("openstack_networking_network_v2.network_1", &network),
testAccCheckNetworkingV2PortExists("openstack_networking_port_v2.port_1", &port),
),
},
},
})
}

func testAccCheckNetworkingV2PortDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
Expand Down Expand Up @@ -304,3 +326,33 @@ resource "openstack_networking_port_v2" "port_1" {
}
}
`

const testAccNetworkingV2Port_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_networking_port_v2" "port_1" {
name = "port_1"
admin_state_up = "true"
network_id = "${openstack_networking_network_v2.network_1.id}"
fixed_ip {
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
ip_address = "192.168.199.23"
}
timeouts {
create = "5m"
delete = "5m"
}
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func resourceNetworkingRouterInterfaceV2() *schema.Resource {
Read: resourceNetworkingRouterInterfaceV2Read,
Delete: resourceNetworkingRouterInterfaceV2Delete,

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 @@ -70,7 +75,7 @@ func resourceNetworkingRouterInterfaceV2Create(d *schema.ResourceData, meta inte
Pending: []string{"BUILD", "PENDING_CREATE", "PENDING_UPDATE"},
Target: []string{"ACTIVE"},
Refresh: waitForRouterInterfaceActive(networkingClient, n.PortID),
Timeout: 2 * time.Minute,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 5 * time.Second,
MinTimeout: 3 * time.Second,
}
Expand Down Expand Up @@ -115,7 +120,7 @@ func resourceNetworkingRouterInterfaceV2Delete(d *schema.ResourceData, meta inte
Pending: []string{"ACTIVE"},
Target: []string{"DELETED"},
Refresh: waitForRouterInterfaceDelete(networkingClient, d),
Timeout: 5 * 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 @@ -61,6 +61,29 @@ func TestAccNetworkingV2RouterInterface_basic_port(t *testing.T) {
})
}

func TestAccNetworkingV2RouterInterface_timeout(t *testing.T) {
var network networks.Network
var router routers.Router
var subnet subnets.Subnet

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNetworkingV2RouterInterfaceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccNetworkingV2RouterInterface_timeout,
Check: resource.ComposeTestCheckFunc(
testAccCheckNetworkingV2NetworkExists("openstack_networking_network_v2.network_1", &network),
testAccCheckNetworkingV2SubnetExists("openstack_networking_subnet_v2.subnet_1", &subnet),
testAccCheckNetworkingV2RouterExists("openstack_networking_router_v2.router_1", &router),
testAccCheckNetworkingV2RouterInterfaceExists("openstack_networking_router_interface_v2.int_1"),
),
},
},
})
}

func testAccCheckNetworkingV2RouterInterfaceDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
Expand Down Expand Up @@ -168,3 +191,31 @@ resource "openstack_networking_port_v2" "port_1" {
}
}
`

const testAccNetworkingV2RouterInterface_timeout = `
resource "openstack_networking_router_v2" "router_1" {
name = "router_1"
admin_state_up = "true"
}
resource "openstack_networking_router_interface_v2" "int_1" {
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
router_id = "${openstack_networking_router_v2.router_1.id}"
timeouts {
create = "5m"
delete = "5m"
}
}
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}"
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func resourceNetworkingRouterV2() *schema.Resource {
Update: resourceNetworkingRouterV2Update,
Delete: resourceNetworkingRouterV2Delete,

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 @@ -108,7 +113,7 @@ func resourceNetworkingRouterV2Create(d *schema.ResourceData, meta interface{})
Pending: []string{"BUILD", "PENDING_CREATE", "PENDING_UPDATE"},
Target: []string{"ACTIVE"},
Refresh: waitForRouterActive(networkingClient, n.ID),
Timeout: 10 * time.Minute,
Timeout: d.Timeout(schema.TimeoutCreate),
Delay: 5 * time.Second,
MinTimeout: 3 * time.Second,
}
Expand Down Expand Up @@ -198,7 +203,7 @@ func resourceNetworkingRouterV2Delete(d *schema.ResourceData, meta interface{})
Pending: []string{"ACTIVE"},
Target: []string{"DELETED"},
Refresh: waitForRouterDelete(networkingClient, d.Id()),
Timeout: 10 * 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 @@ -60,6 +60,24 @@ func TestAccNetworkingV2Router_update_external_gw(t *testing.T) {
})
}

func TestAccNetworkingV2Router_timeout(t *testing.T) {
var router routers.Router

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNetworkingV2RouterDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccNetworkingV2Router_timeout,
Check: resource.ComposeTestCheckFunc(
testAccCheckNetworkingV2RouterExists("openstack_networking_router_v2.router_1", &router),
),
},
},
})
}

func testAccCheckNetworkingV2RouterDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
Expand Down Expand Up @@ -145,3 +163,16 @@ resource "openstack_networking_router_v2" "router_1" {
external_gateway = "%s"
}
`, OS_EXTGW_ID)

const testAccNetworkingV2Router_timeout = `
resource "openstack_networking_router_v2" "router_1" {
name = "router_1"
admin_state_up = "true"
distributed = "false"
timeouts {
create = "5m"
delete = "5m"
}
}
`
Loading

0 comments on commit b2c7c87

Please sign in to comment.