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 | |
Matthew Treinish | 01472ff | 2015-02-20 17:26:52 -0500 | [diff] [blame] | 16 | from tempest_lib.common.utils import data_utils |
| 17 | |
Zhi Kun Liu | bb363a2 | 2013-11-28 18:47:39 +0800 | [diff] [blame] | 18 | from tempest.api.volume import base |
Matthew Treinish | 4d352bc | 2014-01-29 18:29:18 +0000 | [diff] [blame] | 19 | from tempest import config |
Masayuki Igawa | ba7bcf6 | 2014-02-17 14:56:41 +0900 | [diff] [blame] | 20 | from tempest import test |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 21 | |
Matthew Treinish | 4d352bc | 2014-01-29 18:29:18 +0000 | [diff] [blame] | 22 | CONF = config.CONF |
| 23 | |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 24 | |
Zhi Kun Liu | 3d6d986 | 2014-06-16 16:43:59 +0800 | [diff] [blame] | 25 | class VolumesV2ActionsTest(base.BaseVolumeTest): |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 26 | |
| 27 | @classmethod |
Rohan Kanade | 0574915 | 2015-01-30 17:15:18 +0530 | [diff] [blame] | 28 | def setup_clients(cls): |
| 29 | super(VolumesV2ActionsTest, cls).setup_clients() |
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 | |
Rohan Kanade | 0574915 | 2015-01-30 17:15:18 +0530 | [diff] [blame] | 33 | @classmethod |
| 34 | def resource_setup(cls): |
| 35 | super(VolumesV2ActionsTest, cls).resource_setup() |
| 36 | |
Ken'ichi Ohmichi | 5687d55 | 2013-12-26 19:00:12 +0900 | [diff] [blame] | 37 | # Create a test shared instance |
Ken'ichi Ohmichi | 07308f1 | 2015-03-23 00:24:28 +0000 | [diff] [blame] | 38 | srv_name = data_utils.rand_name(cls.__name__ + '-Instance') |
Rohan Kanade | 9ce97df | 2013-12-10 18:59:35 +0530 | [diff] [blame] | 39 | cls.server = cls.create_server(srv_name) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 40 | cls.servers_client.wait_for_server_status(cls.server['id'], 'ACTIVE') |
| 41 | |
Ken'ichi Ohmichi | 5687d55 | 2013-12-26 19:00:12 +0900 | [diff] [blame] | 42 | # Create a test shared volume for attach/detach tests |
| 43 | cls.volume = cls.create_volume() |
JordanP | 0a27a35 | 2015-02-16 11:16:51 +0100 | [diff] [blame] | 44 | cls.client.wait_for_volume_status(cls.volume['id'], 'available') |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 45 | |
Attila Fazekas | 9fa2947 | 2014-08-18 09:48:00 +0200 | [diff] [blame] | 46 | def _delete_image_with_wait(self, image_id): |
| 47 | self.image_client.delete_image(image_id) |
| 48 | self.image_client.wait_for_resource_deletion(image_id) |
| 49 | |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 50 | @classmethod |
Andrea Frittoli | 61a12e2 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 51 | def resource_cleanup(cls): |
Ken'ichi Ohmichi | 5687d55 | 2013-12-26 19:00:12 +0900 | [diff] [blame] | 52 | # Delete the test instance |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 53 | cls.servers_client.delete_server(cls.server['id']) |
Attila Fazekas | 4435bd8 | 2014-03-13 14:35:10 +0100 | [diff] [blame] | 54 | cls.servers_client.wait_for_server_termination(cls.server['id']) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 55 | |
Andrea Frittoli | 61a12e2 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 56 | super(VolumesV2ActionsTest, cls).resource_cleanup() |
Dolph Mathews | 6dbb27c | 2013-05-09 10:56:24 -0500 | [diff] [blame] | 57 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 58 | @test.idempotent_id('fff42874-7db5-4487-a8e1-ddda5fb5288d') |
Masayuki Igawa | ba7bcf6 | 2014-02-17 14:56:41 +0900 | [diff] [blame] | 59 | @test.stresstest(class_setup_per='process') |
| 60 | @test.attr(type='smoke') |
| 61 | @test.services('compute') |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 62 | def test_attach_detach_volume_to_instance(self): |
Sean Dague | 72a0038 | 2013-01-03 17:53:38 -0500 | [diff] [blame] | 63 | # Volume is attached and detached successfully from an instance |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 64 | mountpoint = '/dev/vdc' |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 65 | self.client.attach_volume(self.volume['id'], |
| 66 | self.server['id'], |
| 67 | mountpoint) |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 68 | self.client.wait_for_volume_status(self.volume['id'], 'in-use') |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 69 | self.client.detach_volume(self.volume['id']) |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 70 | self.client.wait_for_volume_status(self.volume['id'], 'available') |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 71 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 72 | @test.idempotent_id('9516a2c8-9135-488c-8dd6-5677a7e5f371') |
Masayuki Igawa | ba7bcf6 | 2014-02-17 14:56:41 +0900 | [diff] [blame] | 73 | @test.stresstest(class_setup_per='process') |
| 74 | @test.attr(type='gate') |
| 75 | @test.services('compute') |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 76 | def test_get_volume_attachment(self): |
Sean Dague | 72a0038 | 2013-01-03 17:53:38 -0500 | [diff] [blame] | 77 | # Verify that a volume's attachment information is retrieved |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 78 | mountpoint = '/dev/vdc' |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 79 | self.client.attach_volume(self.volume['id'], |
| 80 | self.server['id'], |
| 81 | mountpoint) |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 82 | self.client.wait_for_volume_status(self.volume['id'], 'in-use') |
| 83 | # NOTE(gfidente): added in reverse order because functions will be |
| 84 | # called in reverse order to the order they are added (LIFO) |
| 85 | self.addCleanup(self.client.wait_for_volume_status, |
| 86 | self.volume['id'], |
| 87 | 'available') |
| 88 | self.addCleanup(self.client.detach_volume, self.volume['id']) |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 89 | volume = self.client.show_volume(self.volume['id']) |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 90 | self.assertIn('attachments', volume) |
anju tiwari | 789449a | 2013-08-29 16:56:17 +0530 | [diff] [blame] | 91 | attachment = self.client.get_attachment_from_volume(volume) |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 92 | self.assertEqual(mountpoint, attachment['device']) |
| 93 | self.assertEqual(self.server['id'], attachment['server_id']) |
| 94 | self.assertEqual(self.volume['id'], attachment['id']) |
| 95 | self.assertEqual(self.volume['id'], attachment['volume_id']) |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 96 | |
Masayuki Igawa | ba7bcf6 | 2014-02-17 14:56:41 +0900 | [diff] [blame] | 97 | @test.attr(type='gate') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 98 | @test.idempotent_id('d8f1ca95-3d5b-44a3-b8ca-909691c9532d') |
Masayuki Igawa | ba7bcf6 | 2014-02-17 14:56:41 +0900 | [diff] [blame] | 99 | @test.services('image') |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 100 | def test_volume_upload(self): |
| 101 | # NOTE(gfidente): the volume uploaded in Glance comes from setUpClass, |
| 102 | # it is shared with the other tests. After it is uploaded in Glance, |
| 103 | # there is no way to delete it from Cinder, so we delete it from Glance |
| 104 | # using the Glance image_client and from Cinder via tearDownClass. |
Ken'ichi Ohmichi | 07308f1 | 2015-03-23 00:24:28 +0000 | [diff] [blame] | 105 | image_name = data_utils.rand_name('Image') |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 106 | body = self.client.upload_volume(self.volume['id'], |
| 107 | image_name, |
| 108 | CONF.volume.disk_format) |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 109 | image_id = body["image_id"] |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 110 | self.addCleanup(self.image_client.delete_image, image_id) |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 111 | self.image_client.wait_for_image_status(image_id, 'active') |
John Griffith | a05038b | 2013-07-29 10:54:01 -0600 | [diff] [blame] | 112 | self.client.wait_for_volume_status(self.volume['id'], 'available') |
anju tiwari | 789449a | 2013-08-29 16:56:17 +0530 | [diff] [blame] | 113 | |
Masayuki Igawa | ba7bcf6 | 2014-02-17 14:56:41 +0900 | [diff] [blame] | 114 | @test.attr(type='gate') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 115 | @test.idempotent_id('92c4ef64-51b2-40c0-9f7e-4749fbaaba33') |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 116 | def test_reserve_unreserve_volume(self): |
| 117 | # Mark volume as reserved. |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 118 | body = self.client.reserve_volume(self.volume['id']) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 119 | # To get the volume info |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 120 | body = self.client.show_volume(self.volume['id']) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 121 | self.assertIn('attaching', body['status']) |
| 122 | # Unmark volume as reserved. |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 123 | body = self.client.unreserve_volume(self.volume['id']) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 124 | # To get the volume info |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 125 | body = self.client.show_volume(self.volume['id']) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 126 | self.assertIn('available', body['status']) |
| 127 | |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 128 | def _is_true(self, val): |
| 129 | return val in ['true', 'True', True] |
| 130 | |
Masayuki Igawa | ba7bcf6 | 2014-02-17 14:56:41 +0900 | [diff] [blame] | 131 | @test.attr(type='gate') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 132 | @test.idempotent_id('fff74e1e-5bd3-4b33-9ea9-24c103bc3f59') |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 133 | def test_volume_readonly_update(self): |
| 134 | # Update volume readonly true |
| 135 | readonly = True |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 136 | self.client.update_volume_readonly(self.volume['id'], |
| 137 | readonly) |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 138 | # Get Volume information |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 139 | fetched_volume = self.client.show_volume(self.volume['id']) |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 140 | bool_flag = self._is_true(fetched_volume['metadata']['readonly']) |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 141 | self.assertEqual(True, bool_flag) |
| 142 | |
| 143 | # Update volume readonly false |
| 144 | readonly = False |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 145 | self.client.update_volume_readonly(self.volume['id'], readonly) |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 146 | |
| 147 | # Get Volume information |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 148 | fetched_volume = self.client.show_volume(self.volume['id']) |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 149 | bool_flag = self._is_true(fetched_volume['metadata']['readonly']) |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 150 | self.assertEqual(False, bool_flag) |
| 151 | |
anju tiwari | 789449a | 2013-08-29 16:56:17 +0530 | [diff] [blame] | 152 | |
Zhi Kun Liu | 3d6d986 | 2014-06-16 16:43:59 +0800 | [diff] [blame] | 153 | class VolumesV1ActionsTest(VolumesV2ActionsTest): |
| 154 | _api_version = 1 |