blob: d34eb897ff0decb81e5e18058a61f4f59efb6dfb [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
Steven Hardyb1f91982014-04-04 15:35:55 +010013from tempest.api.orchestration import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120014from tempest.common.utils import data_utils
Steven Hardyb1f91982014-04-04 15:35:55 +010015from tempest import config
Ken'ichi Ohmichi835a9452017-01-27 18:17:07 -080016from tempest.lib import decorators
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050017from tempest.lib import exceptions as lib_exc
Steven Hardyb1f91982014-04-04 15:35:55 +010018from tempest import test
19
20
21CONF = config.CONF
Steven Hardyb1f91982014-04-04 15:35:55 +010022
23
24class CinderResourcesTest(base.BaseOrchestrationTest):
25
26 @classmethod
Rohan Kanade80b938a2015-02-07 10:58:56 +053027 def skip_checks(cls):
28 super(CinderResourcesTest, cls).skip_checks()
Steven Hardyb1f91982014-04-04 15:35:55 +010029 if not CONF.service_available.cinder:
30 raise cls.skipException('Cinder support is required')
31
Ghanshyam961ea1a2014-06-09 10:56:00 +090032 def _cinder_verify(self, volume_id, template):
Steven Hardy8b9fa022014-04-04 17:31:50 +010033 self.assertIsNotNone(volume_id)
John Warren6177c9e2015-08-19 20:00:17 +000034 volume = self.volumes_client.show_volume(volume_id)['volume']
Steven Hardy8b9fa022014-04-04 17:31:50 +010035 self.assertEqual('available', volume.get('status'))
Mark Vanderwiel1c940842016-03-03 13:57:33 -060036 self.assertEqual(CONF.volume.volume_size, volume.get('size'))
Rabi Mishrae42bfe42015-09-29 18:02:13 +053037
38 # Some volume properties have been renamed with Cinder v2
39 if CONF.volume_feature_enabled.api_v2:
40 description_field = 'description'
41 name_field = 'name'
42 else:
43 description_field = 'display_description'
44 name_field = 'display_name'
45
Ghanshyam961ea1a2014-06-09 10:56:00 +090046 self.assertEqual(template['resources']['volume']['properties'][
Rabi Mishrae42bfe42015-09-29 18:02:13 +053047 'description'], volume.get(description_field))
Ghanshyam961ea1a2014-06-09 10:56:00 +090048 self.assertEqual(template['resources']['volume']['properties'][
Rabi Mishrae42bfe42015-09-29 18:02:13 +053049 'name'], volume.get(name_field))
Steven Hardy8b9fa022014-04-04 17:31:50 +010050
Ghanshyam961ea1a2014-06-09 10:56:00 +090051 def _outputs_verify(self, stack_identifier, template):
Steven Hardy8b9fa022014-04-04 17:31:50 +010052 self.assertEqual('available',
53 self.get_stack_output(stack_identifier, 'status'))
Mark Vanderwiel1c940842016-03-03 13:57:33 -060054 self.assertEqual(str(CONF.volume.volume_size),
55 self.get_stack_output(stack_identifier, 'size'))
Ghanshyam961ea1a2014-06-09 10:56:00 +090056 self.assertEqual(template['resources']['volume']['properties'][
57 'description'], self.get_stack_output(stack_identifier,
58 'display_description'))
59 self.assertEqual(template['resources']['volume']['properties'][
60 'name'], self.get_stack_output(stack_identifier, 'display_name'))
Steven Hardy8b9fa022014-04-04 17:31:50 +010061
Ken'ichi Ohmichi835a9452017-01-27 18:17:07 -080062 @decorators.idempotent_id('c3243329-7bdd-4730-b402-4d19d50c41d8')
ekhugen16d5dd92014-07-29 18:54:36 +000063 @test.services('volume')
Steven Hardyb1f91982014-04-04 15:35:55 +010064 def test_cinder_volume_create_delete(self):
65 """Create and delete a volume via OS::Cinder::Volume."""
66 stack_name = data_utils.rand_name('heat')
Ghanshyam961ea1a2014-06-09 10:56:00 +090067 template = self.read_template('cinder_basic')
Mark Vanderwiel1c940842016-03-03 13:57:33 -060068 stack_identifier = self.create_stack(
69 stack_name,
70 template,
71 parameters={
72 'volume_size': CONF.volume.volume_size
73 })
Steven Hardyb1f91982014-04-04 15:35:55 +010074 self.client.wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
75
76 # Verify with cinder that the volume exists, with matching details
77 volume_id = self.get_stack_output(stack_identifier, 'volume_id')
Ghanshyam961ea1a2014-06-09 10:56:00 +090078 cinder_basic_template = self.load_template('cinder_basic')
79 self._cinder_verify(volume_id, cinder_basic_template)
Steven Hardyb1f91982014-04-04 15:35:55 +010080
81 # Verify the stack outputs are as expected
Ghanshyam961ea1a2014-06-09 10:56:00 +090082 self._outputs_verify(stack_identifier, cinder_basic_template)
Steven Hardy8b9fa022014-04-04 17:31:50 +010083
84 # Delete the stack and ensure the volume is gone
85 self.client.delete_stack(stack_identifier)
86 self.client.wait_for_stack_status(stack_identifier, 'DELETE_COMPLETE')
Masayuki Igawabfa07602015-01-20 18:47:17 +090087 self.assertRaises(lib_exc.NotFound,
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000088 self.volumes_client.show_volume,
Steven Hardy8b9fa022014-04-04 17:31:50 +010089 volume_id)
90
91 def _cleanup_volume(self, volume_id):
92 """Cleanup the volume direct with cinder."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000093 self.volumes_client.delete_volume(volume_id)
Steven Hardy8b9fa022014-04-04 17:31:50 +010094 self.volumes_client.wait_for_resource_deletion(volume_id)
95
Ken'ichi Ohmichi835a9452017-01-27 18:17:07 -080096 @decorators.idempotent_id('ea8b3a46-b932-4c18-907a-fe23f00b33f8')
ekhugen16d5dd92014-07-29 18:54:36 +000097 @test.services('volume')
Steven Hardy8b9fa022014-04-04 17:31:50 +010098 def test_cinder_volume_create_delete_retain(self):
99 """Ensure the 'Retain' deletion policy is respected."""
100 stack_name = data_utils.rand_name('heat')
Ghanshyam961ea1a2014-06-09 10:56:00 +0900101 template = self.read_template('cinder_basic_delete_retain')
Mark Vanderwiel1c940842016-03-03 13:57:33 -0600102 stack_identifier = self.create_stack(
103 stack_name,
104 template,
105 parameters={
106 'volume_size': CONF.volume.volume_size
107 })
Steven Hardy8b9fa022014-04-04 17:31:50 +0100108 self.client.wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
109
110 # Verify with cinder that the volume exists, with matching details
111 volume_id = self.get_stack_output(stack_identifier, 'volume_id')
112 self.addCleanup(self._cleanup_volume, volume_id)
Ghanshyam961ea1a2014-06-09 10:56:00 +0900113 retain_template = self.load_template('cinder_basic_delete_retain')
114 self._cinder_verify(volume_id, retain_template)
Steven Hardy8b9fa022014-04-04 17:31:50 +0100115
116 # Verify the stack outputs are as expected
Ghanshyam961ea1a2014-06-09 10:56:00 +0900117 self._outputs_verify(stack_identifier, retain_template)
Steven Hardy8b9fa022014-04-04 17:31:50 +0100118
119 # Delete the stack and ensure the volume is *not* gone
120 self.client.delete_stack(stack_identifier)
121 self.client.wait_for_stack_status(stack_identifier, 'DELETE_COMPLETE')
Ghanshyam961ea1a2014-06-09 10:56:00 +0900122 self._cinder_verify(volume_id, retain_template)
Steven Hardy8b9fa022014-04-04 17:31:50 +0100123
124 # Volume cleanup happens via addCleanup calling _cleanup_volume