blob: a088dd69c45dfc5760f7826b1f06eecbb9317f6f [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 Topjian66a046c2017-01-19 22:07:26 -070026 server, err := compute.CreateServer(t, computeClient)
Joe Topjian68bed5f2016-08-10 15:30:57 -060027 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)
feiskycf0c7fe2015-11-05 22:06:17 +080049}
Pengfei Ni99c35802016-05-12 22:45:26 +080050
Joe Topjian68bed5f2016-08-10 15:30:57 -060051func 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 Ni99c35802016-05-12 22:45:26 +080056
Joe Topjian68bed5f2016-08-10 15:30:57 -060057 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 Hannaford531e0cc2016-05-13 13:03:39 +020062
Joe Topjian68bed5f2016-08-10 15:30:57 -060063 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 Ni99c35802016-05-12 22:45:26 +080068}
Jamie Hannaford531e0cc2016-05-13 13:03:39 +020069
Joe Topjian68bed5f2016-08-10 15:30:57 -060070// Note(jtopjian): I plan to work on this at some point, but it requires
71// setting up a server with iscsi utils.
72/*
Jamie Hannaford531e0cc2016-05-13 13:03:39 +020073func TestVolumeConns(t *testing.T) {
Joe Topjian68bed5f2016-08-10 15:30:57 -060074 client, err := newClient()
75 th.AssertNoErr(t, err)
Jamie Hannaford531e0cc2016-05-13 13:03:39 +020076
Joe Topjian68bed5f2016-08-10 15:30:57 -060077 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 Hannaford531e0cc2016-05-13 13:03:39 +020083
Joe Topjian68bed5f2016-08-10 15:30:57 -060084 defer func() {
85 err = volumes.WaitForStatus(client, cv.ID, "available", 60)
86 th.AssertNoErr(t, err)
Jamie Hannaford531e0cc2016-05-13 13:03:39 +020087
Joe Topjian68bed5f2016-08-10 15:30:57 -060088 t.Logf("Deleting volume")
89 err = volumes.Delete(client, cv.ID).ExtractErr()
90 th.AssertNoErr(t, err)
91 }()
Jamie Hannaford531e0cc2016-05-13 13:03:39 +020092
Joe Topjian68bed5f2016-08-10 15:30:57 -060093 err = volumes.WaitForStatus(client, cv.ID, "available", 60)
94 th.AssertNoErr(t, err)
Jamie Hannaford531e0cc2016-05-13 13:03:39 +020095
Joe Topjian68bed5f2016-08-10 15:30:57 -060096 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 Hannaford531e0cc2016-05-13 13:03:39 +0200104
Joe Topjian68bed5f2016-08-10 15:30:57 -0600105 t.Logf("Initializing connection")
106 _, err = volumeactions.InitializeConnection(client, cv.ID, connOpts).Extract()
107 th.AssertNoErr(t, err)
Jamie Hannaford531e0cc2016-05-13 13:03:39 +0200108
Joe Topjian68bed5f2016-08-10 15:30:57 -0600109 t.Logf("Terminating connection")
110 err = volumeactions.TerminateConnection(client, cv.ID, connOpts).ExtractErr()
111 th.AssertNoErr(t, err)
Jamie Hannaford531e0cc2016-05-13 13:03:39 +0200112}
Joe Topjian68bed5f2016-08-10 15:30:57 -0600113*/