Merge branch 'master' of ssh://git.labs.libre-entreprise.org/gitroot/tiramisu
authorgwen <gremond@cadoles.com>
Wed, 4 Sep 2013 07:05:25 +0000 (09:05 +0200)
committergwen <gremond@cadoles.com>
Wed, 4 Sep 2013 07:05:25 +0000 (09:05 +0200)
test/test_option_consistency.py
tiramisu/option.py

index 8dde2a8..5cf53cd 100644 (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)
index d483d9e..6e4d9da 100644 (file)
@@ -168,21 +168,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):
         """export of the requires during the serialization process
@@ -644,8 +658,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
@@ -671,6 +687,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"