add meta in option_bag
This commit is contained in:
parent
f4bf3dc390
commit
b27d283341
@ -964,3 +964,100 @@ def test_path_properties_path_set_value():
|
||||
del ret[1]
|
||||
del ret[0]
|
||||
del ret
|
||||
|
||||
|
||||
def test_path_different_default():
|
||||
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
|
||||
interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0])
|
||||
ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.2'])
|
||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0])
|
||||
ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.3'])
|
||||
interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0])
|
||||
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.4'])
|
||||
ip_admin_eth1 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.5'])
|
||||
interface3 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, ip_admin_eth1])
|
||||
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.6'])
|
||||
interface4 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0])
|
||||
conf1 = Config(interface0, session_id='conf1')
|
||||
conf1.property.read_write()
|
||||
conf2 = Config(interface1, session_id='conf2')
|
||||
conf2.property.read_write()
|
||||
path = PathConfig(interface2, [conf1, conf2], session_id='subpath1')
|
||||
path = PathConfig(interface3, [path], session_id='subpath2')
|
||||
path = PathConfig(interface4, [path])
|
||||
path.property.read_write()
|
||||
path.value.dict() == {'ip_admin_eth0': ['192.168.1.6']}
|
||||
path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.4'], 'ip_admin_eth1': ['192.168.1.5']}
|
||||
path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
|
||||
path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
|
||||
path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
|
||||
#
|
||||
path.option('ip_admin_eth0').value.set(['192.168.1.7'])
|
||||
assert path.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
|
||||
assert path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.7'], 'ip_admin_eth1': ['192.168.1.5']}
|
||||
assert path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
|
||||
assert path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
|
||||
assert path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
|
||||
#
|
||||
path.config('subpath2').option('ip_admin_eth0').value.set(['192.168.1.8'])
|
||||
assert path.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
|
||||
assert path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']}
|
||||
assert path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
|
||||
assert path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
|
||||
assert path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.8']}
|
||||
#
|
||||
raises(AttributeError, "path.config('subpath2.subpath1').option('ip_admin_eth0').value.set(['192.168.1.9'])")
|
||||
assert path.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
|
||||
assert path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']}
|
||||
assert path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
|
||||
assert path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
|
||||
assert path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.8']}
|
||||
#
|
||||
raises(AttributeError, "path.config('subpath2.subpath1.conf2').option('ip_admin_eth0').value.set(['192.168.1.9'])")
|
||||
assert path.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
|
||||
assert path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']}
|
||||
assert path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
|
||||
assert path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
|
||||
assert path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.8']}
|
||||
#
|
||||
path.config('subpath2.subpath1.conf1').option('ip_admin_eth0').value.set(['192.168.1.9'])
|
||||
assert path.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
|
||||
assert path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']}
|
||||
assert path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
|
||||
assert path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
|
||||
assert path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.9']}
|
||||
#
|
||||
raises(AttributeError, "path.option('ip_admin_eth1').value.set(['192.168.1.10'])")
|
||||
assert path.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
|
||||
assert path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']}
|
||||
assert path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
|
||||
assert path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
|
||||
assert path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.9']}
|
||||
#
|
||||
path.config('subpath2').option('ip_admin_eth1').value.set(['192.168.1.10'])
|
||||
assert path.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
|
||||
assert path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']}
|
||||
assert path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.10']}
|
||||
assert path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.10']}
|
||||
assert path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.9']}
|
||||
#
|
||||
path.config('subpath2.subpath1').option('ip_admin_eth1').value.set(['192.168.1.11'])
|
||||
assert path.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
|
||||
assert path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']}
|
||||
assert path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.11']}
|
||||
assert path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.11']}
|
||||
assert path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.9']}
|
||||
#
|
||||
path.config('subpath2.subpath1.conf2').option('ip_admin_eth1').value.set(['192.168.1.12'])
|
||||
assert path.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
|
||||
assert path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']}
|
||||
assert path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.11']}
|
||||
assert path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.12']}
|
||||
assert path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.9']}
|
||||
#
|
||||
raises(AttributeError, "path.config('subpath2.subpath1.conf1').option('ip_admin_eth1').value.set(['192.168.1.13'])")
|
||||
assert path.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
|
||||
assert path.config('subpath2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']}
|
||||
assert path.config('subpath2.subpath1').value.dict() == {'ip_admin_eth1': ['192.168.1.11']}
|
||||
assert path.config('subpath2.subpath1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.12']}
|
||||
assert path.config('subpath2.subpath1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.9']}
|
||||
|
@ -157,11 +157,10 @@ class Values(object):
|
||||
# calculated value is a new value, so reset cache
|
||||
context.cfgimpl_reset_cache(option_bag)
|
||||
|
||||
if self._is_meta(option_bag):
|
||||
option_bag.properties = frozenset()
|
||||
meta = context.cfgimpl_get_meta()
|
||||
moption_bag = self._get_meta(option_bag)
|
||||
if moption_bag:
|
||||
# retrieved value from meta config
|
||||
return meta.cfgimpl_get_values().get_cached_value(option_bag)
|
||||
return moption_bag.config_bag.context.cfgimpl_get_values().get_cached_value(moption_bag)
|
||||
|
||||
if opt.impl_has_callback():
|
||||
# if value has callback, calculate value
|
||||
@ -310,24 +309,27 @@ class Values(object):
|
||||
option_bag.index,
|
||||
commit)
|
||||
|
||||
def _is_meta(self,
|
||||
option_bag):
|
||||
def _get_meta(self,
|
||||
option_bag):
|
||||
context = option_bag.config_bag.context
|
||||
meta = context.cfgimpl_get_meta()
|
||||
if meta is None:
|
||||
return False
|
||||
return None
|
||||
if option_bag.option.impl_is_master_slaves('slave'):
|
||||
master = option_bag.option.impl_get_master_slaves().getmaster()
|
||||
masterp = master.impl_getpath()
|
||||
# slave could be a "meta" only if master hasn't value
|
||||
if self._p_.hasvalue(masterp,
|
||||
index=None):
|
||||
return False
|
||||
return None
|
||||
doption_bag = option_bag.copy()
|
||||
config_bag = option_bag.config_bag.copy()
|
||||
config_bag.context = meta
|
||||
doption_bag.config_bag = config_bag
|
||||
return not meta.cfgimpl_get_values().is_default_owner(doption_bag)
|
||||
doption_bag.properties = frozenset()
|
||||
if meta.cfgimpl_get_values().is_default_owner(doption_bag):
|
||||
return None
|
||||
return doption_bag
|
||||
|
||||
|
||||
#______________________________________________________________________
|
||||
@ -374,15 +376,11 @@ class Values(object):
|
||||
owner = self._p_.getowner(option_bag.path,
|
||||
owners.default,
|
||||
index=option_bag.index)
|
||||
if owner is owners.default and validate_meta is not False and self._is_meta(option_bag):
|
||||
option_bag = option_bag.copy()
|
||||
option_bag.properties = frozenset()
|
||||
config_bag = option_bag.config_bag.copy()
|
||||
meta = context.cfgimpl_get_meta()
|
||||
config_bag.context = meta
|
||||
option_bag.config_bag = config_bag
|
||||
owner = meta.cfgimpl_get_values().getowner(option_bag,
|
||||
only_default=only_default)
|
||||
if owner is owners.default and validate_meta is not False:
|
||||
moption_bag = self._get_meta(option_bag)
|
||||
if moption_bag:
|
||||
owner = moption_bag.config_bag.context.cfgimpl_get_values().getowner(moption_bag,
|
||||
only_default=only_default)
|
||||
return owner
|
||||
|
||||
def setowner(self,
|
||||
|
Loading…
Reference in New Issue
Block a user