33
33
super(ResourceTest, self).setUp()
35
self.stack = parser.Stack(None, 'test_stack', parser.Template({}),
35
self.stack = parser.Stack(dummy_context(), 'test_stack',
36
37
stack_id=uuidutils.generate_uuid())
38
39
resource._register_class('GenericResourceType',
58
59
def test_state_defaults(self):
59
60
tmpl = {'Type': 'Foo'}
60
61
res = generic_rsrc.GenericResource('test_res_def', tmpl, self.stack)
61
self.assertEqual(res.state, (None, None))
62
self.assertEqual(res.state, (res.INIT, res.COMPLETE))
62
63
self.assertEqual(res.status_reason, '')
64
65
def test_state_set(self):
77
78
self.assertRaises(ValueError, res.state_set, 'foo', res.COMPLETE)
78
79
self.assertRaises(ValueError, res.state_set, res.CREATE, 'bla')
81
def test_state_del_stack(self):
82
tmpl = {'Type': 'Foo'}
83
self.stack.action = self.stack.DELETE
84
self.stack.status = self.stack.IN_PROGRESS
85
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
86
self.assertEqual(res.DELETE, res.action)
87
self.assertEqual(res.COMPLETE, res.status)
80
89
def test_type(self):
81
90
tmpl = {'Type': 'Foo'}
82
91
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
149
158
tmpl1 = {'Type': 'Foo'}
150
159
tmpl2 = {'Type': 'Foo'}
151
160
tmpl3 = {'Type': 'Bar'}
152
stack2 = parser.Stack(None, 'test_stack', parser.Template({}),
161
stack2 = parser.Stack(dummy_context(), 'test_stack',
162
parser.Template({}), stack_id=-1)
154
163
res1 = generic_rsrc.GenericResource('test_resource', tmpl1, self.stack)
155
164
res2 = generic_rsrc.GenericResource('test_resource', tmpl2, stack2)
156
165
res3 = generic_rsrc.GenericResource('test_resource2', tmpl3, stack2)
272
281
self.assertRaises(exception.ResourceFailure, create)
273
282
self.assertEqual((res.CREATE, res.FAILED), res.state)
284
def test_create_resource_after_destroy(self):
285
tmpl = {'Type': 'GenericResourceType'}
286
rname = 'test_res_id_none'
287
res = generic_rsrc.ResourceWithProps(rname, tmpl, self.stack)
288
res.id = 'test_res_id'
289
(res.action, res.status) = (res.INIT, res.DELETE)
290
self.assertRaises(exception.ResourceFailure, res.create)
293
scheduler.TaskRunner(res.create)()
294
self.assertEqual((res.CREATE, res.COMPLETE), res.state)
275
296
def test_update_ok(self):
276
297
tmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'abc'}}
277
298
res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack)
463
484
self.assertRaises(exception.ResourceFailure, resume)
464
485
self.assertEqual((res.RESUME, res.FAILED), res.state)
487
def test_resource_class_to_template(self):
489
class TestResource(resource.Resource):
490
list_schema = {'wont_show_up': {'Type': 'Number'}}
491
map_schema = {'will_show_up': {'Type': 'Integer'}}
493
properties_schema = {
494
'name': {'Type': 'String'},
495
'bool': {'Type': 'Boolean'},
496
'implemented': {'Type': 'String',
498
'AllowedPattern': '.*',
502
'not_implemented': {'Type': 'String',
503
'Implemented': False},
504
'number': {'Type': 'Number',
508
'list': {'Type': 'List', 'Schema': {'Type': 'Map',
509
'Schema': list_schema}},
510
'map': {'Type': 'Map', 'Schema': {'Type': 'Map',
511
'Schema': map_schema}},
514
attributes_schema = {
515
'output1': 'output1_desc',
516
'output2': 'output2_desc'
519
expected_template = {
521
'name': {'Type': 'String'},
522
'bool': {'Type': 'Boolean'},
525
'AllowedPattern': '.*',
529
'number': {'Type': 'Number',
533
'list': {'Type': 'CommaDelimitedList'},
534
'map': {'Type': 'Json'}
538
'Type': 'Test::Resource::resource',
540
'name': {'Ref': 'name'},
541
'bool': {'Ref': 'bool'},
542
'implemented': {'Ref': 'implemented'},
543
'number': {'Ref': 'number'},
544
'list': {'Fn::Split': {'Ref': 'list'}},
545
'map': {'Ref': 'map'}
551
'Description': 'output1_desc',
552
'Value': '{"Fn::GetAtt": ["TestResource", "output1"]}'
555
'Description': 'output2_desc',
556
'Value': '{"Fn::GetAtt": ["TestResource", "output2"]}'
560
self.assertEqual(expected_template,
561
TestResource.resource_to_template(
562
'Test::Resource::resource')
467
566
class MetadataTest(HeatTestCase):
472
571
'Metadata': {'Test': 'Initial metadata'}
475
ctx = context.get_admin_context()
476
self.m.StubOutWithMock(ctx, 'username')
477
ctx.username = 'metadata_test_user'
478
self.stack = parser.Stack(ctx, 'test_stack', parser.Template({}))
574
self.stack = parser.Stack(dummy_context(),
575
'test_stack', parser.Template({}))
479
576
self.stack.store()
480
577
self.res = generic_rsrc.GenericResource('metadata_resource',
481
578
tmpl, self.stack)