Updated compute_instance acceptance tests for floating IPs

This commit is contained in:
Joe Topjian 2015-04-01 02:56:24 +00:00
parent bb81228205
commit 67e33a7ac9
2 changed files with 53 additions and 0 deletions

View File

@ -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_NAME")
if v == "" {
t.Fatal("OS_NETWORK_NAME must be set for acceptance tests")
}
}

View File

@ -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/blockstorage/v1/volumes"
"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/floatingip"
"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/volumeattach"
"github.com/rackspace/gophercloud/openstack/compute/v2/servers"
"github.com/rackspace/gophercloud/pagination"
@ -53,6 +55,40 @@ func TestAccComputeV2Instance_volumeAttach(t *testing.T) {
})
}
func TestAccComputeV2Instance_floatingIPAttach(t *testing.T) {
var instance servers.Server
var fip floatingip.FloatingIP
var testAccComputeV2Instance_floatingIPAttach = 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 {
name = "%s"
}
}`,
os.Getenv("OS_NETWORK_NAME"))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeV2InstanceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeV2Instance_floatingIPAttach,
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeV2FloatingIPExists(t, "openstack_compute_floatingip_v2.myip", &fip),
testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.foo", &instance),
testAccCheckComputeV2InstanceFloatingIPAttach(&instance, &fip),
),
},
},
})
}
func testAccCheckComputeV2InstanceDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
computeClient, err := config.computeV2Client(OS_REGION_NAME)
@ -159,6 +195,18 @@ func testAccCheckComputeV2InstanceVolumeAttachment(
}
}
func testAccCheckComputeV2InstanceFloatingIPAttach(
instance *servers.Server, fip *floatingip.FloatingIP) resource.TestCheckFunc {
return func(s *terraform.State) error {
if fip.InstanceID == instance.ID {
return nil
}
return fmt.Errorf("Floating IP %s was not attached to instance %s", fip.ID, instance.ID)
}
}
var testAccComputeV2Instance_basic = fmt.Sprintf(`
resource "openstack_compute_instance_v2" "foo" {
region = "%s"