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