Steve Baker | a5bd912 | 2014-08-11 14:39:00 +1200 | [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 | |
Steve Baker | a5bd912 | 2014-08-11 14:39:00 +1200 | [diff] [blame] | 13 | |
| 14 | from cinderclient import exceptions as cinder_exceptions |
Steve Baker | 2464129 | 2015-03-13 10:47:50 +1300 | [diff] [blame] | 15 | from oslo_log import log as logging |
Pavlo Shchelokovskyy | 60e0ecd | 2014-12-14 22:17:21 +0200 | [diff] [blame] | 16 | import six |
| 17 | from testtools import testcase |
Steve Baker | a5bd912 | 2014-08-11 14:39:00 +1200 | [diff] [blame] | 18 | |
Steve Baker | 50d3e8c | 2014-10-21 11:08:50 +1300 | [diff] [blame] | 19 | from heat_integrationtests.common import exceptions |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 20 | from heat_integrationtests.scenario import scenario_base |
Steve Baker | a5bd912 | 2014-08-11 14:39:00 +1200 | [diff] [blame] | 21 | |
| 22 | LOG = logging.getLogger(__name__) |
| 23 | |
| 24 | |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 25 | class VolumeBackupRestoreIntegrationTest(scenario_base.ScenarioTestsBase): |
| 26 | """ |
| 27 | Class is responsible for testing of volume backup. |
| 28 | """ |
Steve Baker | a5bd912 | 2014-08-11 14:39:00 +1200 | [diff] [blame] | 29 | |
| 30 | def setUp(self): |
| 31 | super(VolumeBackupRestoreIntegrationTest, self).setUp() |
Steve Baker | a5bd912 | 2014-08-11 14:39:00 +1200 | [diff] [blame] | 32 | self.volume_description = 'A test volume description 123' |
| 33 | self.volume_size = self.conf.volume_size |
| 34 | |
| 35 | def _cinder_verify(self, volume_id, expected_status='available'): |
| 36 | self.assertIsNotNone(volume_id) |
| 37 | volume = self.volume_client.volumes.get(volume_id) |
| 38 | self.assertIsNotNone(volume) |
| 39 | self.assertEqual(expected_status, volume.status) |
| 40 | self.assertEqual(self.volume_size, volume.size) |
| 41 | self.assertEqual(self.volume_description, |
| 42 | volume.display_description) |
| 43 | |
| 44 | def _outputs_verify(self, stack, expected_status='available'): |
| 45 | self.assertEqual(expected_status, |
| 46 | self._stack_output(stack, 'status')) |
| 47 | self.assertEqual(six.text_type(self.volume_size), |
| 48 | self._stack_output(stack, 'size')) |
| 49 | self.assertEqual(self.volume_description, |
| 50 | self._stack_output(stack, 'display_description')) |
| 51 | |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 52 | def check_stack(self, stack_id): |
| 53 | stack = self.client.stacks.get(stack_id) |
Sergey Kraynev | ef9d842 | 2015-02-13 03:41:46 -0500 | [diff] [blame] | 54 | |
Steve Baker | a5bd912 | 2014-08-11 14:39:00 +1200 | [diff] [blame] | 55 | # Verify with cinder that the volume exists, with matching details |
| 56 | volume_id = self._stack_output(stack, 'volume_id') |
| 57 | self._cinder_verify(volume_id, expected_status='in-use') |
| 58 | |
| 59 | # Verify the stack outputs are as expected |
| 60 | self._outputs_verify(stack, expected_status='in-use') |
| 61 | |
| 62 | # Delete the stack and ensure a backup is created for volume_id |
| 63 | # but the volume itself is gone |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 64 | self.client.stacks.delete(stack_id) |
| 65 | self._wait_for_stack_status(stack_id, 'DELETE_COMPLETE') |
Steve Baker | a5bd912 | 2014-08-11 14:39:00 +1200 | [diff] [blame] | 66 | self.assertRaises(cinder_exceptions.NotFound, |
| 67 | self.volume_client.volumes.get, |
| 68 | volume_id) |
| 69 | |
| 70 | backups = self.volume_client.backups.list() |
| 71 | self.assertIsNotNone(backups) |
| 72 | backups_filtered = [b for b in backups if b.volume_id == volume_id] |
| 73 | self.assertEqual(1, len(backups_filtered)) |
| 74 | backup = backups_filtered[0] |
| 75 | self.addCleanup(self.volume_client.backups.delete, backup.id) |
| 76 | |
| 77 | # Now, we create another stack where the volume is created from the |
| 78 | # backup created by the previous stack |
Steve Baker | 50d3e8c | 2014-10-21 11:08:50 +1300 | [diff] [blame] | 79 | try: |
Sergey Kraynev | ef9d842 | 2015-02-13 03:41:46 -0500 | [diff] [blame] | 80 | stack_identifier2 = self.launch_stack( |
Steve Baker | 50d3e8c | 2014-10-21 11:08:50 +1300 | [diff] [blame] | 81 | template_name='test_volumes_create_from_backup.yaml', |
| 82 | add_parameters={'backup_id': backup.id}) |
Sergey Kraynev | ef9d842 | 2015-02-13 03:41:46 -0500 | [diff] [blame] | 83 | stack2 = self.client.stacks.get(stack_identifier2) |
Steve Baker | 50d3e8c | 2014-10-21 11:08:50 +1300 | [diff] [blame] | 84 | except exceptions.StackBuildErrorException as e: |
| 85 | LOG.error("Halting test due to bug: #1382300") |
| 86 | LOG.exception(e) |
| 87 | return |
Steve Baker | a5bd912 | 2014-08-11 14:39:00 +1200 | [diff] [blame] | 88 | |
| 89 | # Verify with cinder that the volume exists, with matching details |
| 90 | volume_id2 = self._stack_output(stack2, 'volume_id') |
| 91 | self._cinder_verify(volume_id2, expected_status='in-use') |
| 92 | |
| 93 | # Verify the stack outputs are as expected |
| 94 | self._outputs_verify(stack2, expected_status='in-use') |
| 95 | testfile_data = self._stack_output(stack2, 'testfile_data') |
| 96 | self.assertEqual('{"instance1": "Volume Data:ateststring"}', |
| 97 | testfile_data) |
| 98 | |
| 99 | # Delete the stack and ensure the volume is gone |
| 100 | self.client.stacks.delete(stack_identifier2) |
| 101 | self._wait_for_stack_status(stack_identifier2, 'DELETE_COMPLETE') |
| 102 | self.assertRaises(cinder_exceptions.NotFound, |
| 103 | self.volume_client.volumes.get, |
| 104 | volume_id2) |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 105 | |
| 106 | @testcase.skip('Skipped until failure rate ' |
| 107 | 'can be reduced ref bug #1382300') |
| 108 | def test_cinder_volume_create_backup_restore(self): |
| 109 | """ |
| 110 | Ensure the 'Snapshot' deletion policy works. |
| 111 | |
| 112 | This requires a more complex test, but it tests several aspects |
| 113 | of the heat cinder resources: |
| 114 | 1. Create a volume, attach it to an instance, write some data to it |
| 115 | 2. Delete the stack, with 'Snapshot' specified, creates a backup |
| 116 | 3. Check the snapshot has created a volume backup |
| 117 | 4. Create a new stack, where the volume is created from the backup |
| 118 | 5. Verify the test data written in (1) is present in the new volume |
| 119 | """ |
| 120 | parameters = { |
| 121 | 'key_name': self.keypair_name, |
Pavlo Shchelokovskyy | 46e5cb2 | 2015-03-23 12:01:25 +0000 | [diff] [blame] | 122 | 'instance_type': self.conf.minimal_instance_type, |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 123 | 'image_id': self.conf.minimal_image_ref, |
| 124 | 'volume_description': self.volume_description, |
| 125 | 'timeout': self.conf.build_timeout, |
| 126 | 'network': self.net['id'] |
| 127 | } |
| 128 | |
| 129 | # Launch stack |
| 130 | stack_id = self.launch_stack( |
| 131 | template_name='test_volumes_delete_snapshot.yaml', |
| 132 | parameters=parameters, |
| 133 | add_parameters={'volume_size': self.volume_size} |
| 134 | ) |
| 135 | |
| 136 | # Check stack |
| 137 | self.check_stack(stack_id) |