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: Fix Ordering of Port Allowed Address Pairs #10250

Merged
merged 1 commit into from
Dec 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package openstack

import (
"bytes"
"fmt"
"log"
"time"

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

Expand Down Expand Up @@ -97,10 +99,11 @@ func resourceNetworkingPortV2() *schema.Resource {
},
},
"allowed_address_pairs": &schema.Schema{
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
ForceNew: false,
Computed: true,
Set: allowedAddressPairsHash,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip_address": &schema.Schema{
Expand Down Expand Up @@ -318,7 +321,7 @@ func resourcePortFixedIpsV2(d *schema.ResourceData) interface{} {

func resourceAllowedAddressPairsV2(d *schema.ResourceData) []ports.AddressPair {
// ports.AddressPair
rawPairs := d.Get("allowed_address_pairs").([]interface{})
rawPairs := d.Get("allowed_address_pairs").(*schema.Set).List()

if len(rawPairs) == 0 {
return nil
Expand All @@ -345,6 +348,14 @@ func resourcePortAdminStateUpV2(d *schema.ResourceData) *bool {
return &value
}

func allowedAddressPairsHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
buf.WriteString(fmt.Sprintf("%s", m["ip_address"].(string)))

return hashcode.String(buf.String())
}

func waitForNetworkPortActive(networkingClient *gophercloud.ServiceClient, portId string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
p, err := ports.Get(networkingClient, portId).Extract()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestAccNetworkingV2Port_noip(t *testing.T) {
func TestAccNetworkingV2Port_allowedAddressPairs(t *testing.T) {
var network networks.Network
var subnet subnets.Subnet
var vrrp_port, instance_port ports.Port
var vrrp_port_1, vrrp_port_2, instance_port ports.Port

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -71,7 +71,8 @@ func TestAccNetworkingV2Port_allowedAddressPairs(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckNetworkingV2SubnetExists(t, "openstack_networking_subnet_v2.vrrp_subnet", &subnet),
testAccCheckNetworkingV2NetworkExists(t, "openstack_networking_network_v2.vrrp_network", &network),
testAccCheckNetworkingV2PortExists(t, "openstack_networking_port_v2.vrrp_port", &vrrp_port),
testAccCheckNetworkingV2PortExists(t, "openstack_networking_port_v2.vrrp_port_1", &vrrp_port_1),
testAccCheckNetworkingV2PortExists(t, "openstack_networking_port_v2.vrrp_port_2", &vrrp_port_2),
testAccCheckNetworkingV2PortExists(t, "openstack_networking_port_v2.instance_port", &instance_port),
),
},
Expand Down Expand Up @@ -202,8 +203,18 @@ var testAccNetworkingV2Port_allowedAddressPairs = fmt.Sprintf(`
subnet_id = "${openstack_networking_subnet_v2.vrrp_subnet.id}"
}

resource "openstack_networking_port_v2" "vrrp_port" {
name = "vrrp_port"
resource "openstack_networking_port_v2" "vrrp_port_1" {
name = "vrrp_port_1"
network_id = "${openstack_networking_network_v2.vrrp_network.id}"
admin_state_up = "true"
fixed_ip {
subnet_id = "${openstack_networking_subnet_v2.vrrp_subnet.id}"
ip_address = "10.0.0.202"
}
}

resource "openstack_networking_port_v2" "vrrp_port_2" {
name = "vrrp_port_2"
network_id = "${openstack_networking_network_v2.vrrp_network.id}"
admin_state_up = "true"
fixed_ip {
Expand All @@ -218,7 +229,12 @@ var testAccNetworkingV2Port_allowedAddressPairs = fmt.Sprintf(`
admin_state_up = "true"

allowed_address_pairs {
ip_address = "${openstack_networking_port_v2.vrrp_port.fixed_ip.0.ip_address}"
mac_address = "${openstack_networking_port_v2.vrrp_port.mac_address}"
ip_address = "${openstack_networking_port_v2.vrrp_port_1.fixed_ip.0.ip_address}"
mac_address = "${openstack_networking_port_v2.vrrp_port_1.mac_address}"
}

allowed_address_pairs {
ip_address = "${openstack_networking_port_v2.vrrp_port_2.fixed_ip.0.ip_address}"
mac_address = "${openstack_networking_port_v2.vrrp_port_2.mac_address}"
}
}`)