-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provider/openstack: Additions to the OpenStack Port resource
This commit adds further work to the OpenStack port resource: * Makes relevant fields computed * Adds state change functions * Adds acceptance tests * Adds Documentation
- Loading branch information
Showing
6 changed files
with
375 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
builtin/providers/openstack/resource_openstack_networking_port_v2_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package openstack | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
|
||
"github.com/rackspace/gophercloud/openstack/networking/v2/networks" | ||
"github.com/rackspace/gophercloud/openstack/networking/v2/ports" | ||
) | ||
|
||
func TestAccNetworkingV2Port_basic(t *testing.T) { | ||
region := os.Getenv(OS_REGION_NAME) | ||
|
||
var network networks.Network | ||
var port ports.Port | ||
|
||
var testAccNetworkingV2Port_basic = fmt.Sprintf(` | ||
resource "openstack_networking_network_v2" "foo" { | ||
region = "%s" | ||
name = "network_1" | ||
admin_state_up = "true" | ||
} | ||
resource "openstack_networking_port_v2" "foo" { | ||
region = "%s" | ||
name = "port_1" | ||
network_id = "${openstack_networking_network_v2.foo.id}" | ||
admin_state_up = "true" | ||
}`, region, region) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckNetworkingV2PortDestroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccNetworkingV2Port_basic, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckNetworkingV2NetworkExists(t, "openstack_networking_network_v2.foo", &network), | ||
testAccCheckNetworkingV2PortExists(t, "openstack_networking_port_v2.foo", &port), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckNetworkingV2PortDestroy(s *terraform.State) error { | ||
config := testAccProvider.Meta().(*Config) | ||
networkingClient, err := config.networkingV2Client(OS_REGION_NAME) | ||
if err != nil { | ||
return fmt.Errorf("(testAccCheckNetworkingV2PortDestroy) Error creating OpenStack networking client: %s", err) | ||
} | ||
|
||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "openstack_networking_port_v2" { | ||
continue | ||
} | ||
|
||
_, err := ports.Get(networkingClient, rs.Primary.ID).Extract() | ||
if err == nil { | ||
return fmt.Errorf("Port still exists") | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func testAccCheckNetworkingV2PortExists(t *testing.T, n string, port *ports.Port) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("Not found: %s", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("No ID is set") | ||
} | ||
|
||
config := testAccProvider.Meta().(*Config) | ||
networkingClient, err := config.networkingV2Client(OS_REGION_NAME) | ||
if err != nil { | ||
return fmt.Errorf("(testAccCheckNetworkingV2PortExists) Error creating OpenStack networking client: %s", err) | ||
} | ||
|
||
found, err := ports.Get(networkingClient, rs.Primary.ID).Extract() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if found.ID != rs.Primary.ID { | ||
return fmt.Errorf("Port not found") | ||
} | ||
|
||
*port = *found | ||
|
||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.