76
82
cls = resource.get_class('OS::ResourceType', 'fred', env)
77
83
self.assertEqual(cls, generic_rsrc.GenericResource)
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)
88
85
def test_to_parameters(self):
89
86
"""Tests property conversion to parameter values."""
91
stack = parser.Stack(None, 'test_stack', parser.Template({}),
88
stack = parser.Stack(dummy_context(), 'test_stack',
92
90
stack_id=uuidutils.generate_uuid())
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"))
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)
150
def test_template_as_resource(self):
152
Test that the resulting resource has the right prop and attrib schema.
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.
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)
172
"Type": test_templ_name,
174
"KeyName": "mykeyname",
175
"DBName": "wordpress1",
176
"DBUsername": "wpdbuser",
177
"DBPassword": "wpdbpass",
178
"DBRootPassword": "wpdbrootpass",
179
"LinuxDistribution": "U10"
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,
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])