blob: d15d17ac68dae6637760e851afd1db45eab6e6fd [file] [log] [blame]
feiskycf0c7fe2015-11-05 22:06:17 +08001// +build acceptance blockstorage
2
3package extensions
4
5import (
feiskycf0c7fe2015-11-05 22:06:17 +08006 "testing"
7
Joe Topjian68bed5f2016-08-10 15:30:57 -06008 "github.com/gophercloud/gophercloud/acceptance/clients"
jrperritt9b7b9e62016-07-11 22:30:50 -05009 "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes"
Joe Topjian68bed5f2016-08-10 15:30:57 -060010
11 blockstorage "github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2"
12 compute "github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2"
feiskycf0c7fe2015-11-05 22:06:17 +080013)
14
Joe Topjian48f36ae2017-02-20 14:36:44 -070015func 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 Topjian68bed5f2016-08-10 15:30:57 -060042func 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 Ni99c35802016-05-12 22:45:26 +080046 }
47
Joe Topjian68bed5f2016-08-10 15:30:57 -060048 computeClient, err := clients.NewComputeV2Client()
49 if err != nil {
50 t.Fatalf("Unable to create a compute client: %v", err)
51 }
feiskycf0c7fe2015-11-05 22:06:17 +080052
Joe Topjian66a046c2017-01-19 22:07:26 -070053 server, err := compute.CreateServer(t, computeClient)
Joe Topjian68bed5f2016-08-10 15:30:57 -060054 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)
feiskycf0c7fe2015-11-05 22:06:17 +080076}
Pengfei Ni99c35802016-05-12 22:45:26 +080077
Joe Topjian68bed5f2016-08-10 15:30:57 -060078func 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 Ni99c35802016-05-12 22:45:26 +080083
Joe Topjian68bed5f2016-08-10 15:30:57 -060084 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 Hannaford531e0cc2016-05-13 13:03:39 +020089
Joe Topjian68bed5f2016-08-10 15:30:57 -060090 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 Ni99c35802016-05-12 22:45:26 +080095}
Jamie Hannaford531e0cc2016-05-13 13:03:39 +020096
Joe Topjian68bed5f2016-08-10 15:30:57 -060097// Note(jtopjian): I plan to work on this at some point, but it requires
98// setting up a server with iscsi utils.
99/*
Jamie Hannaford531e0cc2016-05-13 13:03:39 +0200100func TestVolumeConns(t *testing.T) {
Joe Topjian68bed5f2016-08-10 15:30:57 -0600101 client, err := newClient()
102 th.AssertNoErr(t, err)
Jamie Hannaford531e0cc2016-05-13 13:03:39 +0200103
Joe Topjian68bed5f2016-08-10 15:30:57 -0600104 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 Hannaford531e0cc2016-05-13 13:03:39 +0200110
Joe Topjian68bed5f2016-08-10 15:30:57 -0600111 defer func() {
112 err = volumes.WaitForStatus(client, cv.ID, "available", 60)
113 th.AssertNoErr(t, err)
Jamie Hannaford531e0cc2016-05-13 13:03:39 +0200114
Joe Topjian68bed5f2016-08-10 15:30:57 -0600115 t.Logf("Deleting volume")
116 err = volumes.Delete(client, cv.ID).ExtractErr()
117 th.AssertNoErr(t, err)
118 }()
Jamie Hannaford531e0cc2016-05-13 13:03:39 +0200119
Joe Topjian68bed5f2016-08-10 15:30:57 -0600120 err = volumes.WaitForStatus(client, cv.ID, "available", 60)
121 th.AssertNoErr(t, err)
Jamie Hannaford531e0cc2016-05-13 13:03:39 +0200122
Joe Topjian68bed5f2016-08-10 15:30:57 -0600123 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 Hannaford531e0cc2016-05-13 13:03:39 +0200131
Joe Topjian68bed5f2016-08-10 15:30:57 -0600132 t.Logf("Initializing connection")
133 _, err = volumeactions.InitializeConnection(client, cv.ID, connOpts).Extract()
134 th.AssertNoErr(t, err)
Jamie Hannaford531e0cc2016-05-13 13:03:39 +0200135
Joe Topjian68bed5f2016-08-10 15:30:57 -0600136 t.Logf("Terminating connection")
137 err = volumeactions.TerminateConnection(client, cv.ID, connOpts).ExtractErr()
138 th.AssertNoErr(t, err)
Jamie Hannaford531e0cc2016-05-13 13:03:39 +0200139}
Joe Topjian68bed5f2016-08-10 15:30:57 -0600140*/