/cmd/cluster-capacity/go/src/github.com/kubernetes-incubator/cluster-capacity/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/portsbinding/portsbinding_test.go

https://bitbucket.org/enterstudiosbiz/origin · Go · 58 lines · 41 code · 11 blank · 6 comment · 13 complexity · 699395681242d0eb07c1db58873645ba MD5 · raw file

  1. // +build acceptance networking
  2. package portsbinding
  3. import (
  4. "testing"
  5. "github.com/gophercloud/gophercloud/acceptance/clients"
  6. networking "github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2"
  7. "github.com/gophercloud/gophercloud/acceptance/tools"
  8. "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsbinding"
  9. "github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
  10. )
  11. func TestPortsbindingCRUD(t *testing.T) {
  12. client, err := clients.NewNetworkV2Client()
  13. if err != nil {
  14. t.Fatalf("Unable to create a network client: %v", err)
  15. }
  16. // Create Network
  17. network, err := networking.CreateNetwork(t, client)
  18. if err != nil {
  19. t.Fatalf("Unable to create network: %v", err)
  20. }
  21. defer networking.DeleteNetwork(t, client, network.ID)
  22. // Create Subnet
  23. subnet, err := networking.CreateSubnet(t, client, network.ID)
  24. if err != nil {
  25. t.Fatalf("Unable to create subnet: %v", err)
  26. }
  27. defer networking.DeleteSubnet(t, client, subnet.ID)
  28. // Define a host
  29. hostID := "localhost"
  30. // Create port
  31. port, err := CreatePortsbinding(t, client, network.ID, subnet.ID, hostID)
  32. if err != nil {
  33. t.Fatalf("Unable to create port: %v", err)
  34. }
  35. defer networking.DeletePort(t, client, port.ID)
  36. tools.PrintResource(t, port)
  37. // Update port
  38. newPortName := tools.RandomString("TESTACC-", 8)
  39. updateOpts := ports.UpdateOpts{
  40. Name: newPortName,
  41. }
  42. newPort, err := portsbinding.Update(client, port.ID, updateOpts).Extract()
  43. if err != nil {
  44. t.Fatalf("Could not update port: %v", err)
  45. }
  46. tools.PrintResource(t, newPort)
  47. }