Merge branch 'master' into orm

Conflicts:
	test/test_option_consistency.py
	test/test_state.py
	tiramisu/option.py
This commit is contained in:
2014-02-06 22:21:22 +01:00
5 changed files with 469 additions and 412 deletions

View File

@ -400,9 +400,6 @@ class Option(OnlyOption):
"""
if context is not None:
descr = context.cfgimpl_get_description()
#option is also in all_cons_opts
if option not in all_cons_opts:
raise ConfigError(_('option not in all_cons_opts'))
all_cons_vals = []
for opt in all_cons_opts:
@ -413,7 +410,8 @@ class Option(OnlyOption):
#if context, calculate value, otherwise get default value
if context is not None:
opt_value = context._getattr(
descr.impl_get_path_by_opt(opt), validate=False)
descr.impl_get_path_by_opt(opt), validate=False,
force_permissive=True)
else:
opt_value = opt.impl_getdefault()
@ -641,31 +639,15 @@ class Option(OnlyOption):
consistencies = self._state_consistencies
else:
consistencies = self._consistencies
if isinstance(consistencies, list):
new_value = []
for consistency in consistencies:
values = []
for obj in consistency[1]:
if load:
values.append(descr.impl_get_opt_by_path(obj))
else:
values.append(descr.impl_get_path_by_opt(obj))
new_value.append((consistency[0], tuple(values)))
else:
new_value = {}
for key, _consistencies in consistencies.items():
new_value[key] = []
for key_cons, _cons in _consistencies:
_list_cons = []
for _con in _cons:
if load:
_list_cons.append(
descr.impl_get_opt_by_path(_con))
else:
_list_cons.append(
descr.impl_get_path_by_opt(_con))
new_value[key].append((key_cons, tuple(_list_cons)))
new_value = []
for consistency in consistencies:
values = []
for obj in consistency[1]:
if load:
values.append(descr.impl_get_opt_by_path(obj))
else:
values.append(descr.impl_get_path_by_opt(obj))
new_value.append((consistency[0], tuple(values)))
if load:
del(self._state_consistencies)
self._consistencies = new_value
@ -921,8 +903,8 @@ class PortOption(Option):
for val in value:
try:
if not self._extra['_min_value'] <= int(val) <= self._extra['_max_value']:
raise ValueError('invalid port, must be an between {0} '
'and {1}'.format(
raise ValueError(_('invalid port, must be an between {0} '
'and {1}').format(
self._extra['_min_value'],
self._extra['_max_value']))
except ValueError:
@ -979,19 +961,14 @@ class NetmaskOption(Option):
IP('{0}/{1}'.format(val_ipnetwork, val_netmask),
make_net=not make_net)
except ValueError:
if not make_net:
msg = _("invalid network {0} ({1}) "
"with netmask {2},"
" this network is an IP")
pass
else:
if make_net:
msg = _("invalid IP {0} ({1}) with netmask {2},"
" this IP is a network")
except ValueError:
if make_net:
msg = _('invalid IP {0} ({1}) with netmask {2}')
else:
if not make_net:
msg = _('invalid network {0} ({1}) with netmask {2}')
if msg is not None:
raise ValueError(msg.format(val_ipnetwork, opts[1].impl_getname(),
@ -1080,8 +1057,8 @@ class DomainnameOption(Option):
if self._dom_type == 'domainname' and not self._allow_without_dot and \
'.' not in value:
raise ValueError(_("invalid domainname, must have dot"))
if len(value) > 255:
raise ValueError(_("invalid domainname's length (max 255)"))
if len(value) > 255:
raise ValueError(_("invalid domainname's length (max 255)"))
if len(value) < 2:
raise ValueError(_("invalid domainname's length (min 2)"))
if not self._domain_re.search(value):
@ -1338,13 +1315,10 @@ class OptionDescription(BaseOption, StorageOptionDescription):
if consistencies is not None:
for func, all_cons_opts in consistencies:
#all_cons_opts[0] is the option where func is set
ret = all_cons_opts[0]._launch_consistency(func, option,
value,
context, index,
all_cons_opts)
if ret is False:
return False
return True
all_cons_opts[0]._launch_consistency(func, option,
value,
context, index,
all_cons_opts)
# ____________________________________________________________
# serialize object