blob: 333a4f706d2db33752d986296dcb9a952dff1ab7 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Rohit Karajgia42fe442012-09-21 03:08:33 -07002# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Zhi Kun Liubb363a22013-11-28 18:47:39 +080016from tempest.api.volume import base
wanghao5b981752013-10-22 11:41:41 +080017from tempest.common.utils import data_utils
Matthew Treinish4d352bc2014-01-29 18:29:18 +000018from tempest import config
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090019from tempest import test
Rohit Karajgia42fe442012-09-21 03:08:33 -070020
Matthew Treinish4d352bc2014-01-29 18:29:18 +000021CONF = config.CONF
22
Rohit Karajgia42fe442012-09-21 03:08:33 -070023
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +080024class VolumesV2ActionsTest(base.BaseVolumeTest):
Rohit Karajgia42fe442012-09-21 03:08:33 -070025
26 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010027 def resource_setup(cls):
28 super(VolumesV2ActionsTest, cls).resource_setup()
Rohit Karajgia42fe442012-09-21 03:08:33 -070029 cls.client = cls.volumes_client
Giulio Fidente884e9da2013-06-21 17:25:42 +020030 cls.image_client = cls.os.image_client
Rohit Karajgia42fe442012-09-21 03:08:33 -070031
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090032 # Create a test shared instance
wanghao5b981752013-10-22 11:41:41 +080033 srv_name = data_utils.rand_name(cls.__name__ + '-Instance-')
David Kranz0fb14292015-02-11 15:55:20 -050034 cls.server = cls.servers_client.create_server(srv_name,
35 cls.image_ref,
36 cls.flavor_ref)
Rohit Karajgia42fe442012-09-21 03:08:33 -070037 cls.servers_client.wait_for_server_status(cls.server['id'], 'ACTIVE')
38
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090039 # Create a test shared volume for attach/detach tests
40 cls.volume = cls.create_volume()
JordanP0a27a352015-02-16 11:16:51 +010041 cls.client.wait_for_volume_status(cls.volume['id'], 'available')
Rohit Karajgia42fe442012-09-21 03:08:33 -070042
Attila Fazekas9fa29472014-08-18 09:48:00 +020043 def _delete_image_with_wait(self, image_id):
44 self.image_client.delete_image(image_id)
45 self.image_client.wait_for_resource_deletion(image_id)
46
Rohit Karajgia42fe442012-09-21 03:08:33 -070047 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010048 def resource_cleanup(cls):
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090049 # Delete the test instance
Rohit Karajgia42fe442012-09-21 03:08:33 -070050 cls.servers_client.delete_server(cls.server['id'])
Attila Fazekas4435bd82014-03-13 14:35:10 +010051 cls.servers_client.wait_for_server_termination(cls.server['id'])
Rohit Karajgia42fe442012-09-21 03:08:33 -070052
Andrea Frittoli61a12e22014-09-15 13:14:54 +010053 super(VolumesV2ActionsTest, cls).resource_cleanup()
Dolph Mathews6dbb27c2013-05-09 10:56:24 -050054
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090055 @test.stresstest(class_setup_per='process')
56 @test.attr(type='smoke')
57 @test.services('compute')
Rohit Karajgia42fe442012-09-21 03:08:33 -070058 def test_attach_detach_volume_to_instance(self):
Sean Dague72a00382013-01-03 17:53:38 -050059 # Volume is attached and detached successfully from an instance
Giulio Fidente92f77192013-08-26 17:13:28 +020060 mountpoint = '/dev/vdc'
Joseph Lanoux6809bab2014-12-18 14:57:18 +000061 self.client.attach_volume(self.volume['id'],
62 self.server['id'],
63 mountpoint)
Giulio Fidente92f77192013-08-26 17:13:28 +020064 self.client.wait_for_volume_status(self.volume['id'], 'in-use')
Joseph Lanoux6809bab2014-12-18 14:57:18 +000065 self.client.detach_volume(self.volume['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +020066 self.client.wait_for_volume_status(self.volume['id'], 'available')
Rohit Karajgia42fe442012-09-21 03:08:33 -070067
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090068 @test.stresstest(class_setup_per='process')
69 @test.attr(type='gate')
70 @test.services('compute')
Rohit Karajgia42fe442012-09-21 03:08:33 -070071 def test_get_volume_attachment(self):
Sean Dague72a00382013-01-03 17:53:38 -050072 # Verify that a volume's attachment information is retrieved
Rohit Karajgia42fe442012-09-21 03:08:33 -070073 mountpoint = '/dev/vdc'
Joseph Lanoux6809bab2014-12-18 14:57:18 +000074 self.client.attach_volume(self.volume['id'],
75 self.server['id'],
76 mountpoint)
Giulio Fidente92f77192013-08-26 17:13:28 +020077 self.client.wait_for_volume_status(self.volume['id'], 'in-use')
78 # NOTE(gfidente): added in reverse order because functions will be
79 # called in reverse order to the order they are added (LIFO)
80 self.addCleanup(self.client.wait_for_volume_status,
81 self.volume['id'],
82 'available')
83 self.addCleanup(self.client.detach_volume, self.volume['id'])
Joseph Lanoux6809bab2014-12-18 14:57:18 +000084 volume = self.client.get_volume(self.volume['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +020085 self.assertIn('attachments', volume)
anju tiwari789449a2013-08-29 16:56:17 +053086 attachment = self.client.get_attachment_from_volume(volume)
Giulio Fidente92f77192013-08-26 17:13:28 +020087 self.assertEqual(mountpoint, attachment['device'])
88 self.assertEqual(self.server['id'], attachment['server_id'])
89 self.assertEqual(self.volume['id'], attachment['id'])
90 self.assertEqual(self.volume['id'], attachment['volume_id'])
Giulio Fidente884e9da2013-06-21 17:25:42 +020091
Masayuki Igawaba7bcf62014-02-17 14:56:41 +090092 @test.attr(type='gate')
93 @test.services('image')
Giulio Fidente884e9da2013-06-21 17:25:42 +020094 def test_volume_upload(self):
95 # NOTE(gfidente): the volume uploaded in Glance comes from setUpClass,
96 # it is shared with the other tests. After it is uploaded in Glance,
97 # there is no way to delete it from Cinder, so we delete it from Glance
98 # using the Glance image_client and from Cinder via tearDownClass.
wanghao5b981752013-10-22 11:41:41 +080099 image_name = data_utils.rand_name('Image-')
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000100 body = self.client.upload_volume(self.volume['id'],
101 image_name,
102 CONF.volume.disk_format)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200103 image_id = body["image_id"]
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000104 self.addCleanup(self.image_client.delete_image, image_id)
Giulio Fidente884e9da2013-06-21 17:25:42 +0200105 self.image_client.wait_for_image_status(image_id, 'active')
John Griffitha05038b2013-07-29 10:54:01 -0600106 self.client.wait_for_volume_status(self.volume['id'], 'available')
anju tiwari789449a2013-08-29 16:56:17 +0530107
Masayuki Igawaba7bcf62014-02-17 14:56:41 +0900108 @test.attr(type='gate')
zhangyanzi6b632432013-10-24 19:08:50 +0800109 def test_reserve_unreserve_volume(self):
110 # Mark volume as reserved.
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000111 body = self.client.reserve_volume(self.volume['id'])
zhangyanzi6b632432013-10-24 19:08:50 +0800112 # To get the volume info
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000113 body = self.client.get_volume(self.volume['id'])
zhangyanzi6b632432013-10-24 19:08:50 +0800114 self.assertIn('attaching', body['status'])
115 # Unmark volume as reserved.
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000116 body = self.client.unreserve_volume(self.volume['id'])
zhangyanzi6b632432013-10-24 19:08:50 +0800117 # To get the volume info
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000118 body = self.client.get_volume(self.volume['id'])
zhangyanzi6b632432013-10-24 19:08:50 +0800119 self.assertIn('available', body['status'])
120
zhangyanziaa180072013-11-21 12:31:26 +0800121 def _is_true(self, val):
122 return val in ['true', 'True', True]
123
Masayuki Igawaba7bcf62014-02-17 14:56:41 +0900124 @test.attr(type='gate')
zhangyanziaa180072013-11-21 12:31:26 +0800125 def test_volume_readonly_update(self):
126 # Update volume readonly true
127 readonly = True
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000128 self.client.update_volume_readonly(self.volume['id'],
129 readonly)
zhangyanziaa180072013-11-21 12:31:26 +0800130 # Get Volume information
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000131 fetched_volume = self.client.get_volume(self.volume['id'])
zhangyanziaa180072013-11-21 12:31:26 +0800132 bool_flag = self._is_true(fetched_volume['metadata']['readonly'])
zhangyanziaa180072013-11-21 12:31:26 +0800133 self.assertEqual(True, bool_flag)
134
135 # Update volume readonly false
136 readonly = False
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000137 self.client.update_volume_readonly(self.volume['id'], readonly)
zhangyanziaa180072013-11-21 12:31:26 +0800138
139 # Get Volume information
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000140 fetched_volume = self.client.get_volume(self.volume['id'])
zhangyanziaa180072013-11-21 12:31:26 +0800141 bool_flag = self._is_true(fetched_volume['metadata']['readonly'])
zhangyanziaa180072013-11-21 12:31:26 +0800142 self.assertEqual(False, bool_flag)
143
anju tiwari789449a2013-08-29 16:56:17 +0530144
Zhi Kun Liu3d6d9862014-06-16 16:43:59 +0800145class VolumesV1ActionsTest(VolumesV2ActionsTest):
146 _api_version = 1