add SlaveError for slave's length

This commit is contained in:
Emmanuel Garette 2013-04-19 20:23:34 +02:00
parent 410add6a2a
commit d7b5d9dc16
3 changed files with 10 additions and 9 deletions

View 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"]

View 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 = {}

View 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 = {}