mandatory master/slave's consistency with default value as slave

This commit is contained in:
Emmanuel Garette 2014-12-07 14:39:23 +01:00
parent 4fde28a15e
commit bc65caa4dc
4 changed files with 48 additions and 14 deletions

View File

@ -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> Mon Dec 1 22:58:13 2014 +0200 Emmanuel Garette <egarette@cadoles.com>
* propertyerror are transitive in consistency, now it's possible to set * propertyerror are transitive in consistency, now it's possible to set
non-transitive consistency non-transitive consistency

View File

@ -287,6 +287,23 @@ def test_consistency_network_netmask_multi():
raises(ValueError, "c.a = ['192.168.1.1']") 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(): def test_consistency_ip_netmask_multi_master():
a = IPOption('a', '', multi=True) a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True) b = NetmaskOption('b', '', multi=True)

View File

@ -115,24 +115,25 @@ class MasterSlaves(object):
def getitem(self, values, opt, path, validate, force_permissive, def getitem(self, values, opt, path, validate, force_permissive,
force_properties, validate_properties, slave_path=undefined, force_properties, validate_properties, slave_path=undefined,
slave_value=undefined): slave_value=undefined, setting_properties=undefined):
if self.is_master(opt): if self.is_master(opt):
return self._getmaster(values, opt, path, validate, return self._getmaster(values, opt, path, validate,
force_permissive, force_properties, force_permissive, force_properties,
validate_properties, slave_path, validate_properties, slave_path,
slave_value) slave_value, setting_properties)
else: else:
return self._getslave(values, opt, path, validate, return self._getslave(values, opt, path, validate,
force_permissive, force_properties, force_permissive, force_properties,
validate_properties) validate_properties, setting_properties)
def _getmaster(self, values, opt, path, validate, force_permissive, def _getmaster(self, values, opt, path, validate, force_permissive,
force_properties, validate_properties, c_slave_path, force_properties, validate_properties, c_slave_path,
c_slave_value): c_slave_value, setting_properties):
value = values._get_validated_value(opt, path, validate, value = values._get_validated_value(opt, path, validate,
force_permissive, force_permissive,
force_properties, force_properties,
validate_properties) validate_properties,
setting_properties=setting_properties)
if validate is True: if validate is True:
masterlen = len(value) masterlen = len(value)
for slave in self.getslaves(opt): for slave in self.getslaves(opt):
@ -146,7 +147,8 @@ class MasterSlaves(object):
False, False,
False, False,
None, False, None, False,
None) # not undefined None,
setting_properties=setting_properties)
slavelen = len(slave_value) slavelen = len(slave_value)
self.validate_slave_length(masterlen, slavelen, slave.impl_getname(), opt) self.validate_slave_length(masterlen, slavelen, slave.impl_getname(), opt)
except ConfigError: # pragma: optional cover except ConfigError: # pragma: optional cover
@ -154,7 +156,7 @@ class MasterSlaves(object):
return value return value
def _getslave(self, values, opt, path, validate, force_permissive, def _getslave(self, values, opt, path, validate, force_permissive,
force_properties, validate_properties): force_properties, validate_properties, setting_properties):
""" """
if master has length 0: if master has length 0:
return [] return []
@ -177,7 +179,8 @@ class MasterSlaves(object):
list is greater than master: raise SlaveError list is greater than master: raise SlaveError
""" """
master = self.getmaster(opt) 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, masterlen = self.get_length(values, opt, validate, undefined,
undefined, force_permissive, undefined, force_permissive,
master=master) master=master)
@ -185,11 +188,12 @@ class MasterSlaves(object):
value = values._get_validated_value(opt, path, validate, value = values._get_validated_value(opt, path, validate,
force_permissive, force_permissive,
force_properties, force_properties,
validate_properties, False,
None, # not undefined 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 #if slave, had values until master's one
path = opt.impl_getpath(values._getcontext()) path = opt.impl_getpath(context)
valuelen = len(value) valuelen = len(value)
if validate: if validate:
self.validate_slave_length(masterlen, valuelen, self.validate_slave_length(masterlen, valuelen,
@ -199,11 +203,20 @@ class MasterSlaves(object):
index = valuelen + num index = valuelen + num
value.append(values._get_validated_value(opt, path, True, value.append(values._get_validated_value(opt, path, True,
False, None, False, None,
validate_properties, validate_properties=False,
with_meta=master_is_meta, with_meta=master_is_meta,
index=index), index=index,
setting_properties=setting_properties),
setitem=False, setitem=False,
force=True) 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 return value
def setitem(self, values, opt, value, path): def setitem(self, values, opt, value, path):

View File

@ -229,7 +229,8 @@ class Values(object):
validate, validate,
force_permissive, force_permissive,
force_properties, force_properties,
validate_properties) validate_properties,
setting_properties=setting_properties)
else: else:
return self._get_validated_value(opt, path, validate, return self._get_validated_value(opt, path, validate,
force_permissive, force_permissive,