blob: 83d1571a8d666dcb0d7564f5699fe0051779ca6a [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 Topjian68bed5f2016-08-10 15:30:57 -060015func 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 Ni99c35802016-05-12 22:45:26 +080019 }
20
Joe Topjian68bed5f2016-08-10 15:30:57 -060021 computeClient, err := clients.NewComputeV2Client()
22 if err != nil {
23 t.Fatalf("Unable to create a compute client: %v", err)
24 }
feiskycf0c7fe2015-11-05 22:06:17 +080025
Joe Topjian68bed5f2016-08-10 15:30:57 -060026 choices, err := clients.AcceptanceTestChoicesFromEnv()
27 if err != nil {
28 t.Fatal(err)
29 }
feiskycf0c7fe2015-11-05 22:06:17 +080030
Joe Topjian68bed5f2016-08-10 15:30:57 -060031 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)
feiskycf0c7fe2015-11-05 22:06:17 +080054}
Pengfei Ni99c35802016-05-12 22:45:26 +080055
Joe Topjian68bed5f2016-08-10 15:30:57 -060056func 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 Ni99c35802016-05-12 22:45:26 +080061
Joe Topjian68bed5f2016-08-10 15:30:57 -060062 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 Hannaford531e0cc2016-05-13 13:03:39 +020067
Joe Topjian68bed5f2016-08-10 15:30:57 -060068 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 Ni99c35802016-05-12 22:45:26 +080073}
Jamie Hannaford531e0cc2016-05-13 13:03:39 +020074
Joe Topjian68bed5f2016-08-10 15:30:57 -060075// Note(jtopjian): I plan to work on this at some point, but it requires
76// setting up a server with iscsi utils.
77/*
Jamie Hannaford531e0cc2016-05-13 13:03:39 +020078func TestVolumeConns(t *testing.T) {
Joe Topjian68bed5f2016-08-10 15:30:57 -060079 client, err := newClient()
80 th.AssertNoErr(t, err)
Jamie Hannaford531e0cc2016-05-13 13:03:39 +020081
Joe Topjian68bed5f2016-08-10 15:30:57 -060082 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 Hannaford531e0cc2016-05-13 13:03:39 +020088
Joe Topjian68bed5f2016-08-10 15:30:57 -060089 defer func() {
90 err = volumes.WaitForStatus(client, cv.ID, "available", 60)
91 th.AssertNoErr(t, err)
Jamie Hannaford531e0cc2016-05-13 13:03:39 +020092
Joe Topjian68bed5f2016-08-10 15:30:57 -060093 t.Logf("Deleting volume")
94 err = volumes.Delete(client, cv.ID).ExtractErr()
95 th.AssertNoErr(t, err)
96 }()
Jamie Hannaford531e0cc2016-05-13 13:03:39 +020097
Joe Topjian68bed5f2016-08-10 15:30:57 -060098 err = volumes.WaitForStatus(client, cv.ID, "available", 60)
99 th.AssertNoErr(t, err)
Jamie Hannaford531e0cc2016-05-13 13:03:39 +0200100
Joe Topjian68bed5f2016-08-10 15:30:57 -0600101 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 Hannaford531e0cc2016-05-13 13:03:39 +0200109
Joe Topjian68bed5f2016-08-10 15:30:57 -0600110 t.Logf("Initializing connection")
111 _, err = volumeactions.InitializeConnection(client, cv.ID, connOpts).Extract()
112 th.AssertNoErr(t, err)
Jamie Hannaford531e0cc2016-05-13 13:03:39 +0200113
Joe Topjian68bed5f2016-08-10 15:30:57 -0600114 t.Logf("Terminating connection")
115 err = volumeactions.TerminateConnection(client, cv.ID, connOpts).ExtractErr()
116 th.AssertNoErr(t, err)
Jamie Hannaford531e0cc2016-05-13 13:03:39 +0200117}
Joe Topjian68bed5f2016-08-10 15:30:57 -0600118*/