Attila Fazekas | 9fa2947 | 2014-08-18 09:48:00 +0200 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
| 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 | |
Matt Riedemann | 0cc76bf | 2017-07-05 17:29:31 -0400 | [diff] [blame] | 16 | import time |
| 17 | |
Jordan Pittier | 1189dd1 | 2015-07-09 16:03:56 +0200 | [diff] [blame] | 18 | import testtools |
| 19 | |
Attila Fazekas | 9fa2947 | 2014-08-18 09:48:00 +0200 | [diff] [blame] | 20 | from tempest.api.volume import base |
lkuchlan | b599242 | 2017-11-26 16:49:18 +0200 | [diff] [blame] | 21 | from tempest.common import utils |
Yaroslav Lobankov | ed3a35b | 2016-03-24 22:41:30 -0500 | [diff] [blame] | 22 | from tempest.common import waiters |
Jordan Pittier | 1189dd1 | 2015-07-09 16:03:56 +0200 | [diff] [blame] | 23 | from tempest import config |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 24 | from tempest.lib import decorators |
Matt Riedemann | 0cc76bf | 2017-07-05 17:29:31 -0400 | [diff] [blame] | 25 | from tempest.lib import exceptions as lib_exc |
Attila Fazekas | 9fa2947 | 2014-08-18 09:48:00 +0200 | [diff] [blame] | 26 | |
Jordan Pittier | 1189dd1 | 2015-07-09 16:03:56 +0200 | [diff] [blame] | 27 | CONF = config.CONF |
| 28 | |
Attila Fazekas | 9fa2947 | 2014-08-18 09:48:00 +0200 | [diff] [blame] | 29 | |
Ken'ichi Ohmichi | e8afb8c | 2017-03-27 11:25:37 -0700 | [diff] [blame] | 30 | class VolumesExtendTest(base.BaseVolumeTest): |
zhufl | 3fdd35a | 2020-04-16 16:29:47 +0800 | [diff] [blame] | 31 | """Test volume extend""" |
Attila Fazekas | 9fa2947 | 2014-08-18 09:48:00 +0200 | [diff] [blame] | 32 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 33 | @decorators.idempotent_id('9a36df71-a257-43a5-9555-dc7c88e66e0e') |
Attila Fazekas | 9fa2947 | 2014-08-18 09:48:00 +0200 | [diff] [blame] | 34 | def test_volume_extend(self): |
zhufl | 3fdd35a | 2020-04-16 16:29:47 +0800 | [diff] [blame] | 35 | """Test extend a volume""" |
Attila Fazekas | 9fa2947 | 2014-08-18 09:48:00 +0200 | [diff] [blame] | 36 | # Extend Volume Test. |
zhufl | 8802c83 | 2019-06-03 09:31:36 +0800 | [diff] [blame] | 37 | volume = self.create_volume(imageRef=self.image_ref) |
TommyLike | fcda77b | 2018-01-18 15:25:12 +0800 | [diff] [blame] | 38 | extend_size = volume['size'] * 2 |
zhufl | 7a8f29d | 2017-02-17 10:16:45 +0800 | [diff] [blame] | 39 | self.volumes_client.extend_volume(volume['id'], |
lkuchlan | b21fc57 | 2016-11-28 12:25:22 +0200 | [diff] [blame] | 40 | new_size=extend_size) |
lkuchlan | 52d7b0d | 2016-11-07 20:53:19 +0200 | [diff] [blame] | 41 | waiters.wait_for_volume_resource_status(self.volumes_client, |
| 42 | volume['id'], 'available') |
zhufl | 7a8f29d | 2017-02-17 10:16:45 +0800 | [diff] [blame] | 43 | volume = self.volumes_client.show_volume(volume['id'])['volume'] |
Avi Avraham | d77d3d1 | 2017-02-15 16:45:25 +0200 | [diff] [blame] | 44 | self.assertEqual(volume['size'], extend_size) |
Jordan Pittier | 1189dd1 | 2015-07-09 16:03:56 +0200 | [diff] [blame] | 45 | |
| 46 | @decorators.idempotent_id('86be1cba-2640-11e5-9c82-635fb964c912') |
| 47 | @testtools.skipUnless(CONF.volume_feature_enabled.snapshot, |
| 48 | "Cinder volume snapshots are disabled") |
| 49 | def test_volume_extend_when_volume_has_snapshot(self): |
zhufl | 3fdd35a | 2020-04-16 16:29:47 +0800 | [diff] [blame] | 50 | """Test extending a volume which has a snapshot""" |
Jordan Pittier | 1189dd1 | 2015-07-09 16:03:56 +0200 | [diff] [blame] | 51 | volume = self.create_volume() |
| 52 | self.create_snapshot(volume['id']) |
| 53 | |
TommyLike | fcda77b | 2018-01-18 15:25:12 +0800 | [diff] [blame] | 54 | extend_size = volume['size'] * 2 |
Jordan Pittier | 1189dd1 | 2015-07-09 16:03:56 +0200 | [diff] [blame] | 55 | self.volumes_client.extend_volume(volume['id'], new_size=extend_size) |
| 56 | |
| 57 | waiters.wait_for_volume_resource_status(self.volumes_client, |
| 58 | volume['id'], 'available') |
| 59 | resized_volume = self.volumes_client.show_volume( |
| 60 | volume['id'])['volume'] |
| 61 | self.assertEqual(extend_size, resized_volume['size']) |
Matt Riedemann | 0cc76bf | 2017-07-05 17:29:31 -0400 | [diff] [blame] | 62 | |
| 63 | |
Lee Yarwood | 4bd9edb | 2020-01-31 17:26:25 +0000 | [diff] [blame] | 64 | class BaseVolumesExtendAttachedTest(base.BaseVolumeTest): |
Matt Riedemann | 0cc76bf | 2017-07-05 17:29:31 -0400 | [diff] [blame] | 65 | """Tests extending the size of an attached volume.""" |
Ghanshyam Mann | 7d91b69 | 2020-03-03 10:21:50 -0600 | [diff] [blame] | 66 | create_default_network = True |
Matt Riedemann | 0cc76bf | 2017-07-05 17:29:31 -0400 | [diff] [blame] | 67 | |
| 68 | # We need admin credentials for getting instance action event details. By |
| 69 | # default a non-admin can list and show instance actions if they own the |
| 70 | # server instance, but since the event details can contain error messages |
| 71 | # and tracebacks, like an instance fault, those are not viewable by |
| 72 | # non-admins. This is obviously not a great user experience since the user |
| 73 | # may not know when the operation is actually complete. A microversion in |
| 74 | # the compute API will be added so that non-admins can see instance action |
| 75 | # events but will continue to hide the traceback field. |
| 76 | # TODO(mriedem): Change this to not rely on the admin user to get the event |
| 77 | # details once that microversion is available in Nova. |
| 78 | credentials = ['primary', 'admin'] |
| 79 | |
Matt Riedemann | 0cc76bf | 2017-07-05 17:29:31 -0400 | [diff] [blame] | 80 | # NOTE(mriedem): The minimum required volume API version is 3.42 and the |
| 81 | # minimum required compute API microversion is 2.51, but the compute call |
| 82 | # is implicit - Cinder calls Nova at that microversion, Tempest does not. |
Sophie Huang | d458bf3 | 2021-10-12 17:08:41 +0000 | [diff] [blame] | 83 | volume_min_microversion = '3.42' |
Matt Riedemann | 0cc76bf | 2017-07-05 17:29:31 -0400 | [diff] [blame] | 84 | |
Matt Riedemann | 0cc76bf | 2017-07-05 17:29:31 -0400 | [diff] [blame] | 85 | def _find_extend_volume_instance_action(self, server_id): |
| 86 | actions = self.servers_client.list_instance_actions( |
| 87 | server_id)['instanceActions'] |
| 88 | for action in actions: |
| 89 | if action['action'] == 'extend_volume': |
| 90 | return action |
| 91 | |
| 92 | def _find_extend_volume_instance_action_finish_event(self, action): |
| 93 | # This has to be called by an admin client otherwise |
| 94 | # the events don't show up. |
rchouhan | 25bf8ce | 2018-01-29 17:39:36 +0530 | [diff] [blame] | 95 | action = self.os_admin.servers_client.show_instance_action( |
Matt Riedemann | 0cc76bf | 2017-07-05 17:29:31 -0400 | [diff] [blame] | 96 | action['instance_uuid'], action['request_id'])['instanceAction'] |
| 97 | for event in action['events']: |
| 98 | if (event['event'] == 'compute_extend_volume' and |
| 99 | event['finish_time']): |
| 100 | return event |
| 101 | |
Lee Yarwood | 4bd9edb | 2020-01-31 17:26:25 +0000 | [diff] [blame] | 102 | def _test_extend_attached_volume(self, volume): |
Matt Riedemann | 0cc76bf | 2017-07-05 17:29:31 -0400 | [diff] [blame] | 103 | """This is a happy path test which does the following: |
| 104 | |
Matt Riedemann | 0cc76bf | 2017-07-05 17:29:31 -0400 | [diff] [blame] | 105 | * Create a server instance. |
| 106 | * Attach the volume to the server. |
| 107 | * Wait for the volume status to be "in-use". |
| 108 | * Extend the size of the volume and wait for the volume status to go |
| 109 | back to "in-use". |
| 110 | * Assert the volume size change is reflected in the volume API. |
| 111 | * Wait for the "compute_extend_volume" instance action event to show |
| 112 | up in the compute API with the success or failure status. We fail |
| 113 | if we timeout waiting for the instance action event to show up, or |
| 114 | if the action on the server fails. |
| 115 | """ |
Matt Riedemann | 0cc76bf | 2017-07-05 17:29:31 -0400 | [diff] [blame] | 116 | # Create a test server. Will be automatically cleaned up on teardown. |
| 117 | server = self.create_server() |
| 118 | # Attach the volume to the server and wait for the volume status to be |
| 119 | # "in-use". |
| 120 | self.attach_volume(server['id'], volume['id']) |
| 121 | # Extend the size of the volume. If this is successful, the volume API |
| 122 | # will change the status on the volume to "extending" before doing an |
| 123 | # RPC cast to the volume manager on the backend. Note that we multiply |
| 124 | # the size of the volume since certain Cinder backends, e.g. ScaleIO, |
| 125 | # require multiples of 8GB. |
| 126 | extend_size = volume['size'] * 2 |
| 127 | self.volumes_client.extend_volume(volume['id'], new_size=extend_size) |
| 128 | # The volume status should go back to in-use since it is still attached |
| 129 | # to the server instance. |
| 130 | waiters.wait_for_volume_resource_status(self.volumes_client, |
| 131 | volume['id'], 'in-use') |
| 132 | # Assert that the volume size has changed in the volume API. |
| 133 | volume = self.volumes_client.show_volume(volume['id'])['volume'] |
| 134 | self.assertEqual(extend_size, volume['size']) |
| 135 | # Now we wait for the "compute_extend_volume" instance action event |
| 136 | # to show up for the server instance. This is our indication that the |
| 137 | # asynchronous operation is complete on the compute side. |
| 138 | start_time = int(time.time()) |
| 139 | timeout = self.servers_client.build_timeout |
| 140 | action = self._find_extend_volume_instance_action(server['id']) |
| 141 | while action is None and int(time.time()) - start_time < timeout: |
| 142 | time.sleep(self.servers_client.build_interval) |
| 143 | action = self._find_extend_volume_instance_action(server['id']) |
| 144 | |
| 145 | if action is None: |
| 146 | msg = ("Timed out waiting to get 'extend_volume' instance action " |
| 147 | "record for server %(server)s after %(timeout)s seconds." % |
| 148 | {'server': server['id'], 'timeout': timeout}) |
| 149 | raise lib_exc.TimeoutException(msg) |
| 150 | |
| 151 | # Now that we found the extend_volume instance action, we can wait for |
| 152 | # the compute_extend_volume instance action event to show up to |
| 153 | # indicate the operation is complete. |
| 154 | start_time = int(time.time()) |
| 155 | event = self._find_extend_volume_instance_action_finish_event(action) |
| 156 | while event is None and int(time.time()) - start_time < timeout: |
| 157 | time.sleep(self.servers_client.build_interval) |
| 158 | event = self._find_extend_volume_instance_action_finish_event( |
| 159 | action) |
| 160 | |
| 161 | if event is None: |
| 162 | msg = ("Timed out waiting to get 'compute_extend_volume' instance " |
| 163 | "action event record for server %(server)s and request " |
| 164 | "%(request_id)s after %(timeout)s seconds." % |
| 165 | {'server': server['id'], |
| 166 | 'request_id': action['request_id'], |
| 167 | 'timeout': timeout}) |
| 168 | raise lib_exc.TimeoutException(msg) |
| 169 | |
| 170 | # Finally, assert that the action completed successfully. |
| 171 | self.assertTrue( |
| 172 | event['result'].lower() == 'success', |
| 173 | "Unexpected compute_extend_volume result '%(result)s' for request " |
| 174 | "%(request_id)s." % |
| 175 | {'result': event['result'], |
| 176 | 'request_id': action['request_id']}) |
Lee Yarwood | 4bd9edb | 2020-01-31 17:26:25 +0000 | [diff] [blame] | 177 | |
| 178 | |
| 179 | class VolumesExtendAttachedTest(BaseVolumesExtendAttachedTest): |
| 180 | |
| 181 | @decorators.idempotent_id('301f5a30-1c6f-4ea0-be1a-91fd28d44354') |
| 182 | @testtools.skipUnless(CONF.volume_feature_enabled.extend_attached_volume, |
| 183 | "Attached volume extend is disabled.") |
| 184 | @utils.services('compute') |
| 185 | def test_extend_attached_volume(self): |
| 186 | volume = self.create_volume() |
| 187 | self._test_extend_attached_volume(volume) |