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