add SlaveError for slave's length
authorEmmanuel Garette <egarette@cadoles.com>
Fri, 19 Apr 2013 18:23:34 +0000 (20:23 +0200)
committerEmmanuel Garette <egarette@cadoles.com>
Fri, 19 Apr 2013 18:23:34 +0000 (20:23 +0200)
test/test_parsing_group.py
tiramisu/setting.py
tiramisu/value.py

index ef162b6..f060a97 100644 (file)
@@ -4,6 +4,7 @@ from tiramisu.setting import groups, owners
 from tiramisu.config import Config
 from tiramisu.option import ChoiceOption, BoolOption, IntOption, \
     StrOption, OptionDescription
+from tiramisu.error import SlaveError
 
 from py.test import raises
 
@@ -185,18 +186,18 @@ def test_values_with_master_and_slaves_slave():
     maconfig = OptionDescription('toto', '', [interface1])
     cfg = Config(maconfig)
     assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
-    raises(ValueError, "cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0']")
+    raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0']")
     cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
     cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0']
     cfg.ip_admin_eth0.netmask_admin_eth0[0] = '255.255.255.0'
-    raises(ValueError, "cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0', '255.255.255.0']")
-    raises(ValueError, "cfg.ip_admin_eth0.netmask_admin_eth0 = []")
+    raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0', '255.255.255.0']")
+    raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = []")
     del(cfg.ip_admin_eth0.netmask_admin_eth0)
     cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0']
     cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
     assert cfg.ip_admin_eth0.netmask_admin_eth0 == ['255.255.255.0', None]
     cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0', '255.255.255.0']
-    raises(ValueError, 'cfg.ip_admin_eth0.netmask_admin_eth0.pop(1)')
+    raises(SlaveError, 'cfg.ip_admin_eth0.netmask_admin_eth0.pop(1)')
 
 
 def test_values_with_master_and_slaves_master():
@@ -210,6 +211,6 @@ def test_values_with_master_and_slaves_master():
     cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145"]
     cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145", "192.168.230.145"]
     cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0', '255.255.255.0']
-    raises(ValueError, 'cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145"]')
+    raises(SlaveError, 'cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145"]')
     cfg.ip_admin_eth0.ip_admin_eth0.pop(1)
     assert cfg.ip_admin_eth0.ip_admin_eth0 == ["192.168.230.145"]
index f101a0c..38cd487 100644 (file)
@@ -250,7 +250,7 @@ class Setting(object):
         if opt_or_descr in self._cache:
             t = time()
             props, raise_text, created = self._cache[opt_or_descr]
-            if t - created < expires_time:
+            if t < created:
                 properties = props
                 is_cached = True
         if not is_cached:
@@ -318,7 +318,7 @@ class Setting(object):
 
     def _set_cache(self, opt, props, raise_text):
         if self.has_property('expire'):
-            self._cache[opt] = (props, raise_text, time())
+            self._cache[opt] = (props, raise_text, time() + expires_time)
 
     def reset_cache(self):
         self._cache = {}
index 5838df6..e35cbcb 100644 (file)
@@ -86,7 +86,7 @@ class Values(object):
         if opt in self._cache:
             t = time()
             value, created = self._cache[opt]
-            if t - created < expires_time:
+            if t < created:
                 return value
         val = self._getitem(opt, validate, force_permissive, force_properties)
         self._set_cache(opt, val)
@@ -173,7 +173,7 @@ class Values(object):
 
     def _set_cache(self, opt, val):
         if self.context.cfgimpl_get_settings().has_property('expire'):
-            self._cache[opt] = (val, time())
+            self._cache[opt] = (val, time() + expires_time)
 
     def reset_cache(self):
         self._cache = {}