PageRenderTime 42ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2/volumeattach_test.go

https://gitlab.com/unofficial-mirrors/openshift-origin
Go | 78 lines | 60 code | 17 blank | 1 comment | 20 complexity | 3d6a520f963635e57f0a5dcb116b85c6 MD5 | raw file
  1. // +build acceptance compute volumeattach
  2. package v2
  3. import (
  4. "testing"
  5. "github.com/gophercloud/gophercloud"
  6. "github.com/gophercloud/gophercloud/acceptance/clients"
  7. "github.com/gophercloud/gophercloud/acceptance/tools"
  8. "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes"
  9. )
  10. func TestVolumeAttachAttachment(t *testing.T) {
  11. if testing.Short() {
  12. t.Skip("Skipping test that requires server creation in short mode.")
  13. }
  14. client, err := clients.NewComputeV2Client()
  15. if err != nil {
  16. t.Fatalf("Unable to create a compute client: %v", err)
  17. }
  18. blockClient, err := clients.NewBlockStorageV1Client()
  19. if err != nil {
  20. t.Fatalf("Unable to create a blockstorage client: %v", err)
  21. }
  22. server, err := CreateServer(t, client)
  23. if err != nil {
  24. t.Fatalf("Unable to create server: %v", err)
  25. }
  26. defer DeleteServer(t, client, server)
  27. volume, err := createVolume(t, blockClient)
  28. if err != nil {
  29. t.Fatalf("Unable to create volume: %v", err)
  30. }
  31. if err = volumes.WaitForStatus(blockClient, volume.ID, "available", 60); err != nil {
  32. t.Fatalf("Unable to wait for volume: %v", err)
  33. }
  34. defer deleteVolume(t, blockClient, volume)
  35. volumeAttachment, err := CreateVolumeAttachment(t, client, blockClient, server, volume)
  36. if err != nil {
  37. t.Fatalf("Unable to attach volume: %v", err)
  38. }
  39. defer DeleteVolumeAttachment(t, client, blockClient, server, volumeAttachment)
  40. tools.PrintResource(t, volumeAttachment)
  41. }
  42. func createVolume(t *testing.T, blockClient *gophercloud.ServiceClient) (*volumes.Volume, error) {
  43. volumeName := tools.RandomString("ACPTTEST", 16)
  44. createOpts := volumes.CreateOpts{
  45. Size: 1,
  46. Name: volumeName,
  47. }
  48. volume, err := volumes.Create(blockClient, createOpts).Extract()
  49. if err != nil {
  50. return volume, err
  51. }
  52. t.Logf("Created volume: %s", volume.ID)
  53. return volume, nil
  54. }
  55. func deleteVolume(t *testing.T, blockClient *gophercloud.ServiceClient, volume *volumes.Volume) {
  56. err := volumes.Delete(blockClient, volume.ID).ExtractErr()
  57. if err != nil {
  58. t.Fatalf("Unable to delete volume: %v", err)
  59. }
  60. t.Logf("Deleted volume: %s", volume.ID)
  61. }