mirror of
https://github.com/xcat2/confluent.git
synced 2024-11-25 19:10:10 +00:00
Fixup unknown attribute handling.
For one, prevent unknown attributes from getting into configmanager from now on. Additionally, have the attributes plugin manage to convey bad attributes when encountered.
This commit is contained in:
parent
b6853cfbe1
commit
b823bc37d2
@ -54,7 +54,7 @@ from Crypto.Hash import SHA256
|
||||
import array
|
||||
import ast
|
||||
import collections
|
||||
import confluent.config.attributes as attributes
|
||||
import confluent.config.attributes as allattributes
|
||||
import confluent.util
|
||||
import copy
|
||||
import cPickle
|
||||
@ -545,6 +545,10 @@ class ConfigManager(object):
|
||||
self._cfgstore['groups'][group] = {'nodes': set([])}
|
||||
cfgobj = self._cfgstore['groups'][group]
|
||||
for attr in attribmap[group].iterkeys():
|
||||
if (attr not in allattributes.node or
|
||||
('type' in allattributes.node[attr] and
|
||||
not isinstance(attribmap[node][attr],allattributes.node[attr]['type']))):
|
||||
raise ValueError
|
||||
newdict = {}
|
||||
if attr == 'nodes':
|
||||
if not isinstance(attribmap[group][attr], list):
|
||||
@ -610,9 +614,9 @@ class ConfigManager(object):
|
||||
cfgobj = self._cfgstore['nodes'][node]
|
||||
recalcexpressions = False
|
||||
for attrname in attribmap[node].iterkeys():
|
||||
if (attrname not in attributes.node or
|
||||
('type' in attributes.node[attrname] and
|
||||
not isinstance(attribmap[node][attrname],attributes.node[attrname]['type']))):
|
||||
if (attrname not in allattributes.node or
|
||||
('type' in allattributes.node[attrname] and
|
||||
not isinstance(attribmap[node][attrname],allattributes.node[attrname]['type']))):
|
||||
raise ValueError
|
||||
newdict = {}
|
||||
if (isinstance(attribmap[node][attrname], str)):
|
||||
|
@ -35,11 +35,11 @@ class ConfluentMessage(object):
|
||||
val = self.kvpairs[key]
|
||||
value = self.defaultvalue
|
||||
type = self.defaulttype
|
||||
if 'value' in val:
|
||||
if val is not None and 'value' in val:
|
||||
value = val['value']
|
||||
if value is None:
|
||||
value = ''
|
||||
if value == '' and 'isset' in val and val['isset'] is True:
|
||||
if val is not None and value == '' and 'isset' in val and val['isset'] is True:
|
||||
# an encrypted value, put some *** to show it is set
|
||||
# in the explorer
|
||||
value = '********'
|
||||
@ -271,7 +271,10 @@ class Attributes(ConfluentMessage):
|
||||
self.desc = desc
|
||||
nkv = {}
|
||||
for key in kv.iterkeys():
|
||||
nkv[key] = {'value': kv[key]}
|
||||
if type(kv[key]) == str:
|
||||
nkv[key] = {'value': kv[key]}
|
||||
else:
|
||||
nkv[key] = kv[key]
|
||||
if node is None:
|
||||
self.kvpairs = nkv
|
||||
else:
|
||||
|
@ -41,7 +41,10 @@ def retrieve_nodegroup(nodegroup, element, configmanager, inputdata):
|
||||
if attribute == 'nodes':
|
||||
desc = 'The nodes belonging to this group'
|
||||
else:
|
||||
desc = allattributes.node[attribute]['description']
|
||||
try:
|
||||
desc = allattributes.node[attribute]['description']
|
||||
except KeyError:
|
||||
desc = 'Unknown'
|
||||
if 'value' in currattr:
|
||||
yield msg.Attributes(
|
||||
kv={attribute: currattr['value']},
|
||||
@ -89,18 +92,20 @@ def retrieve_nodes(nodes, element, configmanager, inputdata):
|
||||
for node in attributes.iterkeys():
|
||||
for attribute in sorted(attributes[node].iterkeys()):
|
||||
currattr = attributes[node][attribute]
|
||||
try:
|
||||
desc = allattributes.node[attribute]['description']
|
||||
except KeyError:
|
||||
desc = 'Unknown'
|
||||
if 'value' in currattr:
|
||||
yield msg.Attributes(node,
|
||||
{attribute: currattr['value']},
|
||||
allattributes.node[attribute]['description'])
|
||||
desc)
|
||||
elif 'cryptvalue' in currattr:
|
||||
yield msg.CryptedAttributes(node,
|
||||
{attribute: currattr},
|
||||
allattributes.node[attribute]['description'])
|
||||
{attribute: currattr}, desc)
|
||||
elif isinstance(currattr, list):
|
||||
yield msg.ListAttributes(node,
|
||||
{attribute: currattr},
|
||||
allattributes.node[attribute]['description'])
|
||||
{attribute: currattr}, desc)
|
||||
else:
|
||||
raise Exception("BUGGY ATTRIBUTE FOR NODE")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user