From 3b733d1b4f9a9b82ce994eb9931cfdc11c787553 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Tue, 3 Sep 2013 22:41:18 +0200 Subject: [PATCH] support cache consistencies + no consistencies for a symlink + test --- test/test_option_consistency.py | 12 ++++++++- tiramisu/option.py | 48 ++++++++++++++++++++++++--------- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/test/test_option_consistency.py b/test/test_option_consistency.py index 8dde2a8..5cf53cd 100644 --- a/test/test_option_consistency.py +++ b/test/test_option_consistency.py @@ -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) diff --git a/tiramisu/option.py b/tiramisu/option.py index 4fb5434..b380817 100644 --- a/tiramisu/option.py +++ b/tiramisu/option.py @@ -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"