support cache consistencies + no consistencies for a symlink + test

This commit is contained in:
Emmanuel Garette 2013-09-03 22:41:18 +02:00
parent fc9f6ce816
commit 3b733d1b4f
2 changed files with 46 additions and 14 deletions

View File

@ -4,7 +4,7 @@ from py.test import raises
from tiramisu.setting import owners, groups
from tiramisu.config import Config
from tiramisu.option import IPOption, NetworkOption, NetmaskOption, IntOption,\
OptionDescription
SymLinkOption, OptionDescription
def test_consistency_not_equal():
@ -22,6 +22,16 @@ def test_consistency_not_equal():
c.b = 2
def test_consistency_not_equal_symlink():
a = IntOption('a', '')
b = IntOption('b', '')
c = SymLinkOption('c', a)
od = OptionDescription('od', '', [a, b, c])
a.impl_add_consistency('not_equal', b)
c = Config(od)
assert set(od._consistencies.keys()) == set([a, b])
def test_consistency_not_equal_multi():
a = IntOption('a', '', multi=True)
b = IntOption('b', '', multi=True)

View File

@ -167,21 +167,35 @@ class BaseOption(object):
consistencies = self._state_consistencies
else:
consistencies = self._consistencies
new_value = []
for consistency in consistencies:
if load:
new_value.append((consistency[0],
descr.impl_get_opt_by_path(
consistency[1])))
else:
new_value.append((consistency[0],
descr.impl_get_path_by_opt(
consistency[1])))
if isinstance(consistencies, list):
new_value = []
for consistency in consistencies:
if load:
new_value.append((consistency[0],
descr.impl_get_opt_by_path(
consistency[1])))
else:
new_value.append((consistency[0],
descr.impl_get_path_by_opt(
consistency[1])))
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)))
if load:
del(self._state_consistencies)
self._consistencies = tuple(new_value)
self._consistencies = new_value
else:
self._state_consistencies = tuple(new_value)
self._state_consistencies = new_value
def _impl_convert_requires(self, descr, load=False):
if not load and self._requires is None:
@ -621,8 +635,10 @@ else:
class SymLinkOption(BaseOption):
__slots__ = ('_name', '_opt', '_state_opt')
__slots__ = ('_name', '_opt', '_state_opt', '_consistencies')
_opt_type = 'symlink'
#not return _opt consistencies
_consistencies = {}
def __init__(self, name, opt):
self._name = name
@ -648,6 +664,12 @@ class SymLinkOption(BaseOption):
del(self._state_opt)
super(SymLinkOption, self)._impl_setstate(descr)
def _impl_convert_consistencies(self, descr, load=False):
if load:
del(self._state_consistencies)
else:
self._state_consistencies = None
class IPOption(Option):
"represents the choice of an ip"