Matt Riedemann | 342b37c | 2016-09-21 15:38:12 -0400 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | # not use this file except in compliance with the License. You may obtain |
| 3 | # a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | # License for the specific language governing permissions and limitations |
| 11 | # under the License. |
| 12 | |
| 13 | from tempest.api.compute import base |
| 14 | from tempest.common import waiters |
| 15 | from tempest import config |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 16 | from tempest.lib import decorators |
Matt Riedemann | 342b37c | 2016-09-21 15:38:12 -0400 | [diff] [blame] | 17 | from tempest import test |
| 18 | |
| 19 | CONF = config.CONF |
| 20 | |
| 21 | |
| 22 | class TestVolumeSwap(base.BaseV2ComputeAdminTest): |
| 23 | """The test suite for swapping of volume with admin user. |
| 24 | |
| 25 | The following is the scenario outline: |
| 26 | 1. Create a volume "volume1" with non-admin. |
| 27 | 2. Create a volume "volume2" with non-admin. |
| 28 | 3. Boot an instance "instance1" with non-admin. |
| 29 | 4. Attach "volume1" to "instance1" with non-admin. |
| 30 | 5. Swap volume from "volume1" to "volume2" as admin. |
| 31 | 6. Check the swap volume is successful and "volume2" |
| 32 | is attached to "instance1" and "volume1" is in available state. |
| 33 | """ |
| 34 | |
| 35 | @classmethod |
| 36 | def skip_checks(cls): |
| 37 | super(TestVolumeSwap, cls).skip_checks() |
| 38 | if not CONF.compute_feature_enabled.swap_volume: |
| 39 | raise cls.skipException("Swapping volumes is not supported.") |
| 40 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 41 | @decorators.idempotent_id('1769f00d-a693-4d67-a631-6a3496773813') |
Matt Riedemann | 342b37c | 2016-09-21 15:38:12 -0400 | [diff] [blame] | 42 | @test.services('volume') |
| 43 | def test_volume_swap(self): |
| 44 | # Create two volumes. |
| 45 | # NOTE(gmann): Volumes are created before server creation so that |
| 46 | # volumes cleanup can happen successfully irrespective of which volume |
| 47 | # is attached to server. |
| 48 | volume1 = self.create_volume() |
| 49 | volume2 = self.create_volume() |
| 50 | # Boot server |
| 51 | server = self.create_test_server(wait_until='ACTIVE') |
| 52 | # Attach "volume1" to server |
| 53 | self.attach_volume(server, volume1) |
| 54 | # Swap volume from "volume1" to "volume2" |
zhufl | e5b62a6 | 2017-02-15 16:04:21 +0800 | [diff] [blame^] | 55 | self.admin_servers_client.update_attached_volume( |
Matt Riedemann | 342b37c | 2016-09-21 15:38:12 -0400 | [diff] [blame] | 56 | server['id'], volume1['id'], volumeId=volume2['id']) |
| 57 | waiters.wait_for_volume_status(self.volumes_client, |
| 58 | volume1['id'], 'available') |
| 59 | waiters.wait_for_volume_status(self.volumes_client, |
| 60 | volume2['id'], 'in-use') |
| 61 | self.addCleanup(self.servers_client.detach_volume, |
| 62 | server['id'], volume2['id']) |
| 63 | # Verify "volume2" is attached to the server |
| 64 | vol_attachments = self.servers_client.list_volume_attachments( |
| 65 | server['id'])['volumeAttachments'] |
| 66 | self.assertEqual(1, len(vol_attachments)) |
| 67 | self.assertIn(volume2['id'], vol_attachments[0]['volumeId']) |
| 68 | |
| 69 | # TODO(mriedem): Test swapping back from volume2 to volume1 after |
| 70 | # nova bug 1490236 is fixed. |