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 Compute Network Refactor #1347

Merged
merged 14 commits into from
Apr 2, 2015
Merged
5 changes: 5 additions & 0 deletions builtin/providers/openstack/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@ func testAccPreCheck(t *testing.T) {
if v1 == "" && v2 == "" {
t.Fatal("OS_FLAVOR_ID or OS_FLAVOR_NAME must be set for acceptance tests")
}

v = os.Getenv("OS_NETWORK_ID")
if v == "" {
t.Fatal("OS_NETWORK_ID must be set for acceptance tests")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package openstack

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"

"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/floatingip"
"github.com/rackspace/gophercloud/openstack/compute/v2/servers"
)

func TestAccComputeV2FloatingIP_basic(t *testing.T) {
Expand All @@ -28,6 +30,40 @@ func TestAccComputeV2FloatingIP_basic(t *testing.T) {
})
}

func TestAccComputeV2FloatingIP_attach(t *testing.T) {
var instance servers.Server
var fip floatingip.FloatingIP
var testAccComputeV2FloatingIP_attach = fmt.Sprintf(`
resource "openstack_compute_floatingip_v2" "myip" {
}

resource "openstack_compute_instance_v2" "foo" {
name = "terraform-test"
floating_ip = "${openstack_compute_floatingip_v2.myip.address}"

network {
uuid = "%s"
}
}`,
os.Getenv("OS_NETWORK_ID"))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeV2FloatingIPDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeV2FloatingIP_attach,
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeV2FloatingIPExists(t, "openstack_compute_floatingip_v2.myip", &fip),
testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.foo", &instance),
testAccCheckComputeV2InstanceFloatingIPAttach(&instance, &fip),
),
},
},
})
}

func testAccCheckComputeV2FloatingIPDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
computeClient, err := config.computeV2Client(OS_REGION_NAME)
Expand Down Expand Up @@ -83,9 +119,4 @@ func testAccCheckComputeV2FloatingIPExists(t *testing.T, n string, kp *floatingi

var testAccComputeV2FloatingIP_basic = `
resource "openstack_compute_floatingip_v2" "foo" {
}

resource "openstack_compute_instance_v2" "bar" {
name = "terraform-acc-floating-ip-test"
floating_ip = "${openstack_compute_floatingip_v2.foo.address}"
}`
Loading