blob: f11ac2a40b53e4c35128188c588ba86d92685c36 [file] [log] [blame]
Steven Hardyb1f91982014-04-04 15:35:55 +01001# 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
13import logging
14
15from tempest.api.orchestration import base
16from tempest.common.utils import data_utils
17from tempest import config
Steven Hardy8b9fa022014-04-04 17:31:50 +010018from tempest import exceptions
Steven Hardyb1f91982014-04-04 15:35:55 +010019from tempest import test
20
21
22CONF = config.CONF
23LOG = logging.getLogger(__name__)
24
25
26class CinderResourcesTest(base.BaseOrchestrationTest):
27
28 @classmethod
29 def setUpClass(cls):
30 super(CinderResourcesTest, cls).setUpClass()
31 if not CONF.service_available.cinder:
32 raise cls.skipException('Cinder support is required')
33
Ghanshyam961ea1a2014-06-09 10:56:00 +090034 def _cinder_verify(self, volume_id, template):
Steven Hardy8b9fa022014-04-04 17:31:50 +010035 self.assertIsNotNone(volume_id)
36 resp, volume = self.volumes_client.get_volume(volume_id)
37 self.assertEqual(200, resp.status)
38 self.assertEqual('available', volume.get('status'))
Ghanshyam961ea1a2014-06-09 10:56:00 +090039 self.assertEqual(template['resources']['volume']['properties'][
40 'size'], volume.get('size'))
41 self.assertEqual(template['resources']['volume']['properties'][
42 'description'], volume.get('display_description'))
43 self.assertEqual(template['resources']['volume']['properties'][
44 'name'], volume.get('display_name'))
Steven Hardy8b9fa022014-04-04 17:31:50 +010045
Ghanshyam961ea1a2014-06-09 10:56:00 +090046 def _outputs_verify(self, stack_identifier, template):
Steven Hardy8b9fa022014-04-04 17:31:50 +010047 self.assertEqual('available',
48 self.get_stack_output(stack_identifier, 'status'))
Ghanshyam961ea1a2014-06-09 10:56:00 +090049 self.assertEqual(str(template['resources']['volume']['properties'][
50 'size']), self.get_stack_output(stack_identifier, 'size'))
51 self.assertEqual(template['resources']['volume']['properties'][
52 'description'], self.get_stack_output(stack_identifier,
53 'display_description'))
54 self.assertEqual(template['resources']['volume']['properties'][
55 'name'], self.get_stack_output(stack_identifier, 'display_name'))
Steven Hardy8b9fa022014-04-04 17:31:50 +010056
Steven Hardyb1f91982014-04-04 15:35:55 +010057 @test.attr(type='gate')
58 def test_cinder_volume_create_delete(self):
59 """Create and delete a volume via OS::Cinder::Volume."""
60 stack_name = data_utils.rand_name('heat')
Ghanshyam961ea1a2014-06-09 10:56:00 +090061 template = self.read_template('cinder_basic')
Steven Hardyb1f91982014-04-04 15:35:55 +010062 stack_identifier = self.create_stack(stack_name, template)
63 self.client.wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
64
65 # Verify with cinder that the volume exists, with matching details
66 volume_id = self.get_stack_output(stack_identifier, 'volume_id')
Ghanshyam961ea1a2014-06-09 10:56:00 +090067 cinder_basic_template = self.load_template('cinder_basic')
68 self._cinder_verify(volume_id, cinder_basic_template)
Steven Hardyb1f91982014-04-04 15:35:55 +010069
70 # Verify the stack outputs are as expected
Ghanshyam961ea1a2014-06-09 10:56:00 +090071 self._outputs_verify(stack_identifier, cinder_basic_template)
Steven Hardy8b9fa022014-04-04 17:31:50 +010072
73 # Delete the stack and ensure the volume is gone
74 self.client.delete_stack(stack_identifier)
75 self.client.wait_for_stack_status(stack_identifier, 'DELETE_COMPLETE')
76 self.assertRaises(exceptions.NotFound,
77 self.volumes_client.get_volume,
78 volume_id)
79
80 def _cleanup_volume(self, volume_id):
81 """Cleanup the volume direct with cinder."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000082 self.volumes_client.delete_volume(volume_id)
Steven Hardy8b9fa022014-04-04 17:31:50 +010083 self.volumes_client.wait_for_resource_deletion(volume_id)
84
85 @test.attr(type='gate')
86 def test_cinder_volume_create_delete_retain(self):
87 """Ensure the 'Retain' deletion policy is respected."""
88 stack_name = data_utils.rand_name('heat')
Ghanshyam961ea1a2014-06-09 10:56:00 +090089 template = self.read_template('cinder_basic_delete_retain')
Steven Hardy8b9fa022014-04-04 17:31:50 +010090 stack_identifier = self.create_stack(stack_name, template)
91 self.client.wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
92
93 # Verify with cinder that the volume exists, with matching details
94 volume_id = self.get_stack_output(stack_identifier, 'volume_id')
95 self.addCleanup(self._cleanup_volume, volume_id)
Ghanshyam961ea1a2014-06-09 10:56:00 +090096 retain_template = self.load_template('cinder_basic_delete_retain')
97 self._cinder_verify(volume_id, retain_template)
Steven Hardy8b9fa022014-04-04 17:31:50 +010098
99 # Verify the stack outputs are as expected
Ghanshyam961ea1a2014-06-09 10:56:00 +0900100 self._outputs_verify(stack_identifier, retain_template)
Steven Hardy8b9fa022014-04-04 17:31:50 +0100101
102 # Delete the stack and ensure the volume is *not* gone
103 self.client.delete_stack(stack_identifier)
104 self.client.wait_for_stack_status(stack_identifier, 'DELETE_COMPLETE')
Ghanshyam961ea1a2014-06-09 10:56:00 +0900105 self._cinder_verify(volume_id, retain_template)
Steven Hardy8b9fa022014-04-04 17:31:50 +0100106
107 # Volume cleanup happens via addCleanup calling _cleanup_volume