mirror of
https://github.com/xcat2/confluent.git
synced 2024-11-22 09:32:21 +00:00
Fix problem where broken expressions were not gracefully handled
Now when expressions can not be completed, the reason is presented as 'broken'. Additionally, when unsetting a value that would affect expressions, perform appropriate changes.
This commit is contained in:
parent
c56d0ac5a1
commit
811ca61747
5
TODO
5
TODO
@ -1,9 +1,4 @@
|
||||
-Reordering a group does not reorder inheritance preferences
|
||||
-Setting multiple values at once where one is an expression including the othe
|
||||
can fail because the expression is attempted to set before
|
||||
the next setting comes to work and then we get a stack trace
|
||||
Should leave value out of it and set 'broken' with a reason as the
|
||||
value to the key
|
||||
-expressionkeys never gets smaller - perf impact
|
||||
-need event notification for config change- e.g. set attribute triggers consol
|
||||
session object check to see if credentials changed
|
||||
|
@ -299,7 +299,12 @@ def _decode_attribute(attribute, nodeobj, formatter=None, decrypt=False):
|
||||
# set methods induce recalculation as appropriate to get a cached value
|
||||
if 'expression' in nodeobj[attribute] and formatter is not None:
|
||||
retdict = copy.deepcopy(nodeobj[attribute])
|
||||
retdict['value'] = formatter.format(retdict['expression'])
|
||||
if 'value' in retdict:
|
||||
del retdict['value']
|
||||
try:
|
||||
retdict['value'] = formatter.format(retdict['expression'])
|
||||
except Exception as e:
|
||||
retdict['broken'] = str(e)
|
||||
return retdict
|
||||
elif 'value' in nodeobj[attribute]:
|
||||
return nodeobj[attribute]
|
||||
@ -501,6 +506,8 @@ class ConfigManager(object):
|
||||
# if the attribute is not set, this will search for a candidate
|
||||
# if it is set, but inheritedfrom, search for a replacement, just
|
||||
# in case
|
||||
if not 'groups' in nodecfg:
|
||||
return
|
||||
for group in nodecfg['groups']:
|
||||
if attrib in self._cfgstore['groups'][group]:
|
||||
if srcgroup is not None and group != srcgroup:
|
||||
@ -630,12 +637,19 @@ class ConfigManager(object):
|
||||
nodek = self._cfgstore['nodes'][node]
|
||||
except KeyError:
|
||||
continue
|
||||
recalcexpressions = False
|
||||
for attrib in attributes:
|
||||
if attrib in nodek and 'inheritedfrom' not in nodek[attrib]:
|
||||
# if the attribute is set and not inherited,
|
||||
# delete it and check for inheritence to backfil data
|
||||
del nodek[attrib]
|
||||
self._do_inheritance(nodek, attrib, node)
|
||||
if ('_expressionkeys' in nodek and
|
||||
attrib in nodek['_expressionkeys']):
|
||||
recalcexpressions = True
|
||||
if recalcexpressions:
|
||||
exprmgr = _ExpressionFormat(nodek, node)
|
||||
self._recalculate_expressions(nodek, formatter=exprmgr)
|
||||
self._bg_sync_to_file()
|
||||
|
||||
def set_node_attributes(self, attribmap):
|
||||
@ -644,8 +658,8 @@ class ConfigManager(object):
|
||||
# TODO(jbjohnso): multi mgr support, here if we have peers,
|
||||
# pickle the arguments and fire them off in eventlet
|
||||
# flows to peers, all should have the same result
|
||||
exprmgr = None
|
||||
for node in attribmap.iterkeys():
|
||||
exprmgr = None
|
||||
if node not in self._cfgstore['nodes']:
|
||||
self._cfgstore['nodes'][node] = {}
|
||||
cfgobj = self._cfgstore['nodes'][node]
|
||||
|
@ -42,6 +42,10 @@ class ConfluentMessage(object):
|
||||
notes.append('Inherited from %s' % val['inheritedfrom'])
|
||||
if 'expression' in val:
|
||||
notes.append('Derived from expression "%s"' % val['expression'])
|
||||
elif val is not None and 'expression' in val and 'broken' in val:
|
||||
value = "*BROKEN*"
|
||||
notes.append('Derived from expression "%s"' % val['expression'])
|
||||
notes.append('Broken because of %s' % val['broken'])
|
||||
elif val is not None and 'expression' in val:
|
||||
value = val['expression']
|
||||
if value is None:
|
||||
|
@ -62,7 +62,7 @@ def retrieve_nodegroup(nodegroup, element, configmanager, inputdata):
|
||||
else:
|
||||
print attribute
|
||||
print repr(currattr)
|
||||
raise Exception("BUGGY ATTRIBUTE FOR NODE")
|
||||
raise Exception("BUGGY ATTRIBUTE FOR NODEGROUP")
|
||||
|
||||
|
||||
def retrieve_nodes(nodes, element, configmanager, inputdata):
|
||||
@ -96,7 +96,7 @@ def retrieve_nodes(nodes, element, configmanager, inputdata):
|
||||
desc = allattributes.node[attribute]['description']
|
||||
except KeyError:
|
||||
desc = 'Unknown'
|
||||
if 'value' in currattr:
|
||||
if 'value' in currattr or 'expression' in currattr:
|
||||
yield msg.Attributes(node,
|
||||
{attribute: currattr},
|
||||
desc)
|
||||
|
Loading…
Reference in New Issue
Block a user