blob: 83003b34844795786ca77e1e7c971f6ea133b1be [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
wingwjcbd82dc2013-10-22 16:38:39 +080021from tempest.test import attr
22
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:
wingwjcbd82dc2013-10-22 16:38:39 +080035 creds = cls.isolated_creds.get_alt_creds()
36 username, tenant_name, password = creds
37 cls.os_alt = clients.Manager(username=username,
38 password=password,
39 tenant_name=tenant_name,
40 interface=cls._interface)
41 cls.alt_tenant_id = cls.isolated_creds.get_alt_tenant()['id']
42
43 # Add admin tenant to cleanup resources
44 adm_creds = cls.isolated_creds.get_admin_creds()
45 admin_username, admin_tenant_name, admin_password = adm_creds
46 cls.os_adm = clients.Manager(username=admin_username,
47 password=admin_password,
48 tenant_name=admin_tenant_name,
49 interface=cls._interface)
50 else:
51 cls.os_alt = clients.AltManager()
52 alt_tenant_name = cls.os_alt.tenant_name
53 identity_client = cls._get_identity_admin_client()
54 _, tenants = identity_client.list_tenants()
55 cls.alt_tenant_id = [tnt['id'] for tnt in tenants
56 if tnt['name'] == alt_tenant_name][0]
57 cls.os_adm = clients.ComputeAdminManager(interface=cls._interface)
58
59 cls.client = cls.volumes_client
60 cls.alt_client = cls.os_alt.volumes_client
61 cls.adm_client = cls.os_adm.volumes_client
62
John Griffith7050f132014-01-24 14:10:09 -070063 def _delete_volume(self, volume_id):
64 # Delete the specified volume using admin creds
65 resp, _ = self.adm_client.delete_volume(volume_id)
66 self.assertEqual(202, resp.status)
67 self.adm_client.wait_for_resource_deletion(volume_id)
68
wingwjcbd82dc2013-10-22 16:38:39 +080069 @attr(type='gate')
70 def test_create_get_list_accept_volume_transfer(self):
71 # Create a volume first
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090072 volume = self.create_volume()
John Griffith7050f132014-01-24 14:10:09 -070073 self.addCleanup(self._delete_volume, volume['id'])
wingwjcbd82dc2013-10-22 16:38:39 +080074
75 # Create a volume transfer
76 resp, transfer = self.client.create_volume_transfer(volume['id'])
77 self.assertEqual(202, resp.status)
78 transfer_id = transfer['id']
79 auth_key = transfer['auth_key']
80 self.client.wait_for_volume_status(volume['id'],
81 'awaiting-transfer')
82
83 # Get a volume transfer
84 resp, body = self.client.get_volume_transfer(transfer_id)
85 self.assertEqual(200, resp.status)
86 self.assertEqual(volume['id'], body['volume_id'])
87
88 # List volume transfers, the result should be greater than
89 # or equal to 1
90 resp, body = self.client.list_volume_transfers()
91 self.assertEqual(200, resp.status)
Matt Riedemann1c42d6b2014-02-07 18:30:35 -080092 self.assertThat(len(body), matchers.GreaterThan(0))
wingwjcbd82dc2013-10-22 16:38:39 +080093
94 # Accept a volume transfer by alt_tenant
95 resp, body = self.alt_client.accept_volume_transfer(transfer_id,
96 auth_key)
97 self.assertEqual(202, resp.status)
98 self.alt_client.wait_for_volume_status(volume['id'], 'available')
99
100 def test_create_list_delete_volume_transfer(self):
101 # Create a volume first
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +0900102 volume = self.create_volume()
John Griffith7050f132014-01-24 14:10:09 -0700103 self.addCleanup(self._delete_volume, volume['id'])
wingwjcbd82dc2013-10-22 16:38:39 +0800104
105 # Create a volume transfer
106 resp, body = self.client.create_volume_transfer(volume['id'])
107 self.assertEqual(202, resp.status)
108 transfer_id = body['id']
109 self.client.wait_for_volume_status(volume['id'],
110 'awaiting-transfer')
111
112 # List all volume transfers, there's only one in this test
113 resp, body = self.client.list_volume_transfers()
114 self.assertEqual(200, resp.status)
115 self.assertEqual(volume['id'], body[0]['volume_id'])
116
117 # Delete a volume transfer
118 resp, body = self.client.delete_volume_transfer(transfer_id)
119 self.assertEqual(202, resp.status)
120 self.client.wait_for_volume_status(volume['id'], 'available')
121
122
123class VolumesTransfersTestXML(VolumesTransfersTest):
124 _interface = "xml"