summaryrefslogtreecommitdiff
path: root/tempest/api/orchestration/stacks/test_volumes.py
blob: f371370a3c2c920748dd121e87f6c3c7f0aea9bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import logging

from tempest.api.orchestration import base
from tempest.common.utils import data_utils
from tempest import config
from tempest import exceptions
from tempest import test


CONF = config.CONF
LOG = logging.getLogger(__name__)


class CinderResourcesTest(base.BaseOrchestrationTest):

    @classmethod
    def setUpClass(cls):
        super(CinderResourcesTest, cls).setUpClass()
        if not CONF.service_available.cinder:
            raise cls.skipException('Cinder support is required')

    def _cinder_verify(self, volume_id, template):
        self.assertIsNotNone(volume_id)
        _, volume = self.volumes_client.get_volume(volume_id)
        self.assertEqual('available', volume.get('status'))
        self.assertEqual(template['resources']['volume']['properties'][
            'size'], volume.get('size'))
        self.assertEqual(template['resources']['volume']['properties'][
            'description'], volume.get('display_description'))
        self.assertEqual(template['resources']['volume']['properties'][
            'name'], volume.get('display_name'))

    def _outputs_verify(self, stack_identifier, template):
        self.assertEqual('available',
                         self.get_stack_output(stack_identifier, 'status'))
        self.assertEqual(str(template['resources']['volume']['properties'][
            'size']), self.get_stack_output(stack_identifier, 'size'))
        self.assertEqual(template['resources']['volume']['properties'][
            'description'], self.get_stack_output(stack_identifier,
                                                  'display_description'))
        self.assertEqual(template['resources']['volume']['properties'][
            'name'], self.get_stack_output(stack_identifier, 'display_name'))

    @test.attr(type='gate')
    @test.services('volume')
    def test_cinder_volume_create_delete(self):
        """Create and delete a volume via OS::Cinder::Volume."""
        stack_name = data_utils.rand_name('heat')
        template = self.read_template('cinder_basic')
        stack_identifier = self.create_stack(stack_name, template)
        self.client.wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')

        # Verify with cinder that the volume exists, with matching details
        volume_id = self.get_stack_output(stack_identifier, 'volume_id')
        cinder_basic_template = self.load_template('cinder_basic')
        self._cinder_verify(volume_id, cinder_basic_template)

        # Verify the stack outputs are as expected
        self._outputs_verify(stack_identifier, cinder_basic_template)

        # Delete the stack and ensure the volume is gone
        self.client.delete_stack(stack_identifier)
        self.client.wait_for_stack_status(stack_identifier, 'DELETE_COMPLETE')
        self.assertRaises(exceptions.NotFound,
                          self.volumes_client.get_volume,
                          volume_id)

    def _cleanup_volume(self, volume_id):
        """Cleanup the volume direct with cinder."""
        self.volumes_client.delete_volume(volume_id)
        self.volumes_client.wait_for_resource_deletion(volume_id)

    @test.attr(type='gate')
    @test.services('volume')
    def test_cinder_volume_create_delete_retain(self):
        """Ensure the 'Retain' deletion policy is respected."""
        stack_name = data_utils.rand_name('heat')
        template = self.read_template('cinder_basic_delete_retain')
        stack_identifier = self.create_stack(stack_name, template)
        self.client.wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')

        # Verify with cinder that the volume exists, with matching details
        volume_id = self.get_stack_output(stack_identifier, 'volume_id')
        self.addCleanup(self._cleanup_volume, volume_id)
        retain_template = self.load_template('cinder_basic_delete_retain')
        self._cinder_verify(volume_id, retain_template)

        # Verify the stack outputs are as expected
        self._outputs_verify(stack_identifier, retain_template)

        # Delete the stack and ensure the volume is *not* gone
        self.client.delete_stack(stack_identifier)
        self.client.wait_for_stack_status(stack_identifier, 'DELETE_COMPLETE')
        self._cinder_verify(volume_id, retain_template)

        # Volume cleanup happens via addCleanup calling _cleanup_volume