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

/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/layer3/routers_test.go

https://gitlab.com/unofficial-mirrors/openshift-origin
Go | 119 lines | 93 code | 25 blank | 1 comment | 32 complexity | d786a78741d9b28776b637aa55720e12 MD5 | raw file
  1. // +build acceptance networking layer3 router
  2. package layer3
  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/layer3/routers"
  9. "github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
  10. )
  11. func TestLayer3RouterList(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. listOpts := routers.ListOpts{}
  17. allPages, err := routers.List(client, listOpts).AllPages()
  18. if err != nil {
  19. t.Fatalf("Unable to list routers: %v", err)
  20. }
  21. allRouters, err := routers.ExtractRouters(allPages)
  22. if err != nil {
  23. t.Fatalf("Unable to extract routers: %v", err)
  24. }
  25. for _, router := range allRouters {
  26. tools.PrintResource(t, router)
  27. }
  28. }
  29. func TestLayer3ExternalRouterCreateDelete(t *testing.T) {
  30. client, err := clients.NewNetworkV2Client()
  31. if err != nil {
  32. t.Fatalf("Unable to create a network client: %v", err)
  33. }
  34. router, err := CreateExternalRouter(t, client)
  35. if err != nil {
  36. t.Fatalf("Unable to create router: %v", err)
  37. }
  38. defer DeleteRouter(t, client, router.ID)
  39. tools.PrintResource(t, router)
  40. newName := tools.RandomString("TESTACC-", 8)
  41. updateOpts := routers.UpdateOpts{
  42. Name: newName,
  43. }
  44. _, err = routers.Update(client, router.ID, updateOpts).Extract()
  45. if err != nil {
  46. t.Fatalf("Unable to update router: %v", err)
  47. }
  48. newRouter, err := routers.Get(client, router.ID).Extract()
  49. if err != nil {
  50. t.Fatalf("Unable to get router: %v", err)
  51. }
  52. tools.PrintResource(t, newRouter)
  53. }
  54. func TestLayer3RouterInterface(t *testing.T) {
  55. client, err := clients.NewNetworkV2Client()
  56. if err != nil {
  57. t.Fatalf("Unable to create a compute client: %v", err)
  58. }
  59. choices, err := clients.AcceptanceTestChoicesFromEnv()
  60. if err != nil {
  61. t.Fatalf("Unable to get choices: %v", err)
  62. }
  63. netid, err := networks.IDFromName(client, choices.NetworkName)
  64. if err != nil {
  65. t.Fatalf("Unable to find network id: %v", err)
  66. }
  67. subnet, err := networking.CreateSubnet(t, client, netid)
  68. if err != nil {
  69. t.Fatalf("Unable to create subnet: %v", err)
  70. }
  71. defer networking.DeleteSubnet(t, client, subnet.ID)
  72. tools.PrintResource(t, subnet)
  73. router, err := CreateExternalRouter(t, client)
  74. if err != nil {
  75. t.Fatalf("Unable to create router: %v", err)
  76. }
  77. defer DeleteRouter(t, client, router.ID)
  78. aiOpts := routers.AddInterfaceOpts{
  79. SubnetID: subnet.ID,
  80. }
  81. iface, err := routers.AddInterface(client, router.ID, aiOpts).Extract()
  82. if err != nil {
  83. t.Fatalf("Failed to add interface to router: %v", err)
  84. }
  85. tools.PrintResource(t, router)
  86. tools.PrintResource(t, iface)
  87. riOpts := routers.RemoveInterfaceOpts{
  88. SubnetID: subnet.ID,
  89. }
  90. _, err = routers.RemoveInterface(client, router.ID, riOpts).Extract()
  91. if err != nil {
  92. t.Fatalf("Failed to remove interface from router: %v", err)
  93. }
  94. }