From 67e33a7ac97dee558b1209b996d59f9c216386fe Mon Sep 17 00:00:00 2001 From: Joe Topjian Date: Wed, 1 Apr 2015 02:56:24 +0000 Subject: [PATCH] Updated compute_instance acceptance tests for floating IPs --- builtin/providers/openstack/provider_test.go | 5 ++ ...urce_openstack_compute_instance_v2_test.go | 48 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/builtin/providers/openstack/provider_test.go b/builtin/providers/openstack/provider_test.go index 7b3e65dd4..16009d04d 100644 --- a/builtin/providers/openstack/provider_test.go +++ b/builtin/providers/openstack/provider_test.go @@ -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") + } } diff --git a/builtin/providers/openstack/resource_openstack_compute_instance_v2_test.go b/builtin/providers/openstack/resource_openstack_compute_instance_v2_test.go index f4c6c8557..5c528e906 100644 --- a/builtin/providers/openstack/resource_openstack_compute_instance_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_compute_instance_v2_test.go @@ -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"