mandatory master/slave's consistency with default value as slave
This commit is contained in:
parent
4fde28a15e
commit
bc65caa4dc
@ -1,3 +1,6 @@
|
||||
Sun Dec 7 14:37:32 2014 +0200 Emmanuel Garette <egarette@cadoles.com>
|
||||
* mandatory master/slave's consistency with default value as slave
|
||||
|
||||
Mon Dec 1 22:58:13 2014 +0200 Emmanuel Garette <egarette@cadoles.com>
|
||||
* propertyerror are transitive in consistency, now it's possible to set
|
||||
non-transitive consistency
|
||||
|
@ -287,6 +287,23 @@ def test_consistency_network_netmask_multi():
|
||||
raises(ValueError, "c.a = ['192.168.1.1']")
|
||||
|
||||
|
||||
def test_consistency_network_netmask_multi_slave_default():
|
||||
a = NetworkOption('a', '', multi=True, properties=('mandatory',))
|
||||
b = NetmaskOption('b', '', default_multi=u'255.255.255.0', multi=True, properties=('mandatory',))
|
||||
od = OptionDescription('a', '', [a, b])
|
||||
od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
c = Config(od)
|
||||
c.read_write()
|
||||
c.cfgimpl_get_settings().remove('cache')
|
||||
assert c.a == []
|
||||
assert c.b == []
|
||||
c.a.append(u'192.168.1.0')
|
||||
c.read_only()
|
||||
assert c.a == [u'192.168.1.0']
|
||||
assert c.b == [u'255.255.255.0']
|
||||
|
||||
|
||||
def test_consistency_ip_netmask_multi_master():
|
||||
a = IPOption('a', '', multi=True)
|
||||
b = NetmaskOption('b', '', multi=True)
|
||||
|
@ -115,24 +115,25 @@ class MasterSlaves(object):
|
||||
|
||||
def getitem(self, values, opt, path, validate, force_permissive,
|
||||
force_properties, validate_properties, slave_path=undefined,
|
||||
slave_value=undefined):
|
||||
slave_value=undefined, setting_properties=undefined):
|
||||
if self.is_master(opt):
|
||||
return self._getmaster(values, opt, path, validate,
|
||||
force_permissive, force_properties,
|
||||
validate_properties, slave_path,
|
||||
slave_value)
|
||||
slave_value, setting_properties)
|
||||
else:
|
||||
return self._getslave(values, opt, path, validate,
|
||||
force_permissive, force_properties,
|
||||
validate_properties)
|
||||
validate_properties, setting_properties)
|
||||
|
||||
def _getmaster(self, values, opt, path, validate, force_permissive,
|
||||
force_properties, validate_properties, c_slave_path,
|
||||
c_slave_value):
|
||||
c_slave_value, setting_properties):
|
||||
value = values._get_validated_value(opt, path, validate,
|
||||
force_permissive,
|
||||
force_properties,
|
||||
validate_properties)
|
||||
validate_properties,
|
||||
setting_properties=setting_properties)
|
||||
if validate is True:
|
||||
masterlen = len(value)
|
||||
for slave in self.getslaves(opt):
|
||||
@ -146,7 +147,8 @@ class MasterSlaves(object):
|
||||
False,
|
||||
False,
|
||||
None, False,
|
||||
None) # not undefined
|
||||
None,
|
||||
setting_properties=setting_properties)
|
||||
slavelen = len(slave_value)
|
||||
self.validate_slave_length(masterlen, slavelen, slave.impl_getname(), opt)
|
||||
except ConfigError: # pragma: optional cover
|
||||
@ -154,7 +156,7 @@ class MasterSlaves(object):
|
||||
return value
|
||||
|
||||
def _getslave(self, values, opt, path, validate, force_permissive,
|
||||
force_properties, validate_properties):
|
||||
force_properties, validate_properties, setting_properties):
|
||||
"""
|
||||
if master has length 0:
|
||||
return []
|
||||
@ -177,7 +179,8 @@ class MasterSlaves(object):
|
||||
list is greater than master: raise SlaveError
|
||||
"""
|
||||
master = self.getmaster(opt)
|
||||
masterp = master.impl_getpath(values._getcontext())
|
||||
context = values._getcontext()
|
||||
masterp = master.impl_getpath(context)
|
||||
masterlen = self.get_length(values, opt, validate, undefined,
|
||||
undefined, force_permissive,
|
||||
master=master)
|
||||
@ -185,11 +188,12 @@ class MasterSlaves(object):
|
||||
value = values._get_validated_value(opt, path, validate,
|
||||
force_permissive,
|
||||
force_properties,
|
||||
validate_properties,
|
||||
False,
|
||||
None, # not undefined
|
||||
with_meta=master_is_meta)
|
||||
with_meta=master_is_meta,
|
||||
setting_properties=setting_properties)
|
||||
#if slave, had values until master's one
|
||||
path = opt.impl_getpath(values._getcontext())
|
||||
path = opt.impl_getpath(context)
|
||||
valuelen = len(value)
|
||||
if validate:
|
||||
self.validate_slave_length(masterlen, valuelen,
|
||||
@ -199,11 +203,20 @@ class MasterSlaves(object):
|
||||
index = valuelen + num
|
||||
value.append(values._get_validated_value(opt, path, True,
|
||||
False, None,
|
||||
validate_properties,
|
||||
validate_properties=False,
|
||||
with_meta=master_is_meta,
|
||||
index=index),
|
||||
index=index,
|
||||
setting_properties=setting_properties),
|
||||
setitem=False,
|
||||
force=True)
|
||||
if validate_properties:
|
||||
context.cfgimpl_get_settings().validate_properties(opt, False,
|
||||
False,
|
||||
value=value,
|
||||
path=path,
|
||||
force_permissive=force_permissive,
|
||||
force_properties=force_properties,
|
||||
self_properties=setting_properties)
|
||||
return value
|
||||
|
||||
def setitem(self, values, opt, value, path):
|
||||
|
@ -229,7 +229,8 @@ class Values(object):
|
||||
validate,
|
||||
force_permissive,
|
||||
force_properties,
|
||||
validate_properties)
|
||||
validate_properties,
|
||||
setting_properties=setting_properties)
|
||||
else:
|
||||
return self._get_validated_value(opt, path, validate,
|
||||
force_permissive,
|
||||
|
Loading…
Reference in New Issue
Block a user