ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -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 | |
Giulio Fidente | 5ed48ce | 2014-01-09 18:28:28 +0100 | [diff] [blame] | 16 | from testtools.matchers import ContainsAll |
| 17 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 18 | from tempest.api.volume import base |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 19 | from tempest.common.utils import data_utils |
Matthew Treinish | 4d352bc | 2014-01-29 18:29:18 +0000 | [diff] [blame] | 20 | from tempest import config |
Chris Yeoh | 01cb279 | 2013-02-09 22:25:37 +1030 | [diff] [blame] | 21 | from tempest.test import attr |
Matthew Treinish | 660a4c1 | 2013-09-09 20:06:12 +0000 | [diff] [blame] | 22 | from tempest.test import services |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 23 | |
Matthew Treinish | 4d352bc | 2014-01-29 18:29:18 +0000 | [diff] [blame] | 24 | CONF = config.CONF |
| 25 | |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 26 | |
Zhi Kun Liu | bb363a2 | 2013-11-28 18:47:39 +0800 | [diff] [blame] | 27 | class VolumesGetTest(base.BaseVolumeV1Test): |
Attila Fazekas | 3dcdae1 | 2013-02-14 12:50:04 +0100 | [diff] [blame] | 28 | _interface = "json" |
| 29 | |
| 30 | @classmethod |
| 31 | def setUpClass(cls): |
| 32 | super(VolumesGetTest, cls).setUpClass() |
| 33 | cls.client = cls.volumes_client |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 34 | |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 35 | def _delete_volume(self, volume_id): |
| 36 | resp, _ = self.client.delete_volume(volume_id) |
| 37 | self.assertEqual(202, resp.status) |
| 38 | self.client.wait_for_resource_deletion(volume_id) |
| 39 | |
John Griffith | d1fefd5 | 2013-09-23 20:40:37 +0000 | [diff] [blame] | 40 | def _is_true(self, val): |
| 41 | # NOTE(jdg): Temporary conversion method to get cinder patch |
| 42 | # merged. Then we'll make this strict again and |
| 43 | #specifically check "true" or "false" |
| 44 | if val in ['true', 'True', True]: |
| 45 | return True |
| 46 | else: |
| 47 | return False |
| 48 | |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 49 | def _volume_create_get_update_delete(self, **kwargs): |
Sean Dague | 72a0038 | 2013-01-03 17:53:38 -0500 | [diff] [blame] | 50 | # Create a volume, Get it's details and Delete the volume |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 51 | volume = {} |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 52 | v_name = data_utils.rand_name('Volume') |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 53 | metadata = {'Type': 'Test'} |
| 54 | # Create a volume |
| 55 | resp, volume = self.client.create_volume(size=1, |
| 56 | display_name=v_name, |
| 57 | metadata=metadata, |
| 58 | **kwargs) |
| 59 | self.assertEqual(200, resp.status) |
| 60 | self.assertIn('id', volume) |
| 61 | self.addCleanup(self._delete_volume, volume['id']) |
| 62 | self.assertIn('display_name', volume) |
| 63 | self.assertEqual(volume['display_name'], v_name, |
| 64 | "The created volume name is not equal " |
| 65 | "to the requested name") |
| 66 | self.assertTrue(volume['id'] is not None, |
| 67 | "Field volume id is empty or not found.") |
| 68 | self.client.wait_for_volume_status(volume['id'], 'available') |
| 69 | # Get Volume information |
| 70 | resp, fetched_volume = self.client.get_volume(volume['id']) |
| 71 | self.assertEqual(200, resp.status) |
| 72 | self.assertEqual(v_name, |
| 73 | fetched_volume['display_name'], |
Giulio Fidente | 5ed48ce | 2014-01-09 18:28:28 +0100 | [diff] [blame] | 74 | 'The fetched Volume name is different ' |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 75 | 'from the created Volume') |
| 76 | self.assertEqual(volume['id'], |
| 77 | fetched_volume['id'], |
Giulio Fidente | 5ed48ce | 2014-01-09 18:28:28 +0100 | [diff] [blame] | 78 | 'The fetched Volume id is different ' |
Matt Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 79 | 'from the created Volume') |
Giulio Fidente | 5ed48ce | 2014-01-09 18:28:28 +0100 | [diff] [blame] | 80 | self.assertThat(fetched_volume['metadata'].items(), |
| 81 | ContainsAll(metadata.items()), |
| 82 | 'The fetched Volume metadata misses data ' |
| 83 | 'from the created Volume') |
John Griffith | d1fefd5 | 2013-09-23 20:40:37 +0000 | [diff] [blame] | 84 | |
| 85 | # NOTE(jdg): Revert back to strict true/false checking |
| 86 | # after fix for bug #1227837 merges |
| 87 | boot_flag = self._is_true(fetched_volume['bootable']) |
Nayna Patel | 5e76be1 | 2013-08-19 12:10:16 +0000 | [diff] [blame] | 88 | if 'imageRef' in kwargs: |
John Griffith | d1fefd5 | 2013-09-23 20:40:37 +0000 | [diff] [blame] | 89 | self.assertEqual(boot_flag, True) |
Nayna Patel | 5e76be1 | 2013-08-19 12:10:16 +0000 | [diff] [blame] | 90 | if 'imageRef' not in kwargs: |
John Griffith | d1fefd5 | 2013-09-23 20:40:37 +0000 | [diff] [blame] | 91 | self.assertEqual(boot_flag, False) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 92 | |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 93 | # Update Volume |
Xiao Chen | 1ea9367 | 2014-01-09 10:10:47 +0800 | [diff] [blame] | 94 | # Test volume update when display_name is same with original value |
| 95 | resp, update_volume = \ |
| 96 | self.client.update_volume(volume['id'], |
| 97 | display_name=v_name) |
| 98 | self.assertEqual(200, resp.status) |
| 99 | # Test volume update when display_name is new |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 100 | new_v_name = data_utils.rand_name('new-Volume') |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 101 | new_desc = 'This is the new description of volume' |
| 102 | resp, update_volume = \ |
| 103 | self.client.update_volume(volume['id'], |
| 104 | display_name=new_v_name, |
| 105 | display_description=new_desc) |
| 106 | # Assert response body for update_volume method |
| 107 | self.assertEqual(200, resp.status) |
| 108 | self.assertEqual(new_v_name, update_volume['display_name']) |
| 109 | self.assertEqual(new_desc, update_volume['display_description']) |
| 110 | # Assert response body for get_volume method |
| 111 | resp, updated_volume = self.client.get_volume(volume['id']) |
| 112 | self.assertEqual(200, resp.status) |
| 113 | self.assertEqual(volume['id'], updated_volume['id']) |
| 114 | self.assertEqual(new_v_name, updated_volume['display_name']) |
| 115 | self.assertEqual(new_desc, updated_volume['display_description']) |
Giulio Fidente | 5ed48ce | 2014-01-09 18:28:28 +0100 | [diff] [blame] | 116 | self.assertThat(updated_volume['metadata'].items(), |
| 117 | ContainsAll(metadata.items()), |
| 118 | 'The fetched Volume metadata misses data ' |
| 119 | 'from the created Volume') |
Xiao Chen | 1ea9367 | 2014-01-09 10:10:47 +0800 | [diff] [blame] | 120 | # Test volume create when display_name is none and display_description |
| 121 | # contains specific characters, |
| 122 | # then test volume update if display_name is duplicated |
| 123 | new_volume = {} |
| 124 | new_v_desc = data_utils.rand_name('@#$%^* description') |
| 125 | resp, new_volume = \ |
| 126 | self.client.create_volume(size=1, |
| 127 | display_description=new_v_desc, |
| 128 | availability_zone=volume[ |
| 129 | 'availability_zone']) |
| 130 | self.assertEqual(200, resp.status) |
| 131 | self.assertIn('id', new_volume) |
| 132 | self.addCleanup(self._delete_volume, new_volume['id']) |
| 133 | self.client.wait_for_volume_status(new_volume['id'], 'available') |
| 134 | resp, update_volume = \ |
| 135 | self.client.update_volume(new_volume['id'], |
| 136 | display_name=volume['display_name'], |
| 137 | display_description=volume[ |
| 138 | 'display_description']) |
| 139 | self.assertEqual(200, resp.status) |
John Griffith | d1fefd5 | 2013-09-23 20:40:37 +0000 | [diff] [blame] | 140 | |
| 141 | # NOTE(jdg): Revert back to strict true/false checking |
| 142 | # after fix for bug #1227837 merges |
| 143 | boot_flag = self._is_true(updated_volume['bootable']) |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 144 | if 'imageRef' in kwargs: |
John Griffith | d1fefd5 | 2013-09-23 20:40:37 +0000 | [diff] [blame] | 145 | self.assertEqual(boot_flag, True) |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 146 | if 'imageRef' not in kwargs: |
John Griffith | d1fefd5 | 2013-09-23 20:40:37 +0000 | [diff] [blame] | 147 | self.assertEqual(boot_flag, False) |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 148 | |
Giulio Fidente | ba3985a | 2013-05-29 01:46:36 +0200 | [diff] [blame] | 149 | @attr(type='smoke') |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 150 | def test_volume_create_get_update_delete(self): |
| 151 | self._volume_create_get_update_delete() |
Giulio Fidente | 36836c4 | 2013-04-05 15:43:51 +0200 | [diff] [blame] | 152 | |
Giulio Fidente | ba3985a | 2013-05-29 01:46:36 +0200 | [diff] [blame] | 153 | @attr(type='smoke') |
Matthew Treinish | 660a4c1 | 2013-09-09 20:06:12 +0000 | [diff] [blame] | 154 | @services('image') |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 155 | def test_volume_create_get_update_delete_from_image(self): |
Matthew Treinish | 4d352bc | 2014-01-29 18:29:18 +0000 | [diff] [blame] | 156 | self._volume_create_get_update_delete(imageRef=CONF.compute.image_ref) |
Giulio Fidente | 02f4298 | 2013-06-17 16:25:56 +0200 | [diff] [blame] | 157 | |
| 158 | @attr(type='gate') |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 159 | def test_volume_create_get_update_delete_as_clone(self): |
Ken'ichi Ohmichi | 5687d55 | 2013-12-26 19:00:12 +0900 | [diff] [blame] | 160 | origin = self.create_volume() |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 161 | self._volume_create_get_update_delete(source_volid=origin['id']) |
Giulio Fidente | 36836c4 | 2013-04-05 15:43:51 +0200 | [diff] [blame] | 162 | |
Matthew Treinish | 9854d5b | 2012-09-20 10:22:13 -0400 | [diff] [blame] | 163 | |
Attila Fazekas | 3dcdae1 | 2013-02-14 12:50:04 +0100 | [diff] [blame] | 164 | class VolumesGetTestXML(VolumesGetTest): |
| 165 | _interface = "xml" |