blob: 34eab003222ec8df004d041e3fcacc1e67bf19b8 [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
wingwjcbd82dc2013-10-22 16:38:39 +080020from tempest.test import attr
21
22
Zhi Kun Liubb363a22013-11-28 18:47:39 +080023class VolumesTransfersTest(base.BaseVolumeV1Test):
wingwjcbd82dc2013-10-22 16:38:39 +080024 _interface = "json"
25
26 @classmethod
27 def setUpClass(cls):
28 super(VolumesTransfersTest, cls).setUpClass()
29
30 # Add another tenant to test volume-transfer
31 if cls.config.compute.allow_tenant_isolation:
32 creds = cls.isolated_creds.get_alt_creds()
33 username, tenant_name, password = creds
34 cls.os_alt = clients.Manager(username=username,
35 password=password,
36 tenant_name=tenant_name,
37 interface=cls._interface)
38 cls.alt_tenant_id = cls.isolated_creds.get_alt_tenant()['id']
39
40 # Add admin tenant to cleanup resources
41 adm_creds = cls.isolated_creds.get_admin_creds()
42 admin_username, admin_tenant_name, admin_password = adm_creds
43 cls.os_adm = clients.Manager(username=admin_username,
44 password=admin_password,
45 tenant_name=admin_tenant_name,
46 interface=cls._interface)
47 else:
48 cls.os_alt = clients.AltManager()
49 alt_tenant_name = cls.os_alt.tenant_name
50 identity_client = cls._get_identity_admin_client()
51 _, tenants = identity_client.list_tenants()
52 cls.alt_tenant_id = [tnt['id'] for tnt in tenants
53 if tnt['name'] == alt_tenant_name][0]
54 cls.os_adm = clients.ComputeAdminManager(interface=cls._interface)
55
56 cls.client = cls.volumes_client
57 cls.alt_client = cls.os_alt.volumes_client
58 cls.adm_client = cls.os_adm.volumes_client
59
60 @attr(type='gate')
61 def test_create_get_list_accept_volume_transfer(self):
62 # Create a volume first
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090063 volume = self.create_volume()
wingwjcbd82dc2013-10-22 16:38:39 +080064
65 # Create a volume transfer
66 resp, transfer = self.client.create_volume_transfer(volume['id'])
67 self.assertEqual(202, resp.status)
68 transfer_id = transfer['id']
69 auth_key = transfer['auth_key']
70 self.client.wait_for_volume_status(volume['id'],
71 'awaiting-transfer')
72
73 # Get a volume transfer
74 resp, body = self.client.get_volume_transfer(transfer_id)
75 self.assertEqual(200, resp.status)
76 self.assertEqual(volume['id'], body['volume_id'])
77
78 # List volume transfers, the result should be greater than
79 # or equal to 1
80 resp, body = self.client.list_volume_transfers()
81 self.assertEqual(200, resp.status)
82 self.assertGreaterEqual(len(body), 1)
83
84 # Accept a volume transfer by alt_tenant
85 resp, body = self.alt_client.accept_volume_transfer(transfer_id,
86 auth_key)
87 self.assertEqual(202, resp.status)
88 self.alt_client.wait_for_volume_status(volume['id'], 'available')
89
90 def test_create_list_delete_volume_transfer(self):
91 # Create a volume first
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090092 volume = self.create_volume()
wingwjcbd82dc2013-10-22 16:38:39 +080093
94 # Create a volume transfer
95 resp, body = self.client.create_volume_transfer(volume['id'])
96 self.assertEqual(202, resp.status)
97 transfer_id = body['id']
98 self.client.wait_for_volume_status(volume['id'],
99 'awaiting-transfer')
100
101 # List all volume transfers, there's only one in this test
102 resp, body = self.client.list_volume_transfers()
103 self.assertEqual(200, resp.status)
104 self.assertEqual(volume['id'], body[0]['volume_id'])
105
106 # Delete a volume transfer
107 resp, body = self.client.delete_volume_transfer(transfer_id)
108 self.assertEqual(202, resp.status)
109 self.client.wait_for_volume_status(volume['id'], 'available')
110
111
112class VolumesTransfersTestXML(VolumesTransfersTest):
113 _interface = "xml"