@ -300,15 +300,16 @@ class ValueBuilder(object):
return ' Value<path= {0} , state= {1} , value= {2} > ' . format (
self . path , self . state , self . value )
def __init__ ( self , client ):
def __init__ ( self , client , mode = ' config ' ):
self . _client = client
self . _mode = mode
self . _schema_cache = { }
self . _module_prefix_map_cache = None
self . _values = [ ]
self . _values_dirty = False
def build ( self , parent , maybe_qname , value , schema = None ) :
qname , name = self . _ get_prefix_name( maybe_qname )
qname , name = self . get_prefix_name( maybe_qname )
if name is None :
path = parent
else :
@ -329,16 +330,16 @@ class ValueBuilder(object):
self . _add_value ( path , State . PRESENT , None , deps )
else :
if maybe_qname is None :
value_type = self . _ get_type( path )
value_type = self . get_type( path )
else :
value_type = self . _get_child_type ( parent , qname )
if ' identityref ' in value_type :
if isinstance ( value , list ) :
value = [ ll_v for ll_v , t_ll_v
in [ self . _ get_prefix_name( v ) for v in value ] ]
in [ self . get_prefix_name( v ) for v in value ] ]
else :
value , t_value = self . _ get_prefix_name( value )
value , t_value = self . get_prefix_name( value )
self . _add_value ( path , State . SET , value , deps )
elif isinstance ( value , dict ) :
self . _build_dict ( path , schema , value )
@ -420,7 +421,7 @@ class ValueBuilder(object):
def _build_dict ( self , path , schema , value ) :
keys = schema . get ( ' key ' , [ ] )
for dict_key , dict_value in value . items ( ) :
qname , name = self . _ get_prefix_name( dict_key )
qname , name = self . get_prefix_name( dict_key )
if dict_key in ( ' __state ' , ) or name in keys :
continue
@ -429,16 +430,25 @@ class ValueBuilder(object):
def _build_leaf_list ( self , path , schema , value ) :
deps = schema . get ( ' deps ' , [ ] )
entry_type = self . _get_type ( path , schema )
# remove leaf list if treated as a list and then re-create the
# expected list entries.
self . _add_value ( path , State . ABSENT , None , deps )
entry_type = self . get_type ( path , schema )
if self . _mode == ' verify ' :
for entry in value :
if ' identityref ' in entry_type :
entry , t_entry = self . get_prefix_name ( entry )
entry_path = ' {0} {{ {1} }} ' . format ( path , entry )
if not self . _client . exists ( entry_path ) :
self . _add_value ( entry_path , State . ABSENT , None , deps )
else :
# remove leaf list if treated as a list and then re-create the
# expected list entries.
self . _add_value ( path , State . ABSENT , None , deps )
for entry in value :
if ' identityref ' in entry_type :
entry , t_entry = self . _get_prefix_name ( entry )
entry_path = ' {0} {{ {1} }} ' . format ( path , entry )
self . _add_value ( entry_path , State . PRESENT , None , deps )
for entry in value :
if ' identityref ' in entry_type :
entry , t_entry = self . get_prefix_name( entry )
entry_path = ' {0} {{ {1} }} ' . format ( path , entry )
self . _add_value ( entry_path , State . PRESENT , None , deps )
def _build_list ( self , path , schema , value ) :
deps = schema . get ( ' deps ' , [ ] )
@ -470,7 +480,7 @@ class ValueBuilder(object):
value_type = self . _get_child_type ( path , key )
if ' identityref ' in value_type :
value , t_value = self . _ get_prefix_name( value )
value , t_value = self . get_prefix_name( value )
key_parts . append ( self . _quote_key ( value ) )
return ' ' . join ( key_parts )
@ -513,7 +523,7 @@ class ValueBuilder(object):
self . _values . append ( ValueBuilder . Value ( path , state , value , deps ) )
self . _values_dirty = True
def _ get_prefix_name( self , qname ) :
def get_prefix_name( self , qname ) :
if not isinstance ( qname , ( str , unicode ) ) :
return qname , None
if ' : ' not in qname :
@ -536,9 +546,9 @@ class ValueBuilder(object):
parent_schema = all_schema [ ' data ' ]
meta = all_schema [ ' meta ' ]
schema = self . _find_child ( parent_path , parent_schema , key )
return self . _ get_type( parent_path , schema , meta )
return self . get_type( parent_path , schema , meta )
def _ get_type( self , path , schema = None , meta = None ) :
def get_type( self , path , schema = None , meta = None ) :
if schema is None or meta is None :
all_schema = self . _ensure_schema_cached ( path )
schema = all_schema [ ' data ' ]
@ -669,7 +679,8 @@ def verify_version_str(version_str, required_versions):
def normalize_value ( expected_value , value , key ) :
if value is None :
return None
if isinstance ( expected_value , bool ) :
if ( isinstance ( expected_value , bool ) and
isinstance ( value , ( str , unicode ) ) ) :
return value == ' true '
if isinstance ( expected_value , int ) :
try :