Add stack id and resource id in logs

Where applicable, the stack and resource id's will be added in the logs
that reference those stacks and/or resources.

blueprint log-resource-stack-id

Change-Id: I70958ddd4904d70ff26c7ad28e2f7fe951881198
Co-Authored-By: Daniel Givens <daniel.givens@rackspace.com>
This commit is contained in:
Jason Dunsmore 2013-09-17 12:24:08 -05:00
parent f75369eecf
commit faca2b6a01
4 changed files with 44 additions and 1 deletions

View File

@ -282,7 +282,7 @@ class Stack(collections.Mapping):
def __str__(self): def __str__(self):
'''Return a human-readable string representation of the stack.''' '''Return a human-readable string representation of the stack.'''
return 'Stack "%s"' % self.name return 'Stack "%s" [%s]' % (self.name, self.id)
def resource_by_refid(self, refid): def resource_by_refid(self, refid):
''' '''

View File

@ -323,6 +323,12 @@ class Resource(object):
for k in changed_properties_set) for k in changed_properties_set)
def __str__(self): def __str__(self):
if self.stack.id:
if self.resource_id:
return '%s "%s" [%s] %s' % (self.__class__.__name__, self.name,
self.resource_id, str(self.stack))
return '%s "%s" %s' % (self.__class__.__name__, self.name,
str(self.stack))
return '%s "%s"' % (self.__class__.__name__, self.name) return '%s "%s"' % (self.__class__.__name__, self.name)
def _add_dependencies(self, deps, path, fragment): def _add_dependencies(self, deps, path, fragment):

View File

@ -714,6 +714,12 @@ class StackTest(HeatTestCase):
self.m.ReplayAll() self.m.ReplayAll()
def test_stack_string_repr(self):
stack = parser.Stack(self.ctx, 'test_stack', parser.Template({}))
expected = 'Stack "%s" [%s]' % (stack.name, stack.id)
observed = str(stack)
self.assertEqual(expected, observed)
def test_state_defaults(self): def test_state_defaults(self):
stack = parser.Stack(self.ctx, 'test_stack', parser.Template({})) stack = parser.Stack(self.ctx, 'test_stack', parser.Template({}))
self.assertEqual(stack.state, (None, None)) self.assertEqual(stack.state, (None, None))

View File

@ -87,6 +87,37 @@ class ResourceTest(HeatTestCase):
self.assertEqual(res.state, (res.INIT, res.COMPLETE)) self.assertEqual(res.state, (res.INIT, res.COMPLETE))
self.assertEqual(res.status_reason, '') self.assertEqual(res.status_reason, '')
def test_resource_str_repr_stack_id_resource_id(self):
tmpl = {'Type': 'Foo'}
res = generic_rsrc.GenericResource('test_res_str_repr', tmpl,
self.stack)
res.stack.id = "123"
res.resource_id = "456"
expected = ('GenericResource "test_res_str_repr" [456] Stack '
'"test_stack" [123]')
observed = str(res)
self.assertEqual(expected, observed)
def test_resource_str_repr_stack_id_no_resource_id(self):
tmpl = {'Type': 'Foo'}
res = generic_rsrc.GenericResource('test_res_str_repr', tmpl,
self.stack)
res.stack.id = "123"
res.resource_id = None
expected = ('GenericResource "test_res_str_repr" Stack "test_stack" '
'[123]')
observed = str(res)
self.assertEqual(expected, observed)
def test_resource_str_repr_no_stack_id(self):
tmpl = {'Type': 'Foo'}
res = generic_rsrc.GenericResource('test_res_str_repr', tmpl,
self.stack)
res.stack.id = None
expected = ('GenericResource "test_res_str_repr"')
observed = str(res)
self.assertEqual(expected, observed)
def test_state_set(self): def test_state_set(self):
tmpl = {'Type': 'Foo'} tmpl = {'Type': 'Foo'}
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack) res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)