Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 1b17d0a

Browse files
author
Jamie Hannaford
committed
add list operation and squash structs
1 parent c6266be commit 1b17d0a

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

acceptance/openstack/networking/v2/extensions/portsbinding/portsbinding_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/rackspace/gophercloud/openstack/networking/v2/networks"
1111
"github.com/rackspace/gophercloud/openstack/networking/v2/ports"
1212
"github.com/rackspace/gophercloud/openstack/networking/v2/subnets"
13+
"github.com/rackspace/gophercloud/pagination"
1314
th "github.com/rackspace/gophercloud/testhelper"
1415
)
1516

@@ -53,11 +54,40 @@ func TestPortBinding(t *testing.T) {
5354
th.AssertNoErr(t, err)
5455
th.AssertEquals(t, p.HostID, newHostID)
5556

57+
// List ports
58+
t.Logf("Listing all ports")
59+
listPorts(t)
60+
5661
// Delete port
5762
res := ports.Delete(base.Client, portID)
5863
th.AssertNoErr(t, res.Err)
5964
}
6065

66+
func listPorts(t *testing.T) {
67+
count := 0
68+
pager := ports.List(base.Client, ports.ListOpts{})
69+
err := pager.EachPage(func(page pagination.Page) (bool, error) {
70+
count++
71+
t.Logf("--- Page ---")
72+
73+
portList, err := portsbinding.ExtractPorts(page)
74+
th.AssertNoErr(t, err)
75+
76+
for _, p := range portList {
77+
t.Logf("Port: ID [%s] Name [%s] HostID [%s] VNICType [%s] VIFType [%s]",
78+
p.ID, p.Name, p.HostID, p.VNICType, p.VIFType)
79+
}
80+
81+
return true, nil
82+
})
83+
84+
th.CheckNoErr(t, err)
85+
86+
if count == 0 {
87+
t.Logf("No pages were iterated over when listing ports")
88+
}
89+
}
90+
6191
func createPort(t *testing.T, networkID, subnetID, hostID string) string {
6292
enable := false
6393
opts := portsbinding.CreateOpts{

openstack/networking/v2/extensions/portsbinding/requests_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package portsbinding
22

33
import (
4-
"fmt"
54
"testing"
65

76
fake "github.com/rackspace/gophercloud/openstack/networking/v2/common"
@@ -44,11 +43,10 @@ func TestList(t *testing.T) {
4443
DeviceID: "9ae135f4-b6e0-4dad-9e91-3c223e385824",
4544
},
4645
VNICType: "normal",
46+
HostID: "devstack",
4747
},
4848
}
4949

50-
fmt.Printf("%#v", actual)
51-
5250
th.CheckDeepEquals(t, expected, actual)
5351

5452
return true, nil
@@ -81,8 +79,11 @@ func TestGet(t *testing.T) {
8179
th.AssertEquals(t, n.ID, "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2")
8280
th.AssertDeepEquals(t, n.SecurityGroups, []string{})
8381
th.AssertEquals(t, n.DeviceID, "5e3898d7-11be-483e-9732-b2f5eccd2b2e")
84-
th.AssertEquals(t, n.HostID, "HOST1")
82+
83+
th.AssertEquals(t, n.HostID, "devstack")
8584
th.AssertEquals(t, n.VNICType, "normal")
85+
th.AssertEquals(t, n.VIFType, "ovs")
86+
th.AssertDeepEquals(t, n.VIFDetails, map[string]interface{}{"port_filter": true, "ovs_hybrid_plug": true})
8687
}
8788

8889
func TestCreate(t *testing.T) {

openstack/networking/v2/extensions/portsbinding/results.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ type IP struct {
5151
// Port represents a Neutron port. See package documentation for a top-level
5252
// description of what this is.
5353
type Port struct {
54-
ports.Port
54+
ports.Port `mapstructure:",squash"`
5555
// The ID of the host where the port is allocated
5656
HostID string `mapstructure:"binding:host_id" json:"binding:host_id"`
5757
// A dictionary that enables the application to pass information about
5858
// functions that the Networking API provides.
59-
VIFDetails map[string]string `mapstructure:"binding:vif_details" json:"binding:vif_details"`
59+
VIFDetails map[string]interface{} `mapstructure:"binding:vif_details" json:"binding:vif_details"`
6060
// The VIF type for the port.
6161
VIFType string `mapstructure:"binding:vif_type" json:"binding:vif_type"`
6262
// The virtual network interface card (vNIC) type that is bound to the

0 commit comments

Comments
 (0)