blob: 8356497e532cb083e85aae9c0b5f21486170770e [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
Masayuki Igawabfa07602015-01-20 18:47:17 +090015from tempest_lib import exceptions as lib_exc
16
Steven Hardyb1f91982014-04-04 15:35:55 +010017from tempest.api.orchestration import base
18from tempest.common.utils import data_utils
19from tempest import config
20from tempest import test
21
22
23CONF = config.CONF
24LOG = logging.getLogger(__name__)
25
26
27class CinderResourcesTest(base.BaseOrchestrationTest):
28
29 @classmethod
Rohan Kanade80b938a2015-02-07 10:58:56 +053030 def skip_checks(cls):
31 super(CinderResourcesTest, cls).skip_checks()
Steven Hardyb1f91982014-04-04 15:35:55 +010032 if not CONF.service_available.cinder:
33 raise cls.skipException('Cinder support is required')
34
Ghanshyam961ea1a2014-06-09 10:56:00 +090035 def _cinder_verify(self, volume_id, template):
Steven Hardy8b9fa022014-04-04 17:31:50 +010036 self.assertIsNotNone(volume_id)
Joseph Lanoux6809bab2014-12-18 14:57:18 +000037 volume = self.volumes_client.get_volume(volume_id)
Steven Hardy8b9fa022014-04-04 17:31:50 +010038 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')
ekhugen16d5dd92014-07-29 18:54:36 +000058 @test.services('volume')
Steven Hardyb1f91982014-04-04 15:35:55 +010059 def test_cinder_volume_create_delete(self):
60 """Create and delete a volume via OS::Cinder::Volume."""
61 stack_name = data_utils.rand_name('heat')
Ghanshyam961ea1a2014-06-09 10:56:00 +090062 template = self.read_template('cinder_basic')
Steven Hardyb1f91982014-04-04 15:35:55 +010063 stack_identifier = self.create_stack(stack_name, template)
64 self.client.wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
65
66 # Verify with cinder that the volume exists, with matching details
67 volume_id = self.get_stack_output(stack_identifier, 'volume_id')
Ghanshyam961ea1a2014-06-09 10:56:00 +090068 cinder_basic_template = self.load_template('cinder_basic')
69 self._cinder_verify(volume_id, cinder_basic_template)
Steven Hardyb1f91982014-04-04 15:35:55 +010070
71 # Verify the stack outputs are as expected
Ghanshyam961ea1a2014-06-09 10:56:00 +090072 self._outputs_verify(stack_identifier, cinder_basic_template)
Steven Hardy8b9fa022014-04-04 17:31:50 +010073
74 # Delete the stack and ensure the volume is gone
75 self.client.delete_stack(stack_identifier)
76 self.client.wait_for_stack_status(stack_identifier, 'DELETE_COMPLETE')
Masayuki Igawabfa07602015-01-20 18:47:17 +090077 self.assertRaises(lib_exc.NotFound,
Steven Hardy8b9fa022014-04-04 17:31:50 +010078 self.volumes_client.get_volume,
79 volume_id)
80
81 def _cleanup_volume(self, volume_id):
82 """Cleanup the volume direct with cinder."""
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000083 self.volumes_client.delete_volume(volume_id)
Steven Hardy8b9fa022014-04-04 17:31:50 +010084 self.volumes_client.wait_for_resource_deletion(volume_id)
85
86 @test.attr(type='gate')
ekhugen16d5dd92014-07-29 18:54:36 +000087 @test.services('volume')
Steven Hardy8b9fa022014-04-04 17:31:50 +010088 def test_cinder_volume_create_delete_retain(self):
89 """Ensure the 'Retain' deletion policy is respected."""
90 stack_name = data_utils.rand_name('heat')
Ghanshyam961ea1a2014-06-09 10:56:00 +090091 template = self.read_template('cinder_basic_delete_retain')
Steven Hardy8b9fa022014-04-04 17:31:50 +010092 stack_identifier = self.create_stack(stack_name, template)
93 self.client.wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
94
95 # Verify with cinder that the volume exists, with matching details
96 volume_id = self.get_stack_output(stack_identifier, 'volume_id')
97 self.addCleanup(self._cleanup_volume, volume_id)
Ghanshyam961ea1a2014-06-09 10:56:00 +090098 retain_template = self.load_template('cinder_basic_delete_retain')
99 self._cinder_verify(volume_id, retain_template)
Steven Hardy8b9fa022014-04-04 17:31:50 +0100100
101 # Verify the stack outputs are as expected
Ghanshyam961ea1a2014-06-09 10:56:00 +0900102 self._outputs_verify(stack_identifier, retain_template)
Steven Hardy8b9fa022014-04-04 17:31:50 +0100103
104 # Delete the stack and ensure the volume is *not* gone
105 self.client.delete_stack(stack_identifier)
106 self.client.wait_for_stack_status(stack_identifier, 'DELETE_COMPLETE')
Ghanshyam961ea1a2014-06-09 10:56:00 +0900107 self._cinder_verify(volume_id, retain_template)
Steven Hardy8b9fa022014-04-04 17:31:50 +0100108
109 # Volume cleanup happens via addCleanup calling _cleanup_volume