ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 2 | # 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 Liu | bb363a2 | 2013-11-28 18:47:39 +0800 | [diff] [blame] | 16 | from tempest.api.volume import base |
wanghao | 5b98175 | 2013-10-22 11:41:41 +0800 | [diff] [blame] | 17 | from tempest.common.utils import data_utils |
Matthew Treinish | 4d352bc | 2014-01-29 18:29:18 +0000 | [diff] [blame] | 18 | from tempest import config |
Masayuki Igawa | ba7bcf6 | 2014-02-17 14:56:41 +0900 | [diff] [blame] | 19 | from tempest import test |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 20 | |
Matthew Treinish | 4d352bc | 2014-01-29 18:29:18 +0000 | [diff] [blame] | 21 | CONF = config.CONF |
| 22 | |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 23 | |
Zhi Kun Liu | 3d6d986 | 2014-06-16 16:43:59 +0800 | [diff] [blame] | 24 | class VolumesV2ActionsTest(base.BaseVolumeTest): |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 25 | |
| 26 | @classmethod |
Masayuki Igawa | a279a68 | 2014-03-14 13:29:42 +0900 | [diff] [blame] | 27 | @test.safe_setup |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 28 | def setUpClass(cls): |
Zhi Kun Liu | 3d6d986 | 2014-06-16 16:43:59 +0800 | [diff] [blame] | 29 | super(VolumesV2ActionsTest, cls).setUpClass() |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 30 | cls.client = cls.volumes_client |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 31 | cls.image_client = cls.os.image_client |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 32 | |
Ken'ichi Ohmichi | 5687d55 | 2013-12-26 19:00:12 +0900 | [diff] [blame] | 33 | # Create a test shared instance |
wanghao | 5b98175 | 2013-10-22 11:41:41 +0800 | [diff] [blame] | 34 | srv_name = data_utils.rand_name(cls.__name__ + '-Instance-') |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 35 | resp, cls.server = cls.servers_client.create_server(srv_name, |
| 36 | cls.image_ref, |
| 37 | cls.flavor_ref) |
| 38 | cls.servers_client.wait_for_server_status(cls.server['id'], 'ACTIVE') |
| 39 | |
Ken'ichi Ohmichi | 5687d55 | 2013-12-26 19:00:12 +0900 | [diff] [blame] | 40 | # Create a test shared volume for attach/detach tests |
| 41 | cls.volume = cls.create_volume() |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 42 | |
Attila Fazekas | 9fa2947 | 2014-08-18 09:48:00 +0200 | [diff] [blame] | 43 | 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 Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 47 | @classmethod |
| 48 | def tearDownClass(cls): |
Ken'ichi Ohmichi | 5687d55 | 2013-12-26 19:00:12 +0900 | [diff] [blame] | 49 | # Delete the test instance |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 50 | cls.servers_client.delete_server(cls.server['id']) |
Attila Fazekas | 4435bd8 | 2014-03-13 14:35:10 +0100 | [diff] [blame] | 51 | cls.servers_client.wait_for_server_termination(cls.server['id']) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 52 | |
Zhi Kun Liu | 3d6d986 | 2014-06-16 16:43:59 +0800 | [diff] [blame] | 53 | super(VolumesV2ActionsTest, cls).tearDownClass() |
Dolph Mathews | 6dbb27c | 2013-05-09 10:56:24 -0500 | [diff] [blame] | 54 | |
Masayuki Igawa | ba7bcf6 | 2014-02-17 14:56:41 +0900 | [diff] [blame] | 55 | @test.stresstest(class_setup_per='process') |
| 56 | @test.attr(type='smoke') |
| 57 | @test.services('compute') |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 58 | def test_attach_detach_volume_to_instance(self): |
Sean Dague | 72a0038 | 2013-01-03 17:53:38 -0500 | [diff] [blame] | 59 | # Volume is attached and detached successfully from an instance |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 60 | mountpoint = '/dev/vdc' |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 61 | _, body = self.client.attach_volume(self.volume['id'], |
| 62 | self.server['id'], |
| 63 | mountpoint) |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 64 | self.client.wait_for_volume_status(self.volume['id'], 'in-use') |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 65 | _, body = self.client.detach_volume(self.volume['id']) |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 66 | self.client.wait_for_volume_status(self.volume['id'], 'available') |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 67 | |
Masayuki Igawa | ba7bcf6 | 2014-02-17 14:56:41 +0900 | [diff] [blame] | 68 | @test.stresstest(class_setup_per='process') |
| 69 | @test.attr(type='gate') |
| 70 | @test.services('compute') |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 71 | def test_get_volume_attachment(self): |
Sean Dague | 72a0038 | 2013-01-03 17:53:38 -0500 | [diff] [blame] | 72 | # Verify that a volume's attachment information is retrieved |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 73 | mountpoint = '/dev/vdc' |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 74 | _, body = self.client.attach_volume(self.volume['id'], |
| 75 | self.server['id'], |
| 76 | mountpoint) |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 77 | 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']) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 84 | _, volume = self.client.get_volume(self.volume['id']) |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 85 | self.assertIn('attachments', volume) |
anju tiwari | 789449a | 2013-08-29 16:56:17 +0530 | [diff] [blame] | 86 | attachment = self.client.get_attachment_from_volume(volume) |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 87 | 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 Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 91 | |
Masayuki Igawa | ba7bcf6 | 2014-02-17 14:56:41 +0900 | [diff] [blame] | 92 | @test.attr(type='gate') |
| 93 | @test.services('image') |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 94 | 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. |
wanghao | 5b98175 | 2013-10-22 11:41:41 +0800 | [diff] [blame] | 99 | image_name = data_utils.rand_name('Image-') |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 100 | _, body = self.client.upload_volume(self.volume['id'], |
| 101 | image_name, |
| 102 | CONF.volume.disk_format) |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 103 | image_id = body["image_id"] |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 104 | self.addCleanup(self.image_client.delete_image, image_id) |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 105 | self.image_client.wait_for_image_status(image_id, 'active') |
John Griffith | a05038b | 2013-07-29 10:54:01 -0600 | [diff] [blame] | 106 | self.client.wait_for_volume_status(self.volume['id'], 'available') |
anju tiwari | 789449a | 2013-08-29 16:56:17 +0530 | [diff] [blame] | 107 | |
Masayuki Igawa | ba7bcf6 | 2014-02-17 14:56:41 +0900 | [diff] [blame] | 108 | @test.attr(type='gate') |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 109 | def test_reserve_unreserve_volume(self): |
| 110 | # Mark volume as reserved. |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 111 | _, body = self.client.reserve_volume(self.volume['id']) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 112 | # To get the volume info |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 113 | _, body = self.client.get_volume(self.volume['id']) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 114 | self.assertIn('attaching', body['status']) |
| 115 | # Unmark volume as reserved. |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 116 | _, body = self.client.unreserve_volume(self.volume['id']) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 117 | # To get the volume info |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 118 | _, body = self.client.get_volume(self.volume['id']) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 119 | self.assertIn('available', body['status']) |
| 120 | |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 121 | def _is_true(self, val): |
| 122 | return val in ['true', 'True', True] |
| 123 | |
Masayuki Igawa | ba7bcf6 | 2014-02-17 14:56:41 +0900 | [diff] [blame] | 124 | @test.attr(type='gate') |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 125 | def test_volume_readonly_update(self): |
| 126 | # Update volume readonly true |
| 127 | readonly = True |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 128 | _, body = self.client.update_volume_readonly(self.volume['id'], |
| 129 | readonly) |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 130 | # Get Volume information |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 131 | _, fetched_volume = self.client.get_volume(self.volume['id']) |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 132 | bool_flag = self._is_true(fetched_volume['metadata']['readonly']) |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 133 | self.assertEqual(True, bool_flag) |
| 134 | |
| 135 | # Update volume readonly false |
| 136 | readonly = False |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 137 | _, body = self.client.update_volume_readonly(self.volume['id'], |
| 138 | readonly) |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 139 | |
| 140 | # Get Volume information |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame^] | 141 | _, fetched_volume = self.client.get_volume(self.volume['id']) |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 142 | bool_flag = self._is_true(fetched_volume['metadata']['readonly']) |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 143 | self.assertEqual(False, bool_flag) |
| 144 | |
anju tiwari | 789449a | 2013-08-29 16:56:17 +0530 | [diff] [blame] | 145 | |
Zhi Kun Liu | 3d6d986 | 2014-06-16 16:43:59 +0800 | [diff] [blame] | 146 | class VolumesV2ActionsTestXML(VolumesV2ActionsTest): |
| 147 | _interface = "xml" |
| 148 | |
| 149 | |
| 150 | class VolumesV1ActionsTest(VolumesV2ActionsTest): |
| 151 | _api_version = 1 |
| 152 | |
| 153 | |
| 154 | class VolumesV1ActionsTestXML(VolumesV1ActionsTest): |
anju tiwari | 789449a | 2013-08-29 16:56:17 +0530 | [diff] [blame] | 155 | _interface = "xml" |