blob: f603abd9afba79c29b34d5f0795fc3b722d0058c [file] [log] [blame]
Matt Riedemann342b37c2016-09-21 15:38:12 -04001# 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
13from tempest.api.compute import base
14from tempest.common import waiters
15from tempest import config
16from tempest import test
17
18CONF = config.CONF
19
20
21class TestVolumeSwap(base.BaseV2ComputeAdminTest):
22 """The test suite for swapping of volume with admin user.
23
24 The following is the scenario outline:
25 1. Create a volume "volume1" with non-admin.
26 2. Create a volume "volume2" with non-admin.
27 3. Boot an instance "instance1" with non-admin.
28 4. Attach "volume1" to "instance1" with non-admin.
29 5. Swap volume from "volume1" to "volume2" as admin.
30 6. Check the swap volume is successful and "volume2"
31 is attached to "instance1" and "volume1" is in available state.
32 """
33
34 @classmethod
35 def skip_checks(cls):
36 super(TestVolumeSwap, cls).skip_checks()
37 if not CONF.compute_feature_enabled.swap_volume:
38 raise cls.skipException("Swapping volumes is not supported.")
39
40 @classmethod
41 def setup_clients(cls):
42 super(TestVolumeSwap, cls).setup_clients()
43 # We need the admin client for performing the update (swap) volume call
44 cls.servers_admin_client = cls.os_adm.servers_client
45
46 @test.idempotent_id('1769f00d-a693-4d67-a631-6a3496773813')
47 @test.services('volume')
48 def test_volume_swap(self):
49 # Create two volumes.
50 # NOTE(gmann): Volumes are created before server creation so that
51 # volumes cleanup can happen successfully irrespective of which volume
52 # is attached to server.
53 volume1 = self.create_volume()
54 volume2 = self.create_volume()
55 # Boot server
56 server = self.create_test_server(wait_until='ACTIVE')
57 # Attach "volume1" to server
58 self.attach_volume(server, volume1)
59 # Swap volume from "volume1" to "volume2"
60 self.servers_admin_client.update_attached_volume(
61 server['id'], volume1['id'], volumeId=volume2['id'])
62 waiters.wait_for_volume_status(self.volumes_client,
63 volume1['id'], 'available')
64 waiters.wait_for_volume_status(self.volumes_client,
65 volume2['id'], 'in-use')
66 self.addCleanup(self.servers_client.detach_volume,
67 server['id'], volume2['id'])
68 # Verify "volume2" is attached to the server
69 vol_attachments = self.servers_client.list_volume_attachments(
70 server['id'])['volumeAttachments']
71 self.assertEqual(1, len(vol_attachments))
72 self.assertIn(volume2['id'], vol_attachments[0]['volumeId'])
73
74 # TODO(mriedem): Test swapping back from volume2 to volume1 after
75 # nova bug 1490236 is fixed.