github.com/leeclow-ops/gophercloud@v1.2.1/acceptance/openstack/networking/v2/extensions/portsbinding/portsbinding_test.go (about) 1 //go:build acceptance || networking 2 // +build acceptance networking 3 4 package portsbinding 5 6 import ( 7 "testing" 8 9 "github.com/leeclow-ops/gophercloud/acceptance/clients" 10 networking "github.com/leeclow-ops/gophercloud/acceptance/openstack/networking/v2" 11 "github.com/leeclow-ops/gophercloud/acceptance/tools" 12 "github.com/leeclow-ops/gophercloud/openstack/networking/v2/extensions/portsbinding" 13 "github.com/leeclow-ops/gophercloud/openstack/networking/v2/ports" 14 th "github.com/leeclow-ops/gophercloud/testhelper" 15 ) 16 17 func TestPortsbindingCRUD(t *testing.T) { 18 clients.RequireAdmin(t) 19 20 client, err := clients.NewNetworkV2Client() 21 th.AssertNoErr(t, err) 22 23 // Create Network 24 network, err := networking.CreateNetwork(t, client) 25 th.AssertNoErr(t, err) 26 defer networking.DeleteNetwork(t, client, network.ID) 27 28 // Create Subnet 29 subnet, err := networking.CreateSubnet(t, client, network.ID) 30 th.AssertNoErr(t, err) 31 defer networking.DeleteSubnet(t, client, subnet.ID) 32 33 // Define a host 34 hostID := "localhost" 35 profile := map[string]interface{}{"foo": "bar"} 36 37 // Create port 38 port, err := CreatePortsbinding(t, client, network.ID, subnet.ID, hostID, profile) 39 th.AssertNoErr(t, err) 40 defer networking.DeletePort(t, client, port.ID) 41 42 tools.PrintResource(t, port) 43 th.AssertEquals(t, port.HostID, hostID) 44 th.AssertEquals(t, port.VNICType, "normal") 45 th.AssertDeepEquals(t, port.Profile, profile) 46 47 // Update port 48 newPortName := "" 49 newPortDescription := "" 50 newHostID := "127.0.0.1" 51 newProfile := map[string]interface{}{} 52 updateOpts := ports.UpdateOpts{ 53 Name: &newPortName, 54 Description: &newPortDescription, 55 } 56 57 var finalUpdateOpts ports.UpdateOptsBuilder 58 59 finalUpdateOpts = portsbinding.UpdateOptsExt{ 60 UpdateOptsBuilder: updateOpts, 61 HostID: &newHostID, 62 VNICType: "baremetal", 63 Profile: newProfile, 64 } 65 66 var newPort PortWithBindingExt 67 68 _, err = ports.Update(client, port.ID, finalUpdateOpts).Extract() 69 th.AssertNoErr(t, err) 70 71 // Read the updated port 72 err = ports.Get(client, port.ID).ExtractInto(&newPort) 73 th.AssertNoErr(t, err) 74 75 tools.PrintResource(t, newPort) 76 th.AssertEquals(t, newPort.Description, newPortName) 77 th.AssertEquals(t, newPort.Description, newPortDescription) 78 th.AssertEquals(t, newPort.HostID, newHostID) 79 th.AssertEquals(t, newPort.VNICType, "baremetal") 80 th.AssertDeepEquals(t, newPort.Profile, newProfile) 81 }