PageRenderTime 132ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/portsbinding/portsbinding_test.go

https://gitlab.com/unofficial-mirrors/openshift-origin
Go | 57 lines | 40 code | 11 blank | 6 comment | 13 complexity | efbe7a3e07b8187e2034ac33668da61e 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/ports"
  9. )
  10. func TestPortsbindingCRUD(t *testing.T) {
  11. client, err := clients.NewNetworkV2Client()
  12. if err != nil {
  13. t.Fatalf("Unable to create a network client: %v", err)
  14. }
  15. // Create Network
  16. network, err := networking.CreateNetwork(t, client)
  17. if err != nil {
  18. t.Fatalf("Unable to create network: %v", err)
  19. }
  20. defer networking.DeleteNetwork(t, client, network.ID)
  21. // Create Subnet
  22. subnet, err := networking.CreateSubnet(t, client, network.ID)
  23. if err != nil {
  24. t.Fatalf("Unable to create subnet: %v", err)
  25. }
  26. defer networking.DeleteSubnet(t, client, subnet.ID)
  27. // Define a host
  28. hostID := "localhost"
  29. // Create port
  30. port, err := CreatePortsbinding(t, client, network.ID, subnet.ID, hostID)
  31. if err != nil {
  32. t.Fatalf("Unable to create port: %v", err)
  33. }
  34. defer networking.DeletePort(t, client, port.ID)
  35. tools.PrintResource(t, port)
  36. // Update port
  37. newPortName := tools.RandomString("TESTACC-", 8)
  38. updateOpts := ports.UpdateOpts{
  39. Name: newPortName,
  40. }
  41. newPort, err := ports.Update(client, port.ID, updateOpts).Extract()
  42. if err != nil {
  43. t.Fatalf("Could not update port: %v", err)
  44. }
  45. tools.PrintResource(t, newPort)
  46. }