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

« back to all changes in this revision

Viewing changes to heat/tests/magnum/test_magnum_baymodel.py

  • Committer: Package Import Robot
  • Author(s): Corey Bryant
  • Date: 2015-09-08 15:52:07 UTC
  • mfrom: (1.1.28)
  • Revision ID: package-import@ubuntu.com-20150908155207-zi2r1rckyrevr5u7
Tags: 1:5.0.0~b3-0ubuntu1
* New upstream milestone for OpenStack Liberty.
* d/control: Align (build-)depends with upstream.
* d/p/fix-dummy-resource-missing.patch: Dropped. Fixed in milestone.
* d/p/move-extensions.patch: Dropped. Fixed in milestone.

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.common import template_format
 
17
from heat.engine import resource
 
18
from heat.engine.resources.openstack.magnum import baymodel
 
19
from heat.engine import scheduler
 
20
from heat.tests import common
 
21
from heat.tests import utils
 
22
 
 
23
 
 
24
magnum_template = '''
 
25
    heat_template_version: 2015-04-30
 
26
    resources:
 
27
      test_baymodel:
 
28
        type: OS::Magnum::BayModel
 
29
        properties:
 
30
          name: test_bay_model
 
31
          image: fedora-21-atomic-2
 
32
          flavor: m1.small
 
33
          master_flavor: m1.medium
 
34
          keypair: heat_key
 
35
          external_network: 0244b54d-ae1f-44f0-a24a-442760f1d681
 
36
          fixed_network: 0f59a3dd-fac1-4d03-b41a-d4115fbffa89
 
37
          dns_nameserver: 8.8.8.8
 
38
          docker_volume_size: 5
 
39
          ssh_authorized_key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAB
 
40
          coe: 'swarm'
 
41
'''
 
42
 
 
43
RESOURCE_TYPE = 'OS::Magnum::BayModel'
 
44
 
 
45
 
 
46
class FakeBayModel(object):
 
47
    def __init__(self):
 
48
        self.to_dict = lambda: {'attr': 'val'}
 
49
 
 
50
 
 
51
class TestMagnumBayModel(common.HeatTestCase):
 
52
    def setUp(self):
 
53
        super(TestMagnumBayModel, self).setUp()
 
54
        self.ctx = utils.dummy_context()
 
55
        resource._register_class(RESOURCE_TYPE, baymodel.BayModel)
 
56
        t = template_format.parse(magnum_template)
 
57
        self.stack = utils.parse_stack(t)
 
58
 
 
59
        resource_defns = self.stack.t.resource_definitions(self.stack)
 
60
        self.rsrc_defn = resource_defns['test_baymodel']
 
61
        self.client = mock.Mock()
 
62
        self.patchobject(baymodel.BayModel, 'client',
 
63
                         return_value=self.client)
 
64
        self.stub_FlavorConstraint_validate()
 
65
        self.stub_KeypairConstraint_validate()
 
66
        self.stub_ImageConstraint_validate()
 
67
        self.stub_NetworkConstraint_validate()
 
68
 
 
69
    def _create_resource(self, name, snippet, stack):
 
70
        self.resource_id = '12345'
 
71
        self.test_bay_model = self.stack['test_baymodel']
 
72
        value = mock.MagicMock(uuid=self.resource_id)
 
73
        self.client.baymodels.create.return_value = value
 
74
        bm = baymodel.BayModel(name, snippet, stack)
 
75
        scheduler.TaskRunner(bm.create)()
 
76
        return bm
 
77
 
 
78
    def test_bay_model_create(self):
 
79
        bm = self._create_resource('bm', self.rsrc_defn, self.stack)
 
80
        self.assertEqual(self.resource_id, bm.resource_id)
 
81
        self.assertEqual((bm.CREATE, bm.COMPLETE), bm.state)
 
82
 
 
83
    def test_bay_model_delete(self):
 
84
        bm = self._create_resource('bm', self.rsrc_defn, self.stack)
 
85
        scheduler.TaskRunner(bm.delete)()
 
86
        self.assertEqual((bm.DELETE, bm.COMPLETE), bm.state)
 
87
 
 
88
    def test_resource_mapping(self):
 
89
        mapping = baymodel.resource_mapping()
 
90
        self.assertEqual(1, len(mapping))
 
91
        self.assertEqual(baymodel.BayModel, mapping[RESOURCE_TYPE])
 
92
 
 
93
    def test_show_resource(self):
 
94
        bm = self._create_resource('bm', self.rsrc_defn, self.stack)
 
95
        self.client.baymodels.get.return_value = FakeBayModel()
 
96
        self.assertEqual({'attr': 'val'}, bm.FnGetAtt('show'))