blob: 1ef93b9440405e12c7298b906d207b6775aff991 [file] [log] [blame]
wingwjcbd82dc2013-10-22 16:38:39 +08001# Copyright 2013 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 Riedemann1c42d6b2014-02-07 18:30:35 -080016from testtools import matchers
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
Matthew Treinish4d352bc2014-01-29 18:29:18 +000020from tempest import config
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090021from tempest import test
wingwjcbd82dc2013-10-22 16:38:39 +080022
Matthew Treinish4d352bc2014-01-29 18:29:18 +000023CONF = config.CONF
24
wingwjcbd82dc2013-10-22 16:38:39 +080025
Zhi Kun Liubb363a22013-11-28 18:47:39 +080026class VolumesTransfersTest(base.BaseVolumeV1Test):
wingwjcbd82dc2013-10-22 16:38:39 +080027 _interface = "json"
28
29 @classmethod
30 def setUpClass(cls):
31 super(VolumesTransfersTest, cls).setUpClass()
32
33 # Add another tenant to test volume-transfer
Matthew Treinish4d352bc2014-01-29 18:29:18 +000034 if CONF.compute.allow_tenant_isolation:
Andrea Frittoli422fbdf2014-03-20 10:05:18 +000035 cls.os_alt = clients.Manager(cls.isolated_creds.get_alt_creds(),
wingwjcbd82dc2013-10-22 16:38:39 +080036 interface=cls._interface)
37 cls.alt_tenant_id = cls.isolated_creds.get_alt_tenant()['id']
wingwjcbd82dc2013-10-22 16:38:39 +080038 # Add admin tenant to cleanup resources
Andrea Frittoli422fbdf2014-03-20 10:05:18 +000039 cls.os_adm = clients.Manager(cls.isolated_creds.get_admin_creds(),
wingwjcbd82dc2013-10-22 16:38:39 +080040 interface=cls._interface)
Andrea Frittoli422fbdf2014-03-20 10:05:18 +000041
wingwjcbd82dc2013-10-22 16:38:39 +080042 else:
43 cls.os_alt = clients.AltManager()
Matthew Treinish318f1772014-02-07 19:53:29 -050044 alt_tenant_name = cls.os_alt.credentials['tenant_name']
wingwjcbd82dc2013-10-22 16:38:39 +080045 identity_client = cls._get_identity_admin_client()
46 _, tenants = identity_client.list_tenants()
47 cls.alt_tenant_id = [tnt['id'] for tnt in tenants
48 if tnt['name'] == alt_tenant_name][0]
49 cls.os_adm = clients.ComputeAdminManager(interface=cls._interface)
50
51 cls.client = cls.volumes_client
52 cls.alt_client = cls.os_alt.volumes_client
53 cls.adm_client = cls.os_adm.volumes_client
54
John Griffith7050f132014-01-24 14:10:09 -070055 def _delete_volume(self, volume_id):
56 # Delete the specified volume using admin creds
57 resp, _ = self.adm_client.delete_volume(volume_id)
58 self.assertEqual(202, resp.status)
59 self.adm_client.wait_for_resource_deletion(volume_id)
60
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090061 @test.attr(type='gate')
wingwjcbd82dc2013-10-22 16:38:39 +080062 def test_create_get_list_accept_volume_transfer(self):
63 # Create a volume first
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090064 volume = self.create_volume()
John Griffith7050f132014-01-24 14:10:09 -070065 self.addCleanup(self._delete_volume, volume['id'])
wingwjcbd82dc2013-10-22 16:38:39 +080066
67 # Create a volume transfer
68 resp, transfer = self.client.create_volume_transfer(volume['id'])
69 self.assertEqual(202, resp.status)
70 transfer_id = transfer['id']
71 auth_key = transfer['auth_key']
72 self.client.wait_for_volume_status(volume['id'],
73 'awaiting-transfer')
74
75 # Get a volume transfer
76 resp, body = self.client.get_volume_transfer(transfer_id)
77 self.assertEqual(200, resp.status)
78 self.assertEqual(volume['id'], body['volume_id'])
79
80 # List volume transfers, the result should be greater than
81 # or equal to 1
82 resp, body = self.client.list_volume_transfers()
83 self.assertEqual(200, resp.status)
Matt Riedemann1c42d6b2014-02-07 18:30:35 -080084 self.assertThat(len(body), matchers.GreaterThan(0))
wingwjcbd82dc2013-10-22 16:38:39 +080085
86 # Accept a volume transfer by alt_tenant
87 resp, body = self.alt_client.accept_volume_transfer(transfer_id,
88 auth_key)
89 self.assertEqual(202, resp.status)
90 self.alt_client.wait_for_volume_status(volume['id'], 'available')
91
92 def test_create_list_delete_volume_transfer(self):
93 # Create a volume first
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090094 volume = self.create_volume()
John Griffith7050f132014-01-24 14:10:09 -070095 self.addCleanup(self._delete_volume, volume['id'])
wingwjcbd82dc2013-10-22 16:38:39 +080096
97 # Create a volume transfer
98 resp, body = self.client.create_volume_transfer(volume['id'])
99 self.assertEqual(202, resp.status)
100 transfer_id = body['id']
101 self.client.wait_for_volume_status(volume['id'],
102 'awaiting-transfer')
103
Matt Riedemann1f391f82014-02-09 11:04:04 -0800104 # List all volume transfers (looking for the one we created)
wingwjcbd82dc2013-10-22 16:38:39 +0800105 resp, body = self.client.list_volume_transfers()
106 self.assertEqual(200, resp.status)
Matt Riedemann1f391f82014-02-09 11:04:04 -0800107 for transfer in body:
108 if volume['id'] == transfer['volume_id']:
109 break
110 else:
111 self.fail('Transfer not found for volume %s' % volume['id'])
wingwjcbd82dc2013-10-22 16:38:39 +0800112
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"