~ubuntu-branches/ubuntu/saucy/heat/saucy-updates

« back to all changes in this revision

Viewing changes to heat/tests/test_provider_template.py

  • Committer: Package Import Robot
  • Author(s): James Page, Chuck Short, James Page
  • Date: 2013-08-08 15:23:59 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20130808152359-9jgqjp23kssvc3x9
Tags: 2013.2~b2.a186.g2b4b248-0ubuntu1
[ Chuck Short ]
* debian/patches/rename-quantumclient.patch: Dropped no longer needed. 
* debian/control: Add python-oslo.sphinx

[ James Page ]
* New upstream snapshot.
* d/watch: Updated to track releases on launchpad.
* d/control: Drop BD in pep8, no longer required.
* d/control,rules: Drop use of openstack-pkg-tools, revert use of xz
  compression for debs.
* d/control,*.config,*.templates,po: Drop use of debconf/dbconfig-common
  to configure heat.
* d/*.upstart: Add upstart configurations for Ubuntu.
* d/p/default-kombu.patch: Switch default messaging from qpid to
  kombu.
* d/p/default-sqlite.patch: Use sqlite as default database option.
* d/control: Add python-ceilometerclient to BD's.
* d/rules: Fail package build for unit test failures.
* d/*.install: Directly install configuration files to /etc/heat.
* d/control: Update VCS locations to ubuntu-server-dev branches.
* d/heat-common.{install,manpages}: Include new binaries and associated
  manpages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#    License for the specific language governing permissions and limitations
13
13
#    under the License.
14
14
 
 
15
import os
 
16
import yaml
 
17
 
 
18
from heat.common import urlfetch
15
19
 
16
20
from heat.engine import environment
17
21
from heat.engine import parser
22
26
 
23
27
from heat.tests import generic_resource as generic_rsrc
24
28
from heat.tests.common import HeatTestCase
 
29
from heat.tests.utils import dummy_context
25
30
from heat.tests.utils import setup_dummy_db
26
31
 
27
32
 
32
37
class ProviderTemplateTest(HeatTestCase):
33
38
    def setUp(self):
34
39
        super(ProviderTemplateTest, self).setUp()
 
40
        setup_dummy_db()
35
41
        resource._register_class('OS::ResourceType',
36
42
                                 generic_rsrc.GenericResource)
37
43
        resource._register_class('myCloud::ResourceType',
76
82
        cls = resource.get_class('OS::ResourceType', 'fred', env)
77
83
        self.assertEqual(cls, generic_rsrc.GenericResource)
78
84
 
79
 
    def test_get_template_resource(self):
80
 
        # assertion: if the name matches {.yaml|.template} we get the
81
 
        # TemplateResource class.
82
 
        env_str = {'resource_registry': {'resources': {'fred': {
83
 
            "OS::ResourceType": "some_magic.yaml"}}}}
84
 
        env = environment.Environment(env_str)
85
 
        cls = resource.get_class('OS::ResourceType', 'fred', env)
86
 
        self.assertEqual(cls, template_resource.TemplateResource)
87
 
 
88
85
    def test_to_parameters(self):
89
86
        """Tests property conversion to parameter values."""
90
87
        setup_dummy_db()
91
 
        stack = parser.Stack(None, 'test_stack', parser.Template({}),
 
88
        stack = parser.Stack(dummy_context(), 'test_stack',
 
89
                             parser.Template({}),
92
90
                             stack_id=uuidutils.generate_uuid())
93
91
 
94
92
        class DummyResource(object):
139
137
        self.assertEqual(5, converted_params.get("ANum"))
140
138
        # verify Map conversion
141
139
        self.assertEqual(map_prop_val, converted_params.get("AMap"))
 
140
 
 
141
    def test_get_template_resource(self):
 
142
        # assertion: if the name matches {.yaml|.template} we get the
 
143
        # TemplateResource class.
 
144
        env_str = {'resource_registry': {'resources': {'fred': {
 
145
            "OS::ResourceType": "some_magic.yaml"}}}}
 
146
        env = environment.Environment(env_str)
 
147
        cls = resource.get_class('OS::ResourceType', 'fred', env)
 
148
        self.assertEqual(cls, template_resource.TemplateResource)
 
149
 
 
150
    def test_template_as_resource(self):
 
151
        """
 
152
        Test that the resulting resource has the right prop and attrib schema.
 
153
 
 
154
        Note that this test requires the Wordpress_Single_Instance.yaml
 
155
        template in the templates directory since we want to test using a
 
156
        non-trivial template.
 
157
        """
 
158
        test_templ_name = "WordPress_Single_Instance.yaml"
 
159
        path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
 
160
                            'templates', test_templ_name)
 
161
        # check if its in the directory list vs. exists to work around
 
162
        # case-insensitive file systems
 
163
        self.assertIn(test_templ_name, os.listdir(os.path.dirname(path)))
 
164
        with open(path) as test_templ_file:
 
165
            test_templ = test_templ_file.read()
 
166
        self.assertTrue(test_templ, "Empty test template")
 
167
        self.m.StubOutWithMock(urlfetch, "get")
 
168
        urlfetch.get(test_templ_name).AndReturn(test_templ)
 
169
        parsed_test_templ = yaml.safe_load(test_templ)
 
170
        self.m.ReplayAll()
 
171
        json_snippet = {
 
172
            "Type": test_templ_name,
 
173
            "Properties": {
 
174
                "KeyName": "mykeyname",
 
175
                "DBName": "wordpress1",
 
176
                "DBUsername": "wpdbuser",
 
177
                "DBPassword": "wpdbpass",
 
178
                "DBRootPassword": "wpdbrootpass",
 
179
                "LinuxDistribution": "U10"
 
180
            }
 
181
        }
 
182
        stack = parser.Stack(None, 'test_stack', parser.Template({}),
 
183
                             stack_id=uuidutils.generate_uuid())
 
184
        templ_resource = resource.Resource("test_templ_resource", json_snippet,
 
185
                                           stack)
 
186
        self.m.VerifyAll()
 
187
        self.assertIsInstance(templ_resource,
 
188
                              template_resource.TemplateResource)
 
189
        for prop in parsed_test_templ.get("Parameters", {}):
 
190
            self.assertIn(prop, templ_resource.properties)
 
191
        for attrib in parsed_test_templ.get("Outputs", {}):
 
192
            self.assertIn(attrib, templ_resource.attributes)
 
193
        for k, v in json_snippet.get("Properties").items():
 
194
            self.assertEqual(v, templ_resource.properties[k])