Steven Hardy | b1f9198 | 2014-04-04 15:35:55 +0100 | [diff] [blame] | 1 | # 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 | |
| 13 | import logging |
| 14 | |
| 15 | from tempest.api.orchestration import base |
| 16 | from tempest.common.utils import data_utils |
| 17 | from tempest import config |
Steven Hardy | 8b9fa02 | 2014-04-04 17:31:50 +0100 | [diff] [blame] | 18 | from tempest import exceptions |
Steven Hardy | b1f9198 | 2014-04-04 15:35:55 +0100 | [diff] [blame] | 19 | from tempest import test |
| 20 | |
| 21 | |
| 22 | CONF = config.CONF |
| 23 | LOG = logging.getLogger(__name__) |
| 24 | |
| 25 | |
| 26 | class 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 | |
Ghanshyam | 961ea1a | 2014-06-09 10:56:00 +0900 | [diff] [blame] | 34 | def _cinder_verify(self, volume_id, template): |
Steven Hardy | 8b9fa02 | 2014-04-04 17:31:50 +0100 | [diff] [blame] | 35 | 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')) |
Ghanshyam | 961ea1a | 2014-06-09 10:56:00 +0900 | [diff] [blame] | 39 | 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 Hardy | 8b9fa02 | 2014-04-04 17:31:50 +0100 | [diff] [blame] | 45 | |
Ghanshyam | 961ea1a | 2014-06-09 10:56:00 +0900 | [diff] [blame] | 46 | def _outputs_verify(self, stack_identifier, template): |
Steven Hardy | 8b9fa02 | 2014-04-04 17:31:50 +0100 | [diff] [blame] | 47 | self.assertEqual('available', |
| 48 | self.get_stack_output(stack_identifier, 'status')) |
Ghanshyam | 961ea1a | 2014-06-09 10:56:00 +0900 | [diff] [blame] | 49 | 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 Hardy | 8b9fa02 | 2014-04-04 17:31:50 +0100 | [diff] [blame] | 56 | |
Steven Hardy | b1f9198 | 2014-04-04 15:35:55 +0100 | [diff] [blame] | 57 | @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') |
Ghanshyam | 961ea1a | 2014-06-09 10:56:00 +0900 | [diff] [blame] | 61 | template = self.read_template('cinder_basic') |
Steven Hardy | b1f9198 | 2014-04-04 15:35:55 +0100 | [diff] [blame] | 62 | 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') |
Ghanshyam | 961ea1a | 2014-06-09 10:56:00 +0900 | [diff] [blame] | 67 | cinder_basic_template = self.load_template('cinder_basic') |
| 68 | self._cinder_verify(volume_id, cinder_basic_template) |
Steven Hardy | b1f9198 | 2014-04-04 15:35:55 +0100 | [diff] [blame] | 69 | |
| 70 | # Verify the stack outputs are as expected |
Ghanshyam | 961ea1a | 2014-06-09 10:56:00 +0900 | [diff] [blame] | 71 | self._outputs_verify(stack_identifier, cinder_basic_template) |
Steven Hardy | 8b9fa02 | 2014-04-04 17:31:50 +0100 | [diff] [blame] | 72 | |
| 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 Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 82 | self.volumes_client.delete_volume(volume_id) |
Steven Hardy | 8b9fa02 | 2014-04-04 17:31:50 +0100 | [diff] [blame] | 83 | 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') |
Ghanshyam | 961ea1a | 2014-06-09 10:56:00 +0900 | [diff] [blame] | 89 | template = self.read_template('cinder_basic_delete_retain') |
Steven Hardy | 8b9fa02 | 2014-04-04 17:31:50 +0100 | [diff] [blame] | 90 | 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) |
Ghanshyam | 961ea1a | 2014-06-09 10:56:00 +0900 | [diff] [blame] | 96 | retain_template = self.load_template('cinder_basic_delete_retain') |
| 97 | self._cinder_verify(volume_id, retain_template) |
Steven Hardy | 8b9fa02 | 2014-04-04 17:31:50 +0100 | [diff] [blame] | 98 | |
| 99 | # Verify the stack outputs are as expected |
Ghanshyam | 961ea1a | 2014-06-09 10:56:00 +0900 | [diff] [blame] | 100 | self._outputs_verify(stack_identifier, retain_template) |
Steven Hardy | 8b9fa02 | 2014-04-04 17:31:50 +0100 | [diff] [blame] | 101 | |
| 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') |
Ghanshyam | 961ea1a | 2014-06-09 10:56:00 +0900 | [diff] [blame] | 105 | self._cinder_verify(volume_id, retain_template) |
Steven Hardy | 8b9fa02 | 2014-04-04 17:31:50 +0100 | [diff] [blame] | 106 | |
| 107 | # Volume cleanup happens via addCleanup calling _cleanup_volume |