feisky | cf0c7fe | 2015-11-05 22:06:17 +0800 | [diff] [blame] | 1 | // +build acceptance blockstorage |
| 2 | |
| 3 | package extensions |
| 4 | |
| 5 | import ( |
feisky | cf0c7fe | 2015-11-05 22:06:17 +0800 | [diff] [blame] | 6 | "testing" |
| 7 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud/acceptance/clients" |
jrperritt | 9b7b9e6 | 2016-07-11 22:30:50 -0500 | [diff] [blame] | 9 | "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes" |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 10 | |
| 11 | blockstorage "github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2" |
| 12 | compute "github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2" |
feisky | cf0c7fe | 2015-11-05 22:06:17 +0800 | [diff] [blame] | 13 | ) |
| 14 | |
Joe Topjian | 48f36ae | 2017-02-20 14:36:44 -0700 | [diff] [blame] | 15 | func TestVolumeActionsUploadImageDestroy(t *testing.T) { |
| 16 | blockClient, err := clients.NewBlockStorageV2Client() |
| 17 | if err != nil { |
| 18 | t.Fatalf("Unable to create a blockstorage client: %v", err) |
| 19 | } |
| 20 | computeClient, err := clients.NewComputeV2Client() |
| 21 | if err != nil { |
| 22 | t.Fatalf("Unable to create a compute client: %v", err) |
| 23 | } |
| 24 | |
| 25 | volume, err := blockstorage.CreateVolume(t, blockClient) |
| 26 | if err != nil { |
| 27 | t.Fatalf("Unable to create volume: %v", err) |
| 28 | } |
| 29 | defer blockstorage.DeleteVolume(t, blockClient, volume) |
| 30 | |
| 31 | imageName, err := CreateUploadImage(t, blockClient, volume) |
| 32 | if err != nil { |
| 33 | t.Fatalf("Unable to upload volume-backed image: %v", err) |
| 34 | } |
| 35 | |
| 36 | err = DeleteUploadedImage(t, computeClient, imageName) |
| 37 | if err != nil { |
| 38 | t.Fatalf("Unable to delete volume-backed image: %v", err) |
| 39 | } |
| 40 | } |
| 41 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 42 | func TestVolumeActionsAttachCreateDestroy(t *testing.T) { |
| 43 | blockClient, err := clients.NewBlockStorageV2Client() |
| 44 | if err != nil { |
| 45 | t.Fatalf("Unable to create a blockstorage client: %v", err) |
Pengfei Ni | 99c3580 | 2016-05-12 22:45:26 +0800 | [diff] [blame] | 46 | } |
| 47 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 48 | computeClient, err := clients.NewComputeV2Client() |
| 49 | if err != nil { |
| 50 | t.Fatalf("Unable to create a compute client: %v", err) |
| 51 | } |
feisky | cf0c7fe | 2015-11-05 22:06:17 +0800 | [diff] [blame] | 52 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 53 | server, err := compute.CreateServer(t, computeClient) |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 54 | if err != nil { |
| 55 | t.Fatalf("Unable to create server: %v", err) |
| 56 | } |
| 57 | defer compute.DeleteServer(t, computeClient, server) |
| 58 | |
| 59 | volume, err := blockstorage.CreateVolume(t, blockClient) |
| 60 | if err != nil { |
| 61 | t.Fatalf("Unable to create volume: %v", err) |
| 62 | } |
| 63 | defer blockstorage.DeleteVolume(t, blockClient, volume) |
| 64 | |
| 65 | err = CreateVolumeAttach(t, blockClient, volume, server) |
| 66 | if err != nil { |
| 67 | t.Fatalf("Unable to attach volume: %v", err) |
| 68 | } |
| 69 | |
| 70 | newVolume, err := volumes.Get(blockClient, volume.ID).Extract() |
| 71 | if err != nil { |
| 72 | t.Fatal("Unable to get updated volume information: %v", err) |
| 73 | } |
| 74 | |
| 75 | DeleteVolumeAttach(t, blockClient, newVolume) |
feisky | cf0c7fe | 2015-11-05 22:06:17 +0800 | [diff] [blame] | 76 | } |
Pengfei Ni | 99c3580 | 2016-05-12 22:45:26 +0800 | [diff] [blame] | 77 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 78 | func TestVolumeActionsReserveUnreserve(t *testing.T) { |
| 79 | client, err := clients.NewBlockStorageV2Client() |
| 80 | if err != nil { |
| 81 | t.Fatalf("Unable to create blockstorage client: %v", err) |
| 82 | } |
Pengfei Ni | 99c3580 | 2016-05-12 22:45:26 +0800 | [diff] [blame] | 83 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 84 | volume, err := blockstorage.CreateVolume(t, client) |
| 85 | if err != nil { |
| 86 | t.Fatalf("Unable to create volume: %v", err) |
| 87 | } |
| 88 | defer blockstorage.DeleteVolume(t, client, volume) |
Jamie Hannaford | 531e0cc | 2016-05-13 13:03:39 +0200 | [diff] [blame] | 89 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 90 | err = CreateVolumeReserve(t, client, volume) |
| 91 | if err != nil { |
| 92 | t.Fatalf("Unable to create volume reserve: %v", err) |
| 93 | } |
| 94 | defer DeleteVolumeReserve(t, client, volume) |
Pengfei Ni | 99c3580 | 2016-05-12 22:45:26 +0800 | [diff] [blame] | 95 | } |
Jamie Hannaford | 531e0cc | 2016-05-13 13:03:39 +0200 | [diff] [blame] | 96 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 97 | // Note(jtopjian): I plan to work on this at some point, but it requires |
| 98 | // setting up a server with iscsi utils. |
| 99 | /* |
Jamie Hannaford | 531e0cc | 2016-05-13 13:03:39 +0200 | [diff] [blame] | 100 | func TestVolumeConns(t *testing.T) { |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 101 | client, err := newClient() |
| 102 | th.AssertNoErr(t, err) |
Jamie Hannaford | 531e0cc | 2016-05-13 13:03:39 +0200 | [diff] [blame] | 103 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 104 | t.Logf("Creating volume") |
| 105 | cv, err := volumes.Create(client, &volumes.CreateOpts{ |
| 106 | Size: 1, |
| 107 | Name: "blockv2-volume", |
| 108 | }).Extract() |
| 109 | th.AssertNoErr(t, err) |
Jamie Hannaford | 531e0cc | 2016-05-13 13:03:39 +0200 | [diff] [blame] | 110 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 111 | defer func() { |
| 112 | err = volumes.WaitForStatus(client, cv.ID, "available", 60) |
| 113 | th.AssertNoErr(t, err) |
Jamie Hannaford | 531e0cc | 2016-05-13 13:03:39 +0200 | [diff] [blame] | 114 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 115 | t.Logf("Deleting volume") |
| 116 | err = volumes.Delete(client, cv.ID).ExtractErr() |
| 117 | th.AssertNoErr(t, err) |
| 118 | }() |
Jamie Hannaford | 531e0cc | 2016-05-13 13:03:39 +0200 | [diff] [blame] | 119 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 120 | err = volumes.WaitForStatus(client, cv.ID, "available", 60) |
| 121 | th.AssertNoErr(t, err) |
Jamie Hannaford | 531e0cc | 2016-05-13 13:03:39 +0200 | [diff] [blame] | 122 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 123 | connOpts := &volumeactions.ConnectorOpts{ |
| 124 | IP: "127.0.0.1", |
| 125 | Host: "stack", |
| 126 | Initiator: "iqn.1994-05.com.redhat:17cf566367d2", |
| 127 | Multipath: false, |
| 128 | Platform: "x86_64", |
| 129 | OSType: "linux2", |
| 130 | } |
Jamie Hannaford | 531e0cc | 2016-05-13 13:03:39 +0200 | [diff] [blame] | 131 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 132 | t.Logf("Initializing connection") |
| 133 | _, err = volumeactions.InitializeConnection(client, cv.ID, connOpts).Extract() |
| 134 | th.AssertNoErr(t, err) |
Jamie Hannaford | 531e0cc | 2016-05-13 13:03:39 +0200 | [diff] [blame] | 135 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 136 | t.Logf("Terminating connection") |
| 137 | err = volumeactions.TerminateConnection(client, cv.ID, connOpts).ExtractErr() |
| 138 | th.AssertNoErr(t, err) |
Jamie Hannaford | 531e0cc | 2016-05-13 13:03:39 +0200 | [diff] [blame] | 139 | } |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 140 | */ |