blob: 71e9f85c1f863cb007a7f5565402cfc158c68e33 [file] [log] [blame]
wingwjcbd82dc2013-10-22 16:38:39 +08001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 OpenStack Foundation
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
Zhi Kun Liubb363a22013-11-28 18:47:39 +080018from tempest.api.volume import base
wingwjcbd82dc2013-10-22 16:38:39 +080019from tempest import clients
20from tempest.common.utils.data_utils import rand_name
21from tempest.test import attr
22
23
Zhi Kun Liubb363a22013-11-28 18:47:39 +080024class VolumesTransfersTest(base.BaseVolumeV1Test):
wingwjcbd82dc2013-10-22 16:38:39 +080025 _interface = "json"
26
27 @classmethod
28 def setUpClass(cls):
29 super(VolumesTransfersTest, cls).setUpClass()
30
31 # Add another tenant to test volume-transfer
32 if cls.config.compute.allow_tenant_isolation:
33 creds = cls.isolated_creds.get_alt_creds()
34 username, tenant_name, password = creds
35 cls.os_alt = clients.Manager(username=username,
36 password=password,
37 tenant_name=tenant_name,
38 interface=cls._interface)
39 cls.alt_tenant_id = cls.isolated_creds.get_alt_tenant()['id']
40
41 # Add admin tenant to cleanup resources
42 adm_creds = cls.isolated_creds.get_admin_creds()
43 admin_username, admin_tenant_name, admin_password = adm_creds
44 cls.os_adm = clients.Manager(username=admin_username,
45 password=admin_password,
46 tenant_name=admin_tenant_name,
47 interface=cls._interface)
48 else:
49 cls.os_alt = clients.AltManager()
50 alt_tenant_name = cls.os_alt.tenant_name
51 identity_client = cls._get_identity_admin_client()
52 _, tenants = identity_client.list_tenants()
53 cls.alt_tenant_id = [tnt['id'] for tnt in tenants
54 if tnt['name'] == alt_tenant_name][0]
55 cls.os_adm = clients.ComputeAdminManager(interface=cls._interface)
56
57 cls.client = cls.volumes_client
58 cls.alt_client = cls.os_alt.volumes_client
59 cls.adm_client = cls.os_adm.volumes_client
60
61 @attr(type='gate')
62 def test_create_get_list_accept_volume_transfer(self):
63 # Create a volume first
64 vol_name = rand_name('-Volume-')
65 _, volume = self.client.create_volume(size=1, display_name=vol_name)
66 self.addCleanup(self.adm_client.delete_volume, volume['id'])
67 self.client.wait_for_volume_status(volume['id'], 'available')
68
69 # Create a volume transfer
70 resp, transfer = self.client.create_volume_transfer(volume['id'])
71 self.assertEqual(202, resp.status)
72 transfer_id = transfer['id']
73 auth_key = transfer['auth_key']
74 self.client.wait_for_volume_status(volume['id'],
75 'awaiting-transfer')
76
77 # Get a volume transfer
78 resp, body = self.client.get_volume_transfer(transfer_id)
79 self.assertEqual(200, resp.status)
80 self.assertEqual(volume['id'], body['volume_id'])
81
82 # List volume transfers, the result should be greater than
83 # or equal to 1
84 resp, body = self.client.list_volume_transfers()
85 self.assertEqual(200, resp.status)
86 self.assertGreaterEqual(len(body), 1)
87
88 # Accept a volume transfer by alt_tenant
89 resp, body = self.alt_client.accept_volume_transfer(transfer_id,
90 auth_key)
91 self.assertEqual(202, resp.status)
92 self.alt_client.wait_for_volume_status(volume['id'], 'available')
93
94 def test_create_list_delete_volume_transfer(self):
95 # Create a volume first
96 vol_name = rand_name('-Volume-')
97 _, volume = self.client.create_volume(size=1, display_name=vol_name)
98 self.addCleanup(self.adm_client.delete_volume, volume['id'])
99 self.client.wait_for_volume_status(volume['id'], 'available')
100
101 # Create a volume transfer
102 resp, body = self.client.create_volume_transfer(volume['id'])
103 self.assertEqual(202, resp.status)
104 transfer_id = body['id']
105 self.client.wait_for_volume_status(volume['id'],
106 'awaiting-transfer')
107
108 # List all volume transfers, there's only one in this test
109 resp, body = self.client.list_volume_transfers()
110 self.assertEqual(200, resp.status)
111 self.assertEqual(volume['id'], body[0]['volume_id'])
112
113 # Delete a volume transfer
114 resp, body = self.client.delete_volume_transfer(transfer_id)
115 self.assertEqual(202, resp.status)
116 self.client.wait_for_volume_status(volume['id'], 'available')
117
118
119class VolumesTransfersTestXML(VolumesTransfersTest):
120 _interface = "xml"