~ubuntu-branches/ubuntu/wily/heat/wily

« back to all changes in this revision

Viewing changes to contrib/nova_flavor/nova_flavor/tests/test_nova_flavor.py

  • Committer: Package Import Robot
  • Author(s): Corey Bryant, Corey Bryant, James Page
  • Date: 2015-07-07 17:06:19 UTC
  • mfrom: (1.1.26) (45.1.1 vivid-proposed)
  • Revision ID: package-import@ubuntu.com-20150707170619-hra2dbjpfofpou4s
Tags: 1:5.0.0~b1-0ubuntu1
[ Corey Bryant ]
* New upstream milestone for OpenStack Liberty:
  - d/control: Align (build-)depends with upstream.
  - d/p/fix-requirements.patch: Rebased.
  - d/p/sudoers_patch.patch: Rebased.

[ James Page ]
* d/s/options: Ignore any removal of egg-info data during package clean.
* d/control: Drop MySQL and PostgreSQL related BD's, not required for unit
  testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
3
 
#    not use this file except in compliance with the License. You may obtain
4
 
#    a copy of the License at
5
 
#
6
 
#         http://www.apache.org/licenses/LICENSE-2.0
7
 
#
8
 
#    Unless required by applicable law or agreed to in writing, software
9
 
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10
 
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11
 
#    License for the specific language governing permissions and limitations
12
 
#    under the License.
13
 
 
14
 
import mock
15
 
 
16
 
from heat.engine import parser
17
 
from heat.engine import resource
18
 
from heat.engine import template
19
 
from heat.tests import common
20
 
from heat.tests.nova import fakes
21
 
from heat.tests import utils
22
 
 
23
 
from ..resources import nova_flavor  # noqa
24
 
 
25
 
flavor_template = {
26
 
    'heat_template_version': '2013-05-23',
27
 
    'resources': {
28
 
        'my_flavor': {
29
 
            'type': 'OS::Nova::Flavor',
30
 
            'properties': {
31
 
                'ram': 1024,
32
 
                'vcpus': 2,
33
 
                'disk': 20,
34
 
                'swap': 2,
35
 
                'rxtx_factor': 1.0,
36
 
                'ephemeral': 0,
37
 
                'extra_specs': {"foo": "bar"}
38
 
            }
39
 
        }
40
 
    }
41
 
}
42
 
 
43
 
 
44
 
class NovaFlavorTest(common.HeatTestCase):
45
 
    def setUp(self):
46
 
        super(NovaFlavorTest, self).setUp()
47
 
 
48
 
        self.ctx = utils.dummy_context()
49
 
 
50
 
        # For unit testing purpose. Register resource provider
51
 
        # explicitly.
52
 
        resource._register_class("OS::Nova::Flavor", nova_flavor.NovaFlavor)
53
 
 
54
 
        self.stack = parser.Stack(
55
 
            self.ctx, 'nova_flavor_test_stack',
56
 
            template.Template(flavor_template)
57
 
        )
58
 
 
59
 
        self.my_flavor = self.stack['my_flavor']
60
 
        nova = mock.MagicMock()
61
 
        self.novaclient = mock.MagicMock()
62
 
        self.my_flavor.nova = nova
63
 
        nova.return_value = self.novaclient
64
 
        self.flavors = self.novaclient.flavors
65
 
 
66
 
    def test_resource_mapping(self):
67
 
        mapping = nova_flavor.resource_mapping()
68
 
        self.assertEqual(1, len(mapping))
69
 
        self.assertEqual(nova_flavor.NovaFlavor, mapping['OS::Nova::Flavor'])
70
 
        self.assertIsInstance(self.my_flavor, nova_flavor.NovaFlavor)
71
 
 
72
 
    def test_flavor_handle_create(self):
73
 
        value = mock.MagicMock()
74
 
        flavor_id = '927202df-1afb-497f-8368-9c2d2f26e5db'
75
 
        value.id = flavor_id
76
 
        self.flavors.create.return_value = value
77
 
        self.my_flavor.handle_create()
78
 
        value.set_keys.assert_called_once_with({"foo": "bar"})
79
 
        self.assertEqual(flavor_id, self.my_flavor.resource_id)
80
 
 
81
 
    def test_flavor_handle_update_keys(self):
82
 
        value = mock.MagicMock()
83
 
        self.flavors.get.return_value = value
84
 
        value.get_keys.return_value = {}
85
 
 
86
 
        new_keys = {"new_foo": "new_bar"}
87
 
        prop_diff = {'extra_specs': new_keys}
88
 
        self.my_flavor.handle_update(json_snippet=None,
89
 
                                     tmpl_diff=None, prop_diff=prop_diff)
90
 
        value.unset_keys.assert_called_once_with({})
91
 
        value.set_keys.assert_called_once_with(new_keys)
92
 
 
93
 
    def test_flavor_handle_delete(self):
94
 
        self.resource_id = None
95
 
        self.assertIsNone(self.my_flavor.handle_delete())
96
 
        flavor_id = '927202df-1afb-497f-8368-9c2d2f26e5db'
97
 
        self.my_flavor.resource_id = flavor_id
98
 
        self.flavors.delete.return_value = None
99
 
        self.assertIsNone(self.my_flavor.handle_delete())
100
 
        self.flavors.delete.side_effect = fakes.fake_exception()
101
 
        self.assertIsNone(self.my_flavor.handle_delete())